Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -81,7 +81,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"), cs
|
|
81 |
regenerate_button = gr.Button("🔄 Regenerate")
|
82 |
|
83 |
|
84 |
-
# --- 4. EVENT HANDLERS (
|
85 |
def user_submit(user_message, history, system, temp, top_p):
|
86 |
yield gr.update(value=""), history + [[user_message, None]]
|
87 |
for updated_history in chat_stream(user_message, history, system, temp, top_p):
|
@@ -95,23 +95,31 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"), cs
|
|
95 |
|
96 |
clear_button.click(clear_chat, [], [chatbot, chat_history], queue=False)
|
97 |
|
|
|
98 |
def regenerate_response(history, system, temp, top_p):
|
|
|
|
|
|
|
|
|
99 |
if not history:
|
100 |
-
|
101 |
return
|
102 |
|
103 |
last_user_message = history[-1][0]
|
104 |
-
history
|
|
|
105 |
|
106 |
-
for updated_history in chat_stream(last_user_message,
|
107 |
-
#
|
108 |
-
|
109 |
-
yield updated_history, updated_history
|
110 |
|
|
|
111 |
regenerate_button.click(
|
112 |
regenerate_response,
|
|
|
113 |
[chat_history, system_prompt, temperature, top_p],
|
114 |
-
|
|
|
115 |
)
|
116 |
|
117 |
# --- 5. LAUNCH THE APP ---
|
|
|
81 |
regenerate_button = gr.Button("🔄 Regenerate")
|
82 |
|
83 |
|
84 |
+
# --- 4. EVENT HANDLERS (RADICALLY SIMPLIFIED) ---
|
85 |
def user_submit(user_message, history, system, temp, top_p):
|
86 |
yield gr.update(value=""), history + [[user_message, None]]
|
87 |
for updated_history in chat_stream(user_message, history, system, temp, top_p):
|
|
|
95 |
|
96 |
clear_button.click(clear_chat, [], [chatbot, chat_history], queue=False)
|
97 |
|
98 |
+
# --- THIS FUNCTION IS NOW MUCH SIMPLER ---
|
99 |
def regenerate_response(history, system, temp, top_p):
|
100 |
+
"""
|
101 |
+
This simplified function only updates the visible chatbot.
|
102 |
+
It avoids the complex interactions that were causing the startup crash.
|
103 |
+
"""
|
104 |
if not history:
|
105 |
+
# If there's no history, do nothing.
|
106 |
return
|
107 |
|
108 |
last_user_message = history[-1][0]
|
109 |
+
# The history state used for the stream is now managed internally.
|
110 |
+
reduced_history = history[:-1]
|
111 |
|
112 |
+
for updated_history in chat_stream(last_user_message, reduced_history, system, temp, top_p):
|
113 |
+
# The yield now only targets the single output component.
|
114 |
+
yield updated_history
|
|
|
115 |
|
116 |
+
# --- THE CLICK HANDLER IS NOW SIMPLER ---
|
117 |
regenerate_button.click(
|
118 |
regenerate_response,
|
119 |
+
# Inputs remain the same
|
120 |
[chat_history, system_prompt, temperature, top_p],
|
121 |
+
# Output is now ONLY the visible chatbot component
|
122 |
+
[chatbot]
|
123 |
)
|
124 |
|
125 |
# --- 5. LAUNCH THE APP ---
|