Spaces:
Runtime error
Runtime error
Commit
·
283770b
1
Parent(s):
16fdcc8
Update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,7 @@ import torch
|
|
10 |
import torch.nn.functional as F
|
11 |
from open_clip import create_model, get_tokenizer
|
12 |
from torchvision import transforms
|
|
|
13 |
|
14 |
from templates import openai_imagenet_template
|
15 |
|
@@ -43,6 +44,40 @@ preprocess_img = transforms.Compose(
|
|
43 |
|
44 |
ranks = ("Kingdom", "Phylum", "Class", "Order", "Family", "Genus", "Species")
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
open_domain_examples = [
|
47 |
["examples/Ursus-arctos.jpeg", "Species"],
|
48 |
["examples/Phoca-vitulina.png", "Species"],
|
|
|
10 |
import torch.nn.functional as F
|
11 |
from open_clip import create_model, get_tokenizer
|
12 |
from torchvision import transforms
|
13 |
+
import translators as ts
|
14 |
|
15 |
from templates import openai_imagenet_template
|
16 |
|
|
|
44 |
|
45 |
ranks = ("Kingdom", "Phylum", "Class", "Order", "Family", "Genus", "Species")
|
46 |
|
47 |
+
languages = ["English", "Spanish", "French", "German", "Chinese"]
|
48 |
+
|
49 |
+
def translate(text, source_lang, target_lang):
|
50 |
+
return ts.google(text, from_language=source_lang, to_language=target_lang)
|
51 |
+
|
52 |
+
def translate_output(output, target_lang):
|
53 |
+
if target_lang == "English":
|
54 |
+
return output
|
55 |
+
translated = {}
|
56 |
+
for k, v in output.items():
|
57 |
+
translated[translate(k, "English", target_lang)] = v
|
58 |
+
return translated
|
59 |
+
# Rest of code
|
60 |
+
|
61 |
+
with gr.Row():
|
62 |
+
language_select = gr.Radio(choices=languages, value="English")
|
63 |
+
|
64 |
+
open_domain_btn.click(
|
65 |
+
fn=lambda img, rank: translate_output(
|
66 |
+
open_domain_classification(img, rank),
|
67 |
+
language_select.value
|
68 |
+
),
|
69 |
+
inputs=[img_input, rank_dropdown],
|
70 |
+
outputs=[open_domain_output]
|
71 |
+
)
|
72 |
+
zero_shot_btn.click(
|
73 |
+
fn=lambda img, classes: translate_output(
|
74 |
+
zero_shot_classification(img, classes),
|
75 |
+
language_select.value
|
76 |
+
),
|
77 |
+
inputs=[img_input, classes_txt],
|
78 |
+
outputs=zero_shot_output
|
79 |
+
)
|
80 |
+
|
81 |
open_domain_examples = [
|
82 |
["examples/Ursus-arctos.jpeg", "Species"],
|
83 |
["examples/Phoca-vitulina.png", "Species"],
|