Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,34 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import torch
|
3 |
-
from transformers import AutoModelWithLMHead, AutoTokenizer
|
4 |
-
|
5 |
tokenizer = AutoTokenizer.from_pretrained('microsoft/DialoGPT-small', padding_side='right')
|
6 |
model = AutoModelWithLMHead.from_pretrained('tomkr000/scottbotai')
|
7 |
|
8 |
-
def chat(message, history):
|
9 |
-
new_user_input_ids = tokenizer.encode(message + tokenizer.eos_token, return_tensors='pt')
|
10 |
-
bot_input_ids = torch.cat([chat_history_ids, new_user_input_ids], dim=-1) if step > 0 else new_user_input_ids
|
11 |
-
|
12 |
-
chat_history_ids = model.generate(
|
13 |
-
bot_input_ids, max_length=200,
|
14 |
-
pad_token_id=tokenizer.eos_token_id,
|
15 |
-
no_repeat_ngram_size=3,
|
16 |
-
do_sample=True,
|
17 |
-
top_k=100,
|
18 |
-
top_p=0.7,
|
19 |
-
temperature = 0.8
|
20 |
-
)
|
21 |
-
|
22 |
-
response = tokenizer.decode(chat_history_ids[:, bot_input_ids.shape[-1]:][0], skip_special_tokens=True)
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
history.append((message, response))
|
25 |
-
|
26 |
return history, history
|
|
|
27 |
|
28 |
-
chatbot = gr.Chatbot().style(color_map=("green", "pink"))
|
29 |
|
30 |
demo = gr.Interface(
|
31 |
-
chat,
|
32 |
-
["text", "state"],
|
33 |
-
[chatbot, "state"],
|
34 |
allow_flagging="never",
|
35 |
-
)
|
36 |
|
37 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
1 |
tokenizer = AutoTokenizer.from_pretrained('microsoft/DialoGPT-small', padding_side='right')
|
2 |
model = AutoModelWithLMHead.from_pretrained('tomkr000/scottbotai')
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
+
def chat(message, history=[]):
|
6 |
+
|
7 |
+
inputs = tokenizer.encode(message + tokenizer.eos_token, return_tensors="pt")
|
8 |
+
|
9 |
+
reply_ids = model.generate(
|
10 |
+
inputs, max_length=1000,
|
11 |
+
pad_token_id=tokenizer.eos_token_id,
|
12 |
+
no_repeat_ngram_size=3,
|
13 |
+
do_sample=True,
|
14 |
+
top_k=100,
|
15 |
+
top_p=0.7,
|
16 |
+
temperature = 0.8
|
17 |
+
)
|
18 |
+
|
19 |
+
response = tokenizer.decode(reply_ids[:,inputs.shape[1]:][0], skip_special_tokens=True)
|
20 |
+
|
21 |
history.append((message, response))
|
22 |
+
|
23 |
return history, history
|
24 |
+
|
25 |
|
26 |
+
# chatbot = gr.Chatbot().style(color_map=("green", "pink"))
|
27 |
|
28 |
demo = gr.Interface(
|
29 |
+
fn=chat,
|
30 |
+
inputs = ["text", "state"],
|
31 |
+
outputs = ['chatbot', "state"],
|
32 |
allow_flagging="never",
|
33 |
+
).launch()
|
34 |
|
|