Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +33 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 FSMTForConditionalGeneration, FSMTTokenizer
|
9 |
+
mname = "facebook/wmt19-en-de"
|
10 |
+
tokenizer = FSMTTokenizer.from_pretrained(mname)
|
11 |
+
model = FSMTForConditionalGeneration.from_pretrained(mname)
|
12 |
+
|
13 |
+
input_ids = tokenizer.encode(input, return_tensors="pt")
|
14 |
+
outputs = model.generate(input_ids)
|
15 |
+
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
16 |
+
|
17 |
+
mname = "facebook/wmt19-de-en"
|
18 |
+
tokenizer = FSMTTokenizer.from_pretrained(mname)
|
19 |
+
model = FSMTForConditionalGeneration.from_pretrained(mname)
|
20 |
+
|
21 |
+
input_ids = tokenizer.encode(decoded, return_tensors="pt")
|
22 |
+
outputs = model.generate(input_ids)
|
23 |
+
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
24 |
+
return decoded
|
25 |
+
|
26 |
+
|
27 |
+
iface = gr.Interface(fn=text,
|
28 |
+
inputs=[
|
29 |
+
gr.inputs.Textbox(
|
30 |
+
lines=2, placeholder=None, label='Sentence'),
|
31 |
+
],
|
32 |
+
outputs=[gr.outputs.JSON(label=None)])
|
33 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
transformers
|
3 |
+
sacremoses
|
4 |
+
torch
|
5 |
+
sentencepiece
|