Spaces:
Runtime error
Runtime error
Update app.py
Browse filesFix syntax errors
app.py
CHANGED
|
@@ -406,30 +406,31 @@ mdl = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-medium")
|
|
| 406 |
|
| 407 |
def converse(user_input, chat_history=[]):
|
| 408 |
user_input_ids = chat_tkn(user_input + chat_tkn.eos_token, return_tensors='pt').input_ids
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
|
|
|
| 433 |
|
| 434 |
import gradio as grad
|
| 435 |
|
|
|
|
| 406 |
|
| 407 |
def converse(user_input, chat_history=[]):
|
| 408 |
user_input_ids = chat_tkn(user_input + chat_tkn.eos_token, return_tensors='pt').input_ids
|
| 409 |
+
# keep history in the tensor
|
| 410 |
+
bot_input_ids = torch.cat([torch.LongTensor(chat_history), user_input_ids], dim=-1)
|
| 411 |
+
# get response
|
| 412 |
+
chat_history = mdl.generate(bot_input_ids, max_length=1000, pad_token_id=chat_tkn.eos_token_id).tolist()
|
| 413 |
+
print (chat_history)
|
| 414 |
+
response = chat_tkn.decode(chat_history[0]).split("<|endoftext|>")
|
| 415 |
+
print("starting to print response")
|
| 416 |
+
print(response)
|
| 417 |
+
# html for display
|
| 418 |
+
html = "<div class='mybot'>"
|
| 419 |
+
for x, mesg in enumerate(response):
|
| 420 |
+
if x%2!=0 :
|
| 421 |
+
mesg="Alicia:"+mesg
|
| 422 |
+
clazz="alicia"
|
| 423 |
+
else :
|
| 424 |
+
clazz="user"
|
| 425 |
+
print("value of x")
|
| 426 |
+
print(x)
|
| 427 |
+
print("message")
|
| 428 |
+
print (mesg)
|
| 429 |
+
html += "<div class='mesg {}'> {}</div>".format(clazz, mesg)
|
| 430 |
+
html += "</div>"
|
| 431 |
+
print(html)
|
| 432 |
+
|
| 433 |
+
return html, chat_history
|
| 434 |
|
| 435 |
import gradio as grad
|
| 436 |
|