Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +29 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
4 |
+
|
5 |
+
|
6 |
+
|
7 |
+
def text(input):
|
8 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-fr")
|
10 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("Helsinki-NLP/opus-mt-en-fr")
|
11 |
+
input_ids = tokenizer.encode(input, return_tensors="pt")
|
12 |
+
outputs = model.generate(input_ids)
|
13 |
+
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
14 |
+
|
15 |
+
tokenizer = AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-fr-en")
|
16 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("Helsinki-NLP/opus-mt-fr-en")
|
17 |
+
input_ids = tokenizer.encode(decoded, return_tensors="pt")
|
18 |
+
outputs = model.generate(input_ids)
|
19 |
+
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
20 |
+
return decoded
|
21 |
+
|
22 |
+
|
23 |
+
iface = gr.Interface(fn=text,
|
24 |
+
inputs=[
|
25 |
+
gr.inputs.Textbox(
|
26 |
+
lines=2, placeholder=None, label='Sentence'),
|
27 |
+
],
|
28 |
+
outputs=[gr.outputs.JSON(label=None)])
|
29 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
transformers
|
3 |
+
sacremoses
|
4 |
+
torch
|
5 |
+
sentencepiece
|