Spaces:
Runtime error
Runtime error
Commit
•
7c05614
0
Parent(s):
add app files
Browse files- .gitignore +3 -0
- app.py +31 -0
- requirements.txt +4 -0
.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
__pycache__
|
2 |
+
.python-version
|
3 |
+
venv
|
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import logging
|
3 |
+
from transformers import AutoTokenizer, TFAutoModelForSeq2SeqLM, pipeline
|
4 |
+
|
5 |
+
|
6 |
+
# Suppress tokenizer warnings
|
7 |
+
logging.disable(logging.WARNING)
|
8 |
+
|
9 |
+
|
10 |
+
model_name = 'Helsinki-NLP/opus-mt-en-es'
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
12 |
+
model = TFAutoModelForSeq2SeqLM.from_pretrained(model_name)
|
13 |
+
translator = pipeline("translation", model=model, tokenizer=tokenizer)
|
14 |
+
|
15 |
+
def translate(en_input):
|
16 |
+
response = translator(en_input)
|
17 |
+
return response[0]['translation_text']
|
18 |
+
|
19 |
+
# Gradio app
|
20 |
+
def create_inputs():
|
21 |
+
en_input = gr.inputs.Textbox(label='English text', lines=5)
|
22 |
+
return [en_input]
|
23 |
+
|
24 |
+
app = gr.Interface(
|
25 |
+
inputs = create_inputs(),
|
26 |
+
outputs = gr.Textbox(label='Spanish translation', lines=5),
|
27 |
+
fn=translate,
|
28 |
+
title='English to Spanish translator',
|
29 |
+
examples=['Hello world!']
|
30 |
+
)
|
31 |
+
app.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==3.27.0
|
2 |
+
tensorflow-macos==2.12.0
|
3 |
+
sentencepiece
|
4 |
+
transformers
|