Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,7 @@ import gradio as gr
|
|
| 11 |
|
| 12 |
model = M2M100ForConditionalGeneration.from_pretrained("facebook/m2m100_418M")
|
| 13 |
tokenizer = M2M100Tokenizer.from_pretrained("facebook/m2m100_418M")
|
|
|
|
| 14 |
pipe = pipeline("zero-shot-image-classification", model="openai/clip-vit-base-patch32")
|
| 15 |
images="dog.jpg"
|
| 16 |
|
|
@@ -20,16 +21,20 @@ def shot(image, labels_text):
|
|
| 20 |
|
| 21 |
PIL_image = Image.fromarray(np.uint8(image)).convert('RGB')
|
| 22 |
labels = labels_text.split(",")
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
hypothesis_template= "This is a photo of a {}")
|
| 26 |
-
return {dic["label"]: dic["score"] for dic in res}
|
| 27 |
-
# Translate
|
| 28 |
tokenizer.src_lang = "en"
|
| 29 |
encodedText = tokenizer(labels_text, return_tensors="pt")
|
| 30 |
generatedTokens = model.generate(**encodedText, forced_bos_token_id=tokenizer.get_lang_id("ru"))
|
| 31 |
return tokenizer.batch_decode(generatedTokens, skip_special_tokens=True)[0]
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
iface = gr.Interface(shot,
|
| 35 |
["image", "text"],
|
|
|
|
| 11 |
|
| 12 |
model = M2M100ForConditionalGeneration.from_pretrained("facebook/m2m100_418M")
|
| 13 |
tokenizer = M2M100Tokenizer.from_pretrained("facebook/m2m100_418M")
|
| 14 |
+
|
| 15 |
pipe = pipeline("zero-shot-image-classification", model="openai/clip-vit-base-patch32")
|
| 16 |
images="dog.jpg"
|
| 17 |
|
|
|
|
| 21 |
|
| 22 |
PIL_image = Image.fromarray(np.uint8(image)).convert('RGB')
|
| 23 |
labels = labels_text.split(",")
|
| 24 |
+
|
| 25 |
+
# Translate
|
|
|
|
|
|
|
|
|
|
| 26 |
tokenizer.src_lang = "en"
|
| 27 |
encodedText = tokenizer(labels_text, return_tensors="pt")
|
| 28 |
generatedTokens = model.generate(**encodedText, forced_bos_token_id=tokenizer.get_lang_id("ru"))
|
| 29 |
return tokenizer.batch_decode(generatedTokens, skip_special_tokens=True)[0]
|
| 30 |
|
| 31 |
+
|
| 32 |
+
res = pipe(images=PIL_image,
|
| 33 |
+
candidate_labels=labels,
|
| 34 |
+
hypothesis_template= "This is a photo of a {}")
|
| 35 |
+
return {dic["label"]: dic["score"] for dic in res}
|
| 36 |
+
|
| 37 |
+
|
| 38 |
|
| 39 |
iface = gr.Interface(shot,
|
| 40 |
["image", "text"],
|