Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,7 @@ print(f"Model downloaded to: {model_path}")
|
|
13 |
print("===== Loading model... =====")
|
14 |
llm = Llama(
|
15 |
model_path=model_path,
|
16 |
-
n_ctx=
|
17 |
n_threads=8,
|
18 |
n_gpu_layers=0
|
19 |
)
|
@@ -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,34 +95,22 @@ 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 |
-
# --- 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 ---
|
126 |
if __name__ == "__main__":
|
127 |
demo.queue()
|
128 |
-
|
|
|
|
13 |
print("===== Loading model... =====")
|
14 |
llm = Llama(
|
15 |
model_path=model_path,
|
16 |
+
n_ctx=1096,
|
17 |
n_threads=8,
|
18 |
n_gpu_layers=0
|
19 |
)
|
|
|
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 |
|
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 |
return
|
|
|
101 |
last_user_message = history[-1][0]
|
|
|
102 |
reduced_history = history[:-1]
|
|
|
103 |
for updated_history in chat_stream(last_user_message, reduced_history, system, temp, top_p):
|
|
|
104 |
yield updated_history
|
105 |
|
|
|
106 |
regenerate_button.click(
|
107 |
regenerate_response,
|
|
|
108 |
[chat_history, system_prompt, temperature, top_p],
|
|
|
109 |
[chatbot]
|
110 |
)
|
111 |
|
112 |
+
# --- 5. LAUNCH THE APP (WITH THE BUG FIX) ---
|
113 |
if __name__ == "__main__":
|
114 |
demo.queue()
|
115 |
+
# The show_api=False parameter tells Gradio to not build the API page, avoiding the bug.
|
116 |
+
demo.launch(debug=True, show_api=False)
|