-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
43 lines (33 loc) · 1.31 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import gradio as gr
from PIL import Image
from clip.model import OnnxClip, softmax, get_similarity_scores
example = ["a photo of space",
"a photo of a man",
"a photo of a man in dungarees",
"a photo of a sad man in dungarees",
"a photo of a sad man in dungarees with short hair and a orange container to the right",
"a photo of a sad man in dungarees with short hair",
"a photo of a happy man in dungarees",
"A photo of Christopher Nolan"]
def classify(image, text):
images = [image]
texts = {"classification": text.split(',')
}
#type='clip' is also avvailable with this usage
onnx_model = OnnxClip(batch_size=16, type='siglip_full')
probs, _ = onnx_model.inference(images, texts)
probs = [float(p) for p in probs['classification']]
return {label: prob for label, prob in zip(texts['classification'],probs)}
demo = gr.Interface(
classify,
[
gr.Image(label="Image", type="pil"),
gr.Textbox(label="Labels", info="Comma-separated list of class labels"),
],
gr.Label(label="Result"),
examples=[['clip/data/interstellar.jpg', ','.join(example)]],
)
try:
demo.launch(debug=True, height=1000)
except Exception:
demo.launch(share=True, debug=True, height=1000)