Create app.py
Browse filesinitial demo app.
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
4 |
+
|
5 |
+
modelcard = "amurienne/gallek-m2m100"
|
6 |
+
|
7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(modelcard)
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(modelcard)
|
9 |
+
|
10 |
+
def translate(text):
|
11 |
+
"""
|
12 |
+
Translate the text from source lang fr to target lang br
|
13 |
+
"""
|
14 |
+
translation_pipeline = pipeline("translation", model=model, tokenizer=tokenizer, src_lang='fr', tgt_lang='br', max_length=400, device="cuda")
|
15 |
+
result = translation_pipeline(text)
|
16 |
+
return result[0]['translation_text']
|
17 |
+
|
18 |
+
demo = gr.Interface(
|
19 |
+
fn=translate,
|
20 |
+
inputs=[
|
21 |
+
gr.components.Textbox(label="Text"),
|
22 |
+
],
|
23 |
+
outputs=["text"],
|
24 |
+
cache_examples=False,
|
25 |
+
title="Gallek Translation Demo",
|
26 |
+
)
|
27 |
+
|
28 |
+
demo.launch()
|