Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -211,12 +211,17 @@ def chat_with_agent(message: str, history: List, model: str) -> tuple:
|
|
| 211 |
{"role": "system", "content": "You are a helpful coding assistant. Help users with programming questions, debugging, and code explanations."}
|
| 212 |
]
|
| 213 |
|
| 214 |
-
# Add conversation history
|
| 215 |
-
for
|
| 216 |
-
if
|
| 217 |
-
messages.append(
|
| 218 |
-
|
| 219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
|
| 221 |
# Add current message
|
| 222 |
messages.append({"role": "user", "content": message})
|
|
@@ -224,8 +229,9 @@ def chat_with_agent(message: str, history: List, model: str) -> tuple:
|
|
| 224 |
# Get response
|
| 225 |
response = coding_agent.make_request(messages, model, temperature=0.7)
|
| 226 |
|
| 227 |
-
# Add to history
|
| 228 |
-
history.append(
|
|
|
|
| 229 |
return history, ""
|
| 230 |
|
| 231 |
# Create the Gradio interface
|
|
@@ -260,7 +266,7 @@ with gr.Blocks(
|
|
| 260 |
|
| 261 |
# AI Chat Interface
|
| 262 |
with gr.Accordion("💬 Chat with AI", open=True):
|
| 263 |
-
chatbot = gr.Chatbot(height=300, show_label=False)
|
| 264 |
chat_input = gr.Textbox(
|
| 265 |
placeholder="Ask the AI about coding, debugging, or request code generation...",
|
| 266 |
show_label=False
|
|
@@ -340,11 +346,12 @@ with gr.Blocks(
|
|
| 340 |
update_preview_btn = gr.Button("🔄 Update Preview", variant="primary")
|
| 341 |
|
| 342 |
with gr.Tab("Python Output"):
|
| 343 |
-
python_output = gr.
|
| 344 |
value="",
|
| 345 |
-
language="text",
|
| 346 |
label="Python Output",
|
| 347 |
-
lines=10
|
|
|
|
|
|
|
| 348 |
)
|
| 349 |
|
| 350 |
run_python_btn = gr.Button("▶️ Run Python", variant="primary")
|
|
|
|
| 211 |
{"role": "system", "content": "You are a helpful coding assistant. Help users with programming questions, debugging, and code explanations."}
|
| 212 |
]
|
| 213 |
|
| 214 |
+
# Add conversation history - convert from messages format
|
| 215 |
+
for msg in history:
|
| 216 |
+
if isinstance(msg, dict):
|
| 217 |
+
messages.append(msg)
|
| 218 |
+
else:
|
| 219 |
+
# Handle old tuple format if any
|
| 220 |
+
user_msg, assistant_msg = msg
|
| 221 |
+
if user_msg:
|
| 222 |
+
messages.append({"role": "user", "content": user_msg})
|
| 223 |
+
if assistant_msg:
|
| 224 |
+
messages.append({"role": "assistant", "content": assistant_msg})
|
| 225 |
|
| 226 |
# Add current message
|
| 227 |
messages.append({"role": "user", "content": message})
|
|
|
|
| 229 |
# Get response
|
| 230 |
response = coding_agent.make_request(messages, model, temperature=0.7)
|
| 231 |
|
| 232 |
+
# Add to history in messages format
|
| 233 |
+
history.append({"role": "user", "content": message})
|
| 234 |
+
history.append({"role": "assistant", "content": response})
|
| 235 |
return history, ""
|
| 236 |
|
| 237 |
# Create the Gradio interface
|
|
|
|
| 266 |
|
| 267 |
# AI Chat Interface
|
| 268 |
with gr.Accordion("💬 Chat with AI", open=True):
|
| 269 |
+
chatbot = gr.Chatbot(height=300, show_label=False, type='messages')
|
| 270 |
chat_input = gr.Textbox(
|
| 271 |
placeholder="Ask the AI about coding, debugging, or request code generation...",
|
| 272 |
show_label=False
|
|
|
|
| 346 |
update_preview_btn = gr.Button("🔄 Update Preview", variant="primary")
|
| 347 |
|
| 348 |
with gr.Tab("Python Output"):
|
| 349 |
+
python_output = gr.Textbox(
|
| 350 |
value="",
|
|
|
|
| 351 |
label="Python Output",
|
| 352 |
+
lines=10,
|
| 353 |
+
max_lines=20,
|
| 354 |
+
interactive=False
|
| 355 |
)
|
| 356 |
|
| 357 |
run_python_btn = gr.Button("▶️ Run Python", variant="primary")
|