Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -53,9 +53,19 @@ def generate_text(prompt, max_new_tokens=80, temperature=0.7):
|
|
| 53 |
def chat_interface(message, history):
|
| 54 |
"""Formats the Gradio UI input to match your dataset's User/Bot structure."""
|
| 55 |
prompt = ""
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
# Inject current message
|
| 61 |
prompt += f"User: {message}\nBot:"
|
|
|
|
| 53 |
def chat_interface(message, history):
|
| 54 |
"""Formats the Gradio UI input to match your dataset's User/Bot structure."""
|
| 55 |
prompt = ""
|
| 56 |
+
|
| 57 |
+
# Inject context memory (Handles both Gradio 4 and Gradio 5 formats)
|
| 58 |
+
for msg in history:
|
| 59 |
+
# Gradio 5 format: dictionaries with 'role' and 'content'
|
| 60 |
+
if isinstance(msg, dict):
|
| 61 |
+
if msg.get("role") == "user":
|
| 62 |
+
prompt += f"User: {msg.get('content')}\n"
|
| 63 |
+
elif msg.get("role") == "assistant":
|
| 64 |
+
prompt += f"Bot: {msg.get('content')}\n"
|
| 65 |
+
|
| 66 |
+
# Fallback for Gradio 4 format: [user_msg, bot_msg]
|
| 67 |
+
elif isinstance(msg, (list, tuple)) and len(msg) == 2:
|
| 68 |
+
prompt += f"User: {msg[0]}\nBot: {msg[1]}\n"
|
| 69 |
|
| 70 |
# Inject current message
|
| 71 |
prompt += f"User: {message}\nBot:"
|