Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,32 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
def chat_function(message, history):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
for
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
demo = gr.ChatInterface(
|
| 25 |
fn=chat_function,
|
| 26 |
-
title="
|
| 27 |
description="Ask me anything!"
|
| 28 |
)
|
| 29 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
|
| 4 |
+
model_name = "facebook/blenderbot-400M-distill"
|
| 5 |
+
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 8 |
|
| 9 |
def chat_function(message, history):
|
| 10 |
+
|
| 11 |
+
history_text = ""
|
| 12 |
+
|
| 13 |
+
for user, bot in history:
|
| 14 |
+
history_text += user + " " + bot + " "
|
| 15 |
+
|
| 16 |
+
history_text += message
|
| 17 |
+
|
| 18 |
+
inputs = tokenizer(history_text, return_tensors="pt", truncation=True)
|
| 19 |
+
|
| 20 |
+
outputs = model.generate(**inputs, max_new_tokens=60)
|
| 21 |
+
|
| 22 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 23 |
+
|
| 24 |
+
return response
|
| 25 |
+
|
| 26 |
+
|
| 27 |
demo = gr.ChatInterface(
|
| 28 |
fn=chat_function,
|
| 29 |
+
title="BlenderBot Chat",
|
| 30 |
description="Ask me anything!"
|
| 31 |
)
|
| 32 |
|