martinkropf commited on
Commit
c99985e
1 Parent(s): 855b97c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -2
app.py CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
  import numpy as np
@@ -5,6 +8,23 @@ from PIL import Image
5
 
6
 
7
  pipe = pipeline("zero-shot-image-classification", model="mkaichristensen/echo-clip")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
- gr.load("models/mkaichristensen/echo-clip").launch()
10
- print("Models loaded")
 
1
+
2
+
3
+ from turtle import title
4
  import gradio as gr
5
  from transformers import pipeline
6
  import numpy as np
 
8
 
9
 
10
  pipe = pipeline("zero-shot-image-classification", model="mkaichristensen/echo-clip")
11
+ images="dog.jpg"
12
+
13
+ def shot(image, labels_text):
14
+ PIL_image = Image.fromarray(np.uint8(image)).convert('RGB')
15
+ labels = labels_text.split(",")
16
+ res = pipe(images=PIL_image,
17
+ candidate_labels=labels,
18
+ hypothesis_template= "This is a photo of a {}")
19
+ return {dic["label"]: dic["score"] for dic in res}
20
+
21
+ iface = gr.Interface(shot,
22
+ ["image", "text"],
23
+ "label",
24
+ examples=[["dog.jpg", "dog,cat,bird"],
25
+ ["germany.jpg", "germany,belgium,colombia"],
26
+ ["colombia.jpg", "germany,belgium,colombia"]],
27
+ description="Add a picture and a list of labels separated by commas",
28
+ title="Zero-shot Image Classification")
29
 
30
+ iface.launch()