Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import requests
|
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
import time
|
|
|
|
| 6 |
from configparser import ConfigParser
|
| 7 |
from typing import List, Dict, Any
|
| 8 |
|
|
@@ -47,7 +48,7 @@ def load_client_config():
|
|
| 47 |
except Exception as e:
|
| 48 |
print(f"Config parsing warning: {e}")
|
| 49 |
|
| 50 |
-
#
|
| 51 |
if 'API' in parser:
|
| 52 |
config['coder_default'] = parser['API'].get('coder_model_default_label', '').strip()
|
| 53 |
config['strategist_default'] = parser['API'].get('strategist_model_default_label', '').strip()
|
|
@@ -162,7 +163,7 @@ def build_master_log(system_log_list, coder_log_list, strategist_log_list, audit
|
|
| 162 |
master_entries.append(html_entry)
|
| 163 |
seq_counter += 1
|
| 164 |
|
| 165 |
-
#
|
| 166 |
for diagnostic in audit_log_list:
|
| 167 |
elapsed = time.time() - start_time
|
| 168 |
minutes = int(elapsed // 60)
|
|
@@ -272,7 +273,6 @@ def execute_remote_workflow(blueprint, intent, coder_model_label, strategist_mod
|
|
| 272 |
strategist_log_list, audit_log_list,
|
| 273 |
mission_start_time, final_code)
|
| 274 |
|
| 275 |
-
# DIRECTIVE #3: Return final_code as separate output
|
| 276 |
yield sys_log, cod_log, strat_log, master_log, final_code
|
| 277 |
|
| 278 |
except requests.exceptions.RequestException as e:
|
|
@@ -292,7 +292,7 @@ def create_interface():
|
|
| 292 |
Produce a pro level styled and tuned them GUI that has 1 button that when pressed displays a celebration announcement "Happy Birthday MCP!". USE specified colors or themes appropriate for the event. You must incorporate specific colors for design pieces and thematic layouts providing a fun and exciting announcement."""
|
| 293 |
DEMO_INTENT = """A simple test button with a clean look. That when pressed creates a simple happy birthday MCP response on the screen. The gui should be gradio and contain colors that are used in professional builds and match the Gradio, MCP or other color theme or as close as possible."""
|
| 294 |
|
| 295 |
-
#
|
| 296 |
coder_default = CLIENT_CONFIG['coder_default']
|
| 297 |
strategist_default = CLIENT_CONFIG['strategist_default']
|
| 298 |
|
|
@@ -310,7 +310,7 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 310 |
initial_coder_models = CLIENT_CONFIG['coder_by_provider'].get(initial_coder_provider, [])
|
| 311 |
initial_strategist_models = CLIENT_CONFIG['strategist_by_provider'].get(initial_strategist_provider, [])
|
| 312 |
|
| 313 |
-
#
|
| 314 |
coder_initial_value = coder_default if coder_default and coder_default in initial_coder_models else (initial_coder_models[0] if initial_coder_models else None)
|
| 315 |
strategist_initial_value = strategist_default if strategist_default and strategist_default in initial_strategist_models else (initial_strategist_models[0] if initial_strategist_models else None)
|
| 316 |
|
|
@@ -330,8 +330,20 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 330 |
def start_execution_sequence():
|
| 331 |
return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
|
| 332 |
|
|
|
|
| 333 |
def end_execution_sequence(sys_log, cod_log, strat_log, master_log, final_code):
|
| 334 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
|
| 336 |
def reset_to_default():
|
| 337 |
return gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)
|
|
@@ -349,17 +361,24 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 349 |
return gr.update(choices=[], value=None)
|
| 350 |
return gr.update(choices=models, value=models[0])
|
| 351 |
|
| 352 |
-
#
|
| 353 |
def download_code(final_code_content):
|
| 354 |
"""Generate downloadable Python file from final code"""
|
| 355 |
-
if not final_code_content:
|
| 356 |
return None
|
| 357 |
|
| 358 |
# Create temporary file with timestamp
|
| 359 |
timestamp = time.strftime("%Y%m%d_%H%M%S")
|
| 360 |
filename = f"generated_code_{timestamp}.py"
|
| 361 |
|
| 362 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 363 |
|
| 364 |
# RESET MISSION function
|
| 365 |
def reset_mission():
|
|
@@ -382,7 +401,8 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 382 |
gr.update(value=initial_strategist_provider), # strategist_provider
|
| 383 |
gr.update(choices=strategist_models_for_reset, value=strategist_reset_value), # strategist_model
|
| 384 |
gr.update(value=False), # audit_checkbox
|
| 385 |
-
None # final_code_state
|
|
|
|
| 386 |
)
|
| 387 |
|
| 388 |
with gr.Blocks(title="Project: Conductor V4.0 Client") as interface:
|
|
@@ -405,7 +425,7 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 405 |
)
|
| 406 |
coder_model = gr.Dropdown(
|
| 407 |
choices=initial_coder_models,
|
| 408 |
-
value=coder_initial_value,
|
| 409 |
label="Model",
|
| 410 |
interactive=True
|
| 411 |
)
|
|
@@ -454,7 +474,7 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 454 |
)
|
| 455 |
strategist_model = gr.Dropdown(
|
| 456 |
choices=initial_strategist_models,
|
| 457 |
-
value=strategist_initial_value,
|
| 458 |
label="Model",
|
| 459 |
interactive=True
|
| 460 |
)
|
|
@@ -483,9 +503,13 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 483 |
label="MASTER LOG WINDOW"
|
| 484 |
)
|
| 485 |
|
| 486 |
-
#
|
| 487 |
with gr.Row():
|
| 488 |
-
download_btn = gr.DownloadButton(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 489 |
|
| 490 |
# EVENT HANDLERS
|
| 491 |
|
|
@@ -521,10 +545,10 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 521 |
).then(
|
| 522 |
fn=end_execution_sequence,
|
| 523 |
inputs=[system_terminal, coder_log, strategist_log, master_log_output, final_code_state],
|
| 524 |
-
outputs=[system_terminal, coder_log, strategist_log, master_log_output, final_code_state, working_video, celebrate_video]
|
| 525 |
)
|
| 526 |
|
| 527 |
-
#
|
| 528 |
download_btn.click(
|
| 529 |
fn=download_code,
|
| 530 |
inputs=[final_code_state],
|
|
@@ -538,7 +562,7 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 538 |
outputs=[default_image, working_video, celebrate_video]
|
| 539 |
)
|
| 540 |
|
| 541 |
-
# RESET MISSION button
|
| 542 |
reset_btn.click(
|
| 543 |
fn=reset_mission,
|
| 544 |
inputs=[],
|
|
@@ -554,7 +578,8 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 554 |
strategist_provider,
|
| 555 |
strategist_model,
|
| 556 |
audit_checkbox,
|
| 557 |
-
final_code_state
|
|
|
|
| 558 |
]
|
| 559 |
)
|
| 560 |
|
|
|
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
import time
|
| 6 |
+
import tempfile
|
| 7 |
from configparser import ConfigParser
|
| 8 |
from typing import List, Dict, Any
|
| 9 |
|
|
|
|
| 48 |
except Exception as e:
|
| 49 |
print(f"Config parsing warning: {e}")
|
| 50 |
|
| 51 |
+
# Read defaults from config.ini [API] section
|
| 52 |
if 'API' in parser:
|
| 53 |
config['coder_default'] = parser['API'].get('coder_model_default_label', '').strip()
|
| 54 |
config['strategist_default'] = parser['API'].get('strategist_model_default_label', '').strip()
|
|
|
|
| 163 |
master_entries.append(html_entry)
|
| 164 |
seq_counter += 1
|
| 165 |
|
| 166 |
+
# Enhanced tool failure logging
|
| 167 |
for diagnostic in audit_log_list:
|
| 168 |
elapsed = time.time() - start_time
|
| 169 |
minutes = int(elapsed // 60)
|
|
|
|
| 273 |
strategist_log_list, audit_log_list,
|
| 274 |
mission_start_time, final_code)
|
| 275 |
|
|
|
|
| 276 |
yield sys_log, cod_log, strat_log, master_log, final_code
|
| 277 |
|
| 278 |
except requests.exceptions.RequestException as e:
|
|
|
|
| 292 |
Produce a pro level styled and tuned them GUI that has 1 button that when pressed displays a celebration announcement "Happy Birthday MCP!". USE specified colors or themes appropriate for the event. You must incorporate specific colors for design pieces and thematic layouts providing a fun and exciting announcement."""
|
| 293 |
DEMO_INTENT = """A simple test button with a clean look. That when pressed creates a simple happy birthday MCP response on the screen. The gui should be gradio and contain colors that are used in professional builds and match the Gradio, MCP or other color theme or as close as possible."""
|
| 294 |
|
| 295 |
+
# Use config defaults explicitly
|
| 296 |
coder_default = CLIENT_CONFIG['coder_default']
|
| 297 |
strategist_default = CLIENT_CONFIG['strategist_default']
|
| 298 |
|
|
|
|
| 310 |
initial_coder_models = CLIENT_CONFIG['coder_by_provider'].get(initial_coder_provider, [])
|
| 311 |
initial_strategist_models = CLIENT_CONFIG['strategist_by_provider'].get(initial_strategist_provider, [])
|
| 312 |
|
| 313 |
+
# Ensure default value is set or fallback to first available
|
| 314 |
coder_initial_value = coder_default if coder_default and coder_default in initial_coder_models else (initial_coder_models[0] if initial_coder_models else None)
|
| 315 |
strategist_initial_value = strategist_default if strategist_default and strategist_default in initial_strategist_models else (initial_strategist_models[0] if initial_strategist_models else None)
|
| 316 |
|
|
|
|
| 330 |
def start_execution_sequence():
|
| 331 |
return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
|
| 332 |
|
| 333 |
+
# ISSUE #1 FIX: Button visibility control in end sequence
|
| 334 |
def end_execution_sequence(sys_log, cod_log, strat_log, master_log, final_code):
|
| 335 |
+
# Button becomes visible only when final_code exists
|
| 336 |
+
button_visibility = final_code is not None and final_code.strip() != ""
|
| 337 |
+
return (
|
| 338 |
+
sys_log,
|
| 339 |
+
cod_log,
|
| 340 |
+
strat_log,
|
| 341 |
+
master_log,
|
| 342 |
+
final_code,
|
| 343 |
+
gr.update(visible=False), # working_video
|
| 344 |
+
gr.update(visible=True), # celebrate_video
|
| 345 |
+
gr.update(visible=button_visibility) # download_btn
|
| 346 |
+
)
|
| 347 |
|
| 348 |
def reset_to_default():
|
| 349 |
return gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)
|
|
|
|
| 361 |
return gr.update(choices=[], value=None)
|
| 362 |
return gr.update(choices=models, value=models[0])
|
| 363 |
|
| 364 |
+
# ISSUE #2 FIX: Download code function with proper file handling
|
| 365 |
def download_code(final_code_content):
|
| 366 |
"""Generate downloadable Python file from final code"""
|
| 367 |
+
if not final_code_content or final_code_content.strip() == "":
|
| 368 |
return None
|
| 369 |
|
| 370 |
# Create temporary file with timestamp
|
| 371 |
timestamp = time.strftime("%Y%m%d_%H%M%S")
|
| 372 |
filename = f"generated_code_{timestamp}.py"
|
| 373 |
|
| 374 |
+
# Write to temporary file and return filepath
|
| 375 |
+
temp_dir = tempfile.gettempdir()
|
| 376 |
+
filepath = os.path.join(temp_dir, filename)
|
| 377 |
+
|
| 378 |
+
with open(filepath, 'w', encoding='utf-8') as f:
|
| 379 |
+
f.write(final_code_content)
|
| 380 |
+
|
| 381 |
+
return filepath
|
| 382 |
|
| 383 |
# RESET MISSION function
|
| 384 |
def reset_mission():
|
|
|
|
| 401 |
gr.update(value=initial_strategist_provider), # strategist_provider
|
| 402 |
gr.update(choices=strategist_models_for_reset, value=strategist_reset_value), # strategist_model
|
| 403 |
gr.update(value=False), # audit_checkbox
|
| 404 |
+
None, # final_code_state
|
| 405 |
+
gr.update(visible=False) # ISSUE #1 FIX: Hide download button on reset
|
| 406 |
)
|
| 407 |
|
| 408 |
with gr.Blocks(title="Project: Conductor V4.0 Client") as interface:
|
|
|
|
| 425 |
)
|
| 426 |
coder_model = gr.Dropdown(
|
| 427 |
choices=initial_coder_models,
|
| 428 |
+
value=coder_initial_value,
|
| 429 |
label="Model",
|
| 430 |
interactive=True
|
| 431 |
)
|
|
|
|
| 474 |
)
|
| 475 |
strategist_model = gr.Dropdown(
|
| 476 |
choices=initial_strategist_models,
|
| 477 |
+
value=strategist_initial_value,
|
| 478 |
label="Model",
|
| 479 |
interactive=True
|
| 480 |
)
|
|
|
|
| 503 |
label="MASTER LOG WINDOW"
|
| 504 |
)
|
| 505 |
|
| 506 |
+
# ISSUE #1 FIX: Download button initialized as invisible
|
| 507 |
with gr.Row():
|
| 508 |
+
download_btn = gr.DownloadButton(
|
| 509 |
+
label="DOWNLOAD CODE (.py)",
|
| 510 |
+
variant="primary",
|
| 511 |
+
visible=False
|
| 512 |
+
)
|
| 513 |
|
| 514 |
# EVENT HANDLERS
|
| 515 |
|
|
|
|
| 545 |
).then(
|
| 546 |
fn=end_execution_sequence,
|
| 547 |
inputs=[system_terminal, coder_log, strategist_log, master_log_output, final_code_state],
|
| 548 |
+
outputs=[system_terminal, coder_log, strategist_log, master_log_output, final_code_state, working_video, celebrate_video, download_btn]
|
| 549 |
)
|
| 550 |
|
| 551 |
+
# ISSUE #2 FIX: Download button handler with proper file return
|
| 552 |
download_btn.click(
|
| 553 |
fn=download_code,
|
| 554 |
inputs=[final_code_state],
|
|
|
|
| 562 |
outputs=[default_image, working_video, celebrate_video]
|
| 563 |
)
|
| 564 |
|
| 565 |
+
# RESET MISSION button with download button visibility control
|
| 566 |
reset_btn.click(
|
| 567 |
fn=reset_mission,
|
| 568 |
inputs=[],
|
|
|
|
| 578 |
strategist_provider,
|
| 579 |
strategist_model,
|
| 580 |
audit_checkbox,
|
| 581 |
+
final_code_state,
|
| 582 |
+
download_btn
|
| 583 |
]
|
| 584 |
)
|
| 585 |
|