leofome commited on
Commit
ec878e6
·
verified ·
1 Parent(s): 0849afe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -1,12 +1,16 @@
1
- import gradio as gr
 
 
 
 
2
 
3
- description = "Story generation with GPT-2"
4
- title = "Generate your own story"
5
- examples = [["Adventurer is approached by a mysterious stranger in the tavern for a new quest."]]
6
 
7
- interface = gr.Interface.load("huggingface/pranavpsv/gpt2-genre-story-generator",
8
- description=description,
9
- examples=examples
10
- )
11
 
12
- interface.launch()
 
 
 
1
+ from transformers import AutoModelForSeq2SeqLM,AutoTokenizer
2
+ import gradio as grad
3
+ mdl_name = "Helsinki-NLP/opus-mt-es-en"
4
+ mdl = AutoModelForSeq2SeqLM.from_pretrained(mdl_name)
5
+ my_tkn = AutoTokenizer.from_pretrained(mdl_name)
6
 
7
+ #opus_translator = pipeline("translation", model=mdl_name)
 
 
8
 
9
+ def translate(text):
10
+ inputs = my_tkn(text, return_tensors="pt")
11
+ trans_output = mdl.generate(**inputs)
12
+ response = my_tkn.decode(trans_output[0], skip_special_tokens=True)
13
 
14
+ #response = opus_translator(text)
15
+ return response
16
+ grad.Interface(translate, inputs=["text",], outputs="text").launch()