OMGJ commited on
Commit
07e8ffa
1 Parent(s): 75a2347

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from turtle import title
2
+ import gradio as gr
3
+ from transformers import pipeline
4
+ import numpy as np
5
+ from PIL import Image
6
+
7
+
8
+ pipe = pipeline("zero-shot-image-classification", model="openai/clip-vit-base-patch32")
9
+
10
+
11
+ def shot(image, labels_text):
12
+ PIL_image = Image.fromarray(np.uint8(image)).convert('RGB')
13
+ labels = labels_text.split(",")
14
+ res = pipe(images=PIL_image,
15
+ candidate_labels=labels,
16
+ hypothesis_template= "This is a photo of a {}")
17
+ return {dic["label"]: dic["score"] for dic in res}
18
+
19
+ iface = gr.Interface(shot,
20
+ ["image", "text"],
21
+ "label",
22
+ description="Ajouter une image avc une liste de labels séparées par la virgule",
23
+ title="Zero-shot Image Classification")
24
+
25
+ iface.launch()