Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -58,9 +58,11 @@ def chat_fn(message, history, mode, model, image, include_ascii):
|
|
| 58 |
system_prompt = MODE_PROMPTS.get(mode, MODE_PROMPTS["Normal Chat"])
|
| 59 |
messages = [{"role": "system", "content": system_prompt}]
|
| 60 |
|
| 61 |
-
# 2.
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
| 64 |
|
| 65 |
# 3. Process current input
|
| 66 |
user_input_text = str(message).strip()
|
|
@@ -88,8 +90,8 @@ with gr.Blocks() as demo:
|
|
| 88 |
mode_dd = gr.Dropdown(choices=list(MODE_PROMPTS.keys()), value="Normal Chat", label="Mode")
|
| 89 |
model_dd = gr.Dropdown(choices=["llama-3.1-8b-instant", "llama-3.1-70b-versatile"], value=DEFAULT_MODEL, label="Model")
|
| 90 |
|
| 91 |
-
#
|
| 92 |
-
chatbot = gr.Chatbot(height=450, type="
|
| 93 |
|
| 94 |
with gr.Row():
|
| 95 |
user_input = gr.Textbox(placeholder="Ask anything...", show_label=False, scale=4)
|
|
@@ -102,9 +104,8 @@ with gr.Blocks() as demo:
|
|
| 102 |
# 1. Get the bot's response
|
| 103 |
bot_message = chat_fn(msg, chat_history, mode, model, img, ascii_on)
|
| 104 |
|
| 105 |
-
#
|
| 106 |
-
chat_history.append(
|
| 107 |
-
chat_history.append({"role": "assistant", "content": bot_message})
|
| 108 |
|
| 109 |
# 3. Return history and clear the input box
|
| 110 |
return chat_history, ""
|
|
|
|
| 58 |
system_prompt = MODE_PROMPTS.get(mode, MODE_PROMPTS["Normal Chat"])
|
| 59 |
messages = [{"role": "system", "content": system_prompt}]
|
| 60 |
|
| 61 |
+
# 2. Convert Gradio's history (list of lists) to Groq's format (list of dicts)
|
| 62 |
+
if history:
|
| 63 |
+
for user_msg, bot_msg in history:
|
| 64 |
+
if user_msg: messages.append({"role": "user", "content": str(user_msg)})
|
| 65 |
+
if bot_msg: messages.append({"role": "assistant", "content": str(bot_msg)})
|
| 66 |
|
| 67 |
# 3. Process current input
|
| 68 |
user_input_text = str(message).strip()
|
|
|
|
| 90 |
mode_dd = gr.Dropdown(choices=list(MODE_PROMPTS.keys()), value="Normal Chat", label="Mode")
|
| 91 |
model_dd = gr.Dropdown(choices=["llama-3.1-8b-instant", "llama-3.1-70b-versatile"], value=DEFAULT_MODEL, label="Model")
|
| 92 |
|
| 93 |
+
# Force classic tuple format for history
|
| 94 |
+
chatbot = gr.Chatbot(height=450, type="tuple")
|
| 95 |
|
| 96 |
with gr.Row():
|
| 97 |
user_input = gr.Textbox(placeholder="Ask anything...", show_label=False, scale=4)
|
|
|
|
| 104 |
# 1. Get the bot's response
|
| 105 |
bot_message = chat_fn(msg, chat_history, mode, model, img, ascii_on)
|
| 106 |
|
| 107 |
+
# 2. Append the new interaction as a TUPLE (user, bot)
|
| 108 |
+
chat_history.append((msg, bot_message))
|
|
|
|
| 109 |
|
| 110 |
# 3. Return history and clear the input box
|
| 111 |
return chat_history, ""
|