Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration
|
| 3 |
|
| 4 |
-
# ✅
|
| 5 |
model_name = "facebook/blenderbot-90M"
|
| 6 |
tokenizer = BlenderbotTokenizer.from_pretrained(model_name)
|
| 7 |
model = BlenderbotForConditionalGeneration.from_pretrained(model_name)
|
|
@@ -26,12 +26,12 @@ def chat_with_bot(messages, state):
|
|
| 26 |
|
| 27 |
conversation = f"{state}User: {user_input}\nBot:"
|
| 28 |
|
| 29 |
-
# ✅ FIX:
|
| 30 |
inputs = tokenizer(
|
| 31 |
conversation,
|
| 32 |
return_tensors="pt",
|
| 33 |
-
padding=True,
|
| 34 |
truncation=True,
|
|
|
|
| 35 |
max_length=512,
|
| 36 |
)
|
| 37 |
|
|
@@ -40,14 +40,13 @@ def chat_with_bot(messages, state):
|
|
| 40 |
|
| 41 |
new_state = f"{conversation} {reply}\n"
|
| 42 |
messages.append({"role": "assistant", "content": reply})
|
| 43 |
-
|
| 44 |
return messages, new_state
|
| 45 |
|
| 46 |
-
# --- Gradio
|
| 47 |
demo = gr.ChatInterface(
|
| 48 |
fn=chat_with_bot,
|
| 49 |
-
title="🤖 Mini Chatbot (BlenderBot-90M)",
|
| 50 |
-
description="
|
| 51 |
theme="soft",
|
| 52 |
type="messages",
|
| 53 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration
|
| 3 |
|
| 4 |
+
# ✅ Use the correct and public model
|
| 5 |
model_name = "facebook/blenderbot-90M"
|
| 6 |
tokenizer = BlenderbotTokenizer.from_pretrained(model_name)
|
| 7 |
model = BlenderbotForConditionalGeneration.from_pretrained(model_name)
|
|
|
|
| 26 |
|
| 27 |
conversation = f"{state}User: {user_input}\nBot:"
|
| 28 |
|
| 29 |
+
# ✅ FIX: Pass plain string (no nested list)
|
| 30 |
inputs = tokenizer(
|
| 31 |
conversation,
|
| 32 |
return_tensors="pt",
|
|
|
|
| 33 |
truncation=True,
|
| 34 |
+
padding='max_length',
|
| 35 |
max_length=512,
|
| 36 |
)
|
| 37 |
|
|
|
|
| 40 |
|
| 41 |
new_state = f"{conversation} {reply}\n"
|
| 42 |
messages.append({"role": "assistant", "content": reply})
|
|
|
|
| 43 |
return messages, new_state
|
| 44 |
|
| 45 |
+
# --- Gradio Interface ---
|
| 46 |
demo = gr.ChatInterface(
|
| 47 |
fn=chat_with_bot,
|
| 48 |
+
title="🤖 Mini Chatbot (Facebook BlenderBot-90M)",
|
| 49 |
+
description="Hi 👋 I’m a conversational chatbot built with Facebook’s BlenderBot-90M model.",
|
| 50 |
theme="soft",
|
| 51 |
type="messages",
|
| 52 |
)
|