Spaces:
Runtime error
Runtime error
Commit
•
8c39a5e
1
Parent(s):
94f5c4a
Update app.py
Browse files
app.py
CHANGED
@@ -10,13 +10,14 @@ model = GPT2LMHeadModel.from_pretrained("ethzanalytics/ai-msgbot-gpt2-XL-dialogu
|
|
10 |
script_speaker_name = "person alpha"
|
11 |
|
12 |
script_responder_name = "person beta"
|
13 |
-
convo = ''
|
14 |
def output(prompt):
|
|
|
15 |
sentence = convo + '\n' + script_speaker_name + ': ' + prompt + '\n' + script_responder_name + ': '
|
16 |
input_ids = tokenizer.encode(sentence, return_tensors='pt')
|
17 |
# generate text until the output length (which includes the context length) reaches 50
|
18 |
output = model.generate(input_ids, max_length=50, num_beams=5, no_repeat_ngram_size=2, early_stopping=True)
|
19 |
convo = tokenizer.decode(output[0], skip_special_tokens=True)
|
|
|
20 |
|
21 |
iface = gr.Interface(fn=output, inputs="text", outputs="text")
|
22 |
iface.launch()
|
|
|
10 |
script_speaker_name = "person alpha"
|
11 |
|
12 |
script_responder_name = "person beta"
|
|
|
13 |
def output(prompt):
|
14 |
+
global convo
|
15 |
sentence = convo + '\n' + script_speaker_name + ': ' + prompt + '\n' + script_responder_name + ': '
|
16 |
input_ids = tokenizer.encode(sentence, return_tensors='pt')
|
17 |
# generate text until the output length (which includes the context length) reaches 50
|
18 |
output = model.generate(input_ids, max_length=50, num_beams=5, no_repeat_ngram_size=2, early_stopping=True)
|
19 |
convo = tokenizer.decode(output[0], skip_special_tokens=True)
|
20 |
+
return convo
|
21 |
|
22 |
iface = gr.Interface(fn=output, inputs="text", outputs="text")
|
23 |
iface.launch()
|