Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,24 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
def chat(message, history):
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
gr.ChatInterface(fn=chat).launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
model_name = "microsoft/DialoGPT-medium"
|
| 6 |
+
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 9 |
|
| 10 |
def chat(message, history):
|
| 11 |
+
if not message:
|
| 12 |
+
return ""
|
| 13 |
+
|
| 14 |
+
new_user_input_ids = tokenizer.encode(message + tokenizer.eos_token, return_tensors='pt')
|
| 15 |
+
|
| 16 |
+
bot_input_ids = new_user_input_ids
|
| 17 |
+
|
| 18 |
+
chat_history_ids = model.generate(bot_input_ids, max_length=200, pad_token_id=tokenizer.eos_token_id)
|
| 19 |
+
|
| 20 |
+
response = tokenizer.decode(chat_history_ids[:, bot_input_ids.shape[-1]:][0], skip_special_tokens=True)
|
| 21 |
+
|
| 22 |
+
return response
|
| 23 |
|
| 24 |
gr.ChatInterface(fn=chat).launch()
|