Spaces:
Build error
Build error
Hussain Shaikh
commited on
Commit
·
d7b57f5
1
Parent(s):
0bd0ee9
made changes in labels and input
Browse files- app.py +20 -7
- requirements.txt +2 -0
app.py
CHANGED
@@ -1,12 +1,25 @@
|
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
|
3 |
|
4 |
-
|
5 |
-
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
iface
|
9 |
-
iface.launch()
|
10 |
-
|
11 |
-
|
12 |
-
# gr.Interface(inference, gr.inputs.Image(type="pil"), gr.outputs.Image(type="pil"),title=title,description=description,article=article,examples=examples,allow_flagging=False,allow_screenshot=False).launch(enable_queue=True,cache_examples=True)
|
|
|
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 |
+
images="dog.jpg"
|
10 |
|
11 |
+
def shot(image, labels_text="signature,profile picture"):
|
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",
|
21 |
+
"label",
|
22 |
+
description="Add a picture and a list of labels separated by commas",
|
23 |
+
title="Zero-shot Image Classification")
|
24 |
|
25 |
+
iface.launch()
|
|
|
|
|
|
|
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
git+https://github.com/huggingface/transformers.git@master#egg=transformers
|
2 |
+
torch
|