Spaces:
Running
Running
alirezamsh
commited on
Commit
•
df7bba0
1
Parent(s):
b1ccaf1
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
|
4 |
+
os.system("pip install transformers sentencepiece torch")
|
5 |
+
|
6 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
7 |
+
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained("alirezamsh/small100")
|
9 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("alirezamsh/small100")
|
10 |
+
|
11 |
+
def fn(text, lang):
|
12 |
+
tokenizer.tgt_lang = lang
|
13 |
+
encoded = tokenizer(text, return_tensors="pt")
|
14 |
+
generated_tokens = model.generate(**encoded)
|
15 |
+
return tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
|
16 |
+
|
17 |
+
demo = gr.Interface(fn=fn, inputs=["text", "text"], outputs="text")
|
18 |
+
demo.launch()
|