Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,7 +27,7 @@ model.to(device)
|
|
| 27 |
# ----------------------
|
| 28 |
def chat_with_bot(message, history):
|
| 29 |
try:
|
| 30 |
-
#
|
| 31 |
conversation = ""
|
| 32 |
for user_msg, bot_msg in history:
|
| 33 |
conversation += f"User: {user_msg}\nBot: {bot_msg}\n"
|
|
@@ -49,7 +49,7 @@ def chat_with_bot(message, history):
|
|
| 49 |
early_stopping=True
|
| 50 |
)
|
| 51 |
|
| 52 |
-
# Decode only new part
|
| 53 |
reply = tokenizer.decode(outputs[:, inputs.shape[-1]:][0], skip_special_tokens=True)
|
| 54 |
return reply.strip() if reply.strip() else "I'm not sure how to answer that."
|
| 55 |
|
|
@@ -57,24 +57,23 @@ def chat_with_bot(message, history):
|
|
| 57 |
return f"⚠️ Error: {str(e)}"
|
| 58 |
|
| 59 |
# ----------------------
|
| 60 |
-
#
|
| 61 |
# ----------------------
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
chatbot
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
demo.api_name = "chat"
|
| 78 |
|
| 79 |
# Launch
|
| 80 |
if __name__ == "__main__":
|
|
|
|
| 27 |
# ----------------------
|
| 28 |
def chat_with_bot(message, history):
|
| 29 |
try:
|
| 30 |
+
# Convert history to conversation string
|
| 31 |
conversation = ""
|
| 32 |
for user_msg, bot_msg in history:
|
| 33 |
conversation += f"User: {user_msg}\nBot: {bot_msg}\n"
|
|
|
|
| 49 |
early_stopping=True
|
| 50 |
)
|
| 51 |
|
| 52 |
+
# Decode only the new part
|
| 53 |
reply = tokenizer.decode(outputs[:, inputs.shape[-1]:][0], skip_special_tokens=True)
|
| 54 |
return reply.strip() if reply.strip() else "I'm not sure how to answer that."
|
| 55 |
|
|
|
|
| 57 |
return f"⚠️ Error: {str(e)}"
|
| 58 |
|
| 59 |
# ----------------------
|
| 60 |
+
# Use ChatInterface instead of Blocks
|
| 61 |
# ----------------------
|
| 62 |
+
demo = gr.ChatInterface(
|
| 63 |
+
fn=chat_with_bot,
|
| 64 |
+
title="My Fitlien Chatbot",
|
| 65 |
+
description="A chatbot fine-tuned from DialoGPT-medium for fitness conversations.",
|
| 66 |
+
examples=[
|
| 67 |
+
"Hello! How are you?",
|
| 68 |
+
"What's a good workout routine?",
|
| 69 |
+
"Tell me about nutrition",
|
| 70 |
+
"How can I stay motivated?"
|
| 71 |
+
],
|
| 72 |
+
retry_btn=None,
|
| 73 |
+
undo_btn="Delete Previous",
|
| 74 |
+
clear_btn="Clear",
|
| 75 |
+
submit_btn="Submit"
|
| 76 |
+
)
|
|
|
|
| 77 |
|
| 78 |
# Launch
|
| 79 |
if __name__ == "__main__":
|