Spaces:
Runtime error
Runtime error
kingabzpro
commited on
Commit
•
f76e9f3
1
Parent(s):
7b8ccff
Update app.py
Browse files
app.py
CHANGED
@@ -16,5 +16,26 @@ The bot is trained on Rick and Morty dialogues Kaggle Dataset using DialoGPT.
|
|
16 |
"""
|
17 |
article = "<p style='text-align: center'><a href='https://medium.com/geekculture/discord-bot-using-dailogpt-and-huggingface-api-c71983422701' target='_blank'>Complete Tutorial</a></p><p style='text-align: center'><a href='https://dagshub.com/kingabzpro/DailoGPT-RickBot' target='_blank'>Project is Available at DAGsHub</a></p></center></p>"
|
18 |
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
|
|
16 |
"""
|
17 |
article = "<p style='text-align: center'><a href='https://medium.com/geekculture/discord-bot-using-dailogpt-and-huggingface-api-c71983422701' target='_blank'>Complete Tutorial</a></p><p style='text-align: center'><a href='https://dagshub.com/kingabzpro/DailoGPT-RickBot' target='_blank'>Project is Available at DAGsHub</a></p></center></p>"
|
18 |
|
19 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
20 |
+
import torch
|
21 |
+
|
22 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium")
|
23 |
+
model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-medium")
|
24 |
+
|
25 |
+
def predict(input, history=[]):
|
26 |
+
# tokenize the new input sentence
|
27 |
+
new_user_input_ids = tokenizer.encode(input + tokenizer.eos_token, return_tensors='pt')
|
28 |
+
|
29 |
+
# append the new user input tokens to the chat history
|
30 |
+
bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)
|
31 |
+
|
32 |
+
# generate a response
|
33 |
+
history = model.generate(bot_input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id).tolist()
|
34 |
+
|
35 |
+
# convert the tokens to text, and then split the responses into lines
|
36 |
+
response = tokenizer.decode(history[0]).replace("<|endoftext|>", "\n")
|
37 |
+
|
38 |
+
return response, history
|
39 |
+
|
40 |
+
gr.Interface(predict,"textbox","chatbot",theme ="grass", title = title, flagging_callback=hf_writer,description = description, article = article).launch(enable_queue=True) # customizes the input component
|
41 |
|