Spaces:
Sleeping
Sleeping
fix: adds translations
Browse files
app.py
CHANGED
|
@@ -2,12 +2,20 @@ import gradio as gr
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
model_id = "Salesforce/blip-image-captioning-large"
|
|
|
|
|
|
|
| 5 |
caption_eng = pipeline(model=model_id)
|
| 6 |
|
| 7 |
def evaluate(input):
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
iface = gr.Interface(fn=evaluate, inputs=gr.Image(type="pil"), outputs="
|
| 11 |
|
| 12 |
if __name__ == "__main__":
|
| 13 |
iface.launch()
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
model_id = "Salesforce/blip-image-captioning-large"
|
| 5 |
+
translate_model_id = "facebook/nllb-200-distilled-600M"
|
| 6 |
+
|
| 7 |
caption_eng = pipeline(model=model_id)
|
| 8 |
|
| 9 |
def evaluate(input):
|
| 10 |
+
eng = caption_eng(input)[0]["generated_text"]
|
| 11 |
+
nob = translate(eng)
|
| 12 |
+
return {eng: eng, nob: nob}
|
| 13 |
+
|
| 14 |
+
def translate(text, source='eng_Latn', target='nob_Latn'):
|
| 15 |
+
translator = pipeline( model=translate_model_id, src_lang=source, tgt_lang=target)
|
| 16 |
+
return translator(text, max_length=400)
|
| 17 |
|
| 18 |
+
iface = gr.Interface(fn=evaluate, inputs=gr.Image(type="pil"), outputs="json")
|
| 19 |
|
| 20 |
if __name__ == "__main__":
|
| 21 |
iface.launch()
|