Spaces:
Runtime error
Runtime error
NadiaHassan
commited on
Commit
•
9425467
1
Parent(s):
60bd2b1
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,15 @@
|
|
1 |
from transformers import GPT2LMHeadModel,GPT2Tokenizer
|
2 |
import gradio as grad
|
3 |
-
|
4 |
mdl = GPT2LMHeadModel.from_pretrained('gpt2')
|
5 |
gpt2_tkn=GPT2Tokenizer.from_pretrained('gpt2')
|
6 |
-
|
7 |
-
|
8 |
def generate(starting_text):
|
9 |
tkn_ids = gpt2_tkn.encode(starting_text, return_tensors = 'pt')
|
10 |
-
gpt2_tensors = mdl.generate(tkn_ids)
|
11 |
response=""
|
12 |
#response = gpt2_tensors
|
13 |
for i, x in enumerate(gpt2_tensors):
|
14 |
response=response+f"{i}: {gpt2_tkn.decode(x, skip_special_tokens=True)}"
|
15 |
return response
|
16 |
-
|
17 |
txt=grad.Textbox(lines=1, label="English", placeholder="English Text here")
|
18 |
out=grad.Textbox(lines=1, label="Generated Tensors")
|
19 |
grad.Interface(generate, inputs=txt, outputs=out).launch()
|
|
|
1 |
from transformers import GPT2LMHeadModel,GPT2Tokenizer
|
2 |
import gradio as grad
|
|
|
3 |
mdl = GPT2LMHeadModel.from_pretrained('gpt2')
|
4 |
gpt2_tkn=GPT2Tokenizer.from_pretrained('gpt2')
|
|
|
|
|
5 |
def generate(starting_text):
|
6 |
tkn_ids = gpt2_tkn.encode(starting_text, return_tensors = 'pt')
|
7 |
+
gpt2_tensors = mdl.generate(tkn_ids,max_length=100,no_repeat_ngram_size=True)
|
8 |
response=""
|
9 |
#response = gpt2_tensors
|
10 |
for i, x in enumerate(gpt2_tensors):
|
11 |
response=response+f"{i}: {gpt2_tkn.decode(x, skip_special_tokens=True)}"
|
12 |
return response
|
|
|
13 |
txt=grad.Textbox(lines=1, label="English", placeholder="English Text here")
|
14 |
out=grad.Textbox(lines=1, label="Generated Tensors")
|
15 |
grad.Interface(generate, inputs=txt, outputs=out).launch()
|