innitial commit
Browse files- .gitignore +2 -0
- app.py +20 -0
- dog.jpg +0 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
venv/
|
2 |
+
transformers/
|
app.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
|
7 |
+
pipe = pipeline("zero-shot-image-classification", model="openai/clip-vit-base-patch32")
|
8 |
+
images="dog.jpg"
|
9 |
+
|
10 |
+
def shot(image, labels_text):
|
11 |
+
PIL_image = Image.fromarray(np.uint8(image)).convert('RGB')
|
12 |
+
labels = labels_text.split(",")
|
13 |
+
res = pipe(images=PIL_image,
|
14 |
+
candidate_labels=labels,
|
15 |
+
hypothesis_template= "This is a photo of a {}")
|
16 |
+
return {dic["label"]: dic["score"] for dic in res}
|
17 |
+
|
18 |
+
iface = gr.Interface(shot, ["image", "text"], "label", examples=[["dog.jpg", "dog,cat,bird"]])
|
19 |
+
|
20 |
+
iface.launch()
|
dog.jpg
ADDED