Spaces:
Runtime error
Runtime error
Added language selector
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
from PIL import Image
|
|
|
4 |
|
5 |
##Image Classification
|
6 |
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
|
@@ -20,8 +21,8 @@ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
|
20 |
modelt = AutoModelForSeq2SeqLM.from_pretrained("facebook/nllb-200-distilled-600M")
|
21 |
tokenizert = AutoTokenizer.from_pretrained("facebook/nllb-200-distilled-600M")
|
22 |
|
23 |
-
def translation(text):
|
24 |
-
translator = pipeline('translation', model=modelt, tokenizer=tokenizert, src_lang="eng_Latn", tgt_lang=
|
25 |
output = translator(text)
|
26 |
return (output[0]['translation_text'])
|
27 |
|
@@ -32,7 +33,8 @@ with demo:
|
|
32 |
b1 = gr.Button("Recognize Image")
|
33 |
text = gr.Textbox()
|
34 |
b1.click(image_to_text, inputs=image_file, outputs=text)
|
|
|
35 |
b2 = gr.Button("Translation")
|
36 |
out1 = gr.Textbox()
|
37 |
-
b2.click(translation, inputs=text, outputs=out1)
|
38 |
demo.launch()
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
from PIL import Image
|
4 |
+
from lang_list import LANG
|
5 |
|
6 |
##Image Classification
|
7 |
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
|
|
|
21 |
modelt = AutoModelForSeq2SeqLM.from_pretrained("facebook/nllb-200-distilled-600M")
|
22 |
tokenizert = AutoTokenizer.from_pretrained("facebook/nllb-200-distilled-600M")
|
23 |
|
24 |
+
def translation(text,target):
|
25 |
+
translator = pipeline('translation', model=modelt, tokenizer=tokenizert, src_lang="eng_Latn", tgt_lang=target)
|
26 |
output = translator(text)
|
27 |
return (output[0]['translation_text'])
|
28 |
|
|
|
33 |
b1 = gr.Button("Recognize Image")
|
34 |
text = gr.Textbox()
|
35 |
b1.click(image_to_text, inputs=image_file, outputs=text)
|
36 |
+
target = gr.Dropdown(LANG,interactive=True,label="Target Language")
|
37 |
b2 = gr.Button("Translation")
|
38 |
out1 = gr.Textbox()
|
39 |
+
b2.click(translation, inputs=[text,target], outputs=out1)
|
40 |
demo.launch()
|