Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,7 @@ from typing import List, Dict, Any
|
|
| 8 |
|
| 9 |
MCP_SERVER_URL = "https://mcp-1st-birthday-project-conductor-core-mcp.hf.space/execute"
|
| 10 |
|
| 11 |
-
# HARDCODED PROVIDER MAPPING
|
| 12 |
PROVIDER_MODEL_MAPPING = {
|
| 13 |
"Google Gemini": [],
|
| 14 |
"Anthropic": [],
|
|
@@ -86,6 +86,7 @@ def format_conversation_log(history: List[Dict[str, Any]]) -> str:
|
|
| 86 |
return "\n".join(log_lines)
|
| 87 |
|
| 88 |
def build_master_log(system_log_list, coder_log_list, strategist_log_list, audit_log_list, start_time, final_code_block=None):
|
|
|
|
| 89 |
actor_styles = {
|
| 90 |
'SYSTEM': {'icon': '🔧', 'color': '#ef4444'},
|
| 91 |
'CODER': {'icon': '💻', 'color': '#3b82f6'},
|
|
@@ -168,16 +169,16 @@ def build_master_log(system_log_list, coder_log_list, strategist_log_list, audit
|
|
| 168 |
master_entries.append(html_entry)
|
| 169 |
seq_counter += 1
|
| 170 |
|
| 171 |
-
# Append
|
| 172 |
if final_code_block:
|
| 173 |
-
|
| 174 |
-
<div style="margin-top: 20px;
|
| 175 |
-
<h3 style="color: #10b981;
|
| 176 |
-
<pre style="background-color: #
|
| 177 |
</div>
|
| 178 |
'''
|
| 179 |
-
master_entries.append(
|
| 180 |
-
|
| 181 |
if not master_entries:
|
| 182 |
return '<div style="font-family: monospace; color: #6b7280;">No log data captured.</div>'
|
| 183 |
|
|
@@ -190,15 +191,16 @@ def build_master_log(system_log_list, coder_log_list, strategist_log_list, audit
|
|
| 190 |
return html_output
|
| 191 |
|
| 192 |
def execute_remote_workflow(blueprint, intent, coder_model_label, strategist_model_label, enable_audit):
|
| 193 |
-
"""
|
| 194 |
mission_start_time = time.time()
|
|
|
|
| 195 |
|
| 196 |
payload = {
|
| 197 |
"blueprint": blueprint,
|
| 198 |
"intent": intent,
|
| 199 |
"coder_model_label": coder_model_label,
|
| 200 |
"strategist_model_label": strategist_model_label,
|
| 201 |
-
"enable_audit": enable_audit
|
| 202 |
}
|
| 203 |
|
| 204 |
try:
|
|
@@ -212,8 +214,6 @@ def execute_remote_workflow(blueprint, intent, coder_model_label, strategist_mod
|
|
| 212 |
|
| 213 |
response.raise_for_status()
|
| 214 |
|
| 215 |
-
final_code_content = None
|
| 216 |
-
|
| 217 |
for line in response.iter_lines():
|
| 218 |
if not line:
|
| 219 |
continue
|
|
@@ -232,21 +232,21 @@ def execute_remote_workflow(blueprint, intent, coder_model_label, strategist_mod
|
|
| 232 |
if data.get("status") == "complete":
|
| 233 |
break
|
| 234 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
system_log_list = data.get("system_log", [])
|
| 236 |
coder_log_list = data.get("coder_log", [])
|
| 237 |
strategist_log_list = data.get("strategist_log", [])
|
| 238 |
audit_log_list = data.get("audit_log", [])
|
| 239 |
|
| 240 |
-
# Capture final output if present
|
| 241 |
-
if data.get("final_output"):
|
| 242 |
-
final_code_content = data.get("final_output")
|
| 243 |
-
|
| 244 |
sys_log = "\n".join(system_log_list)
|
| 245 |
cod_log = format_conversation_log(coder_log_list)
|
| 246 |
strat_log = format_conversation_log(strategist_log_list)
|
| 247 |
master_log = build_master_log(system_log_list, coder_log_list,
|
| 248 |
strategist_log_list, audit_log_list,
|
| 249 |
-
mission_start_time,
|
| 250 |
|
| 251 |
yield sys_log, cod_log, strat_log, master_log
|
| 252 |
|
|
@@ -267,7 +267,7 @@ def create_interface():
|
|
| 267 |
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."""
|
| 268 |
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."""
|
| 269 |
|
| 270 |
-
#
|
| 271 |
coder_default = CLIENT_CONFIG['coder_default']
|
| 272 |
strategist_default = CLIENT_CONFIG['strategist_default']
|
| 273 |
|
|
@@ -281,36 +281,20 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 281 |
if strategist_default:
|
| 282 |
initial_strategist_provider = classify_model_by_provider(strategist_default)
|
| 283 |
|
| 284 |
-
# TASK 1: Set Default Models on Launch
|
| 285 |
-
# We override the config default if specific models are requested
|
| 286 |
-
default_model_label = "gemini-2.0-flash-lite" # Assumes this key exists in config
|
| 287 |
-
|
| 288 |
-
# Helper to safely get a default value
|
| 289 |
-
def get_safe_default(provider, preferred_label):
|
| 290 |
-
models = CLIENT_CONFIG['coder_by_provider'].get(provider, [])
|
| 291 |
-
if preferred_label in models:
|
| 292 |
-
return preferred_label
|
| 293 |
-
return models[0] if models else None
|
| 294 |
-
|
| 295 |
-
initial_coder_model_val = get_safe_default(initial_coder_provider, default_model_label)
|
| 296 |
-
initial_strategist_model_val = get_safe_default(initial_strategist_provider, default_model_label)
|
| 297 |
-
|
| 298 |
def load_demo_data():
|
| 299 |
-
|
| 300 |
-
#
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
return DEMO_BLUEPRINT, DEMO_INTENT, gr.update(value=target_model)
|
| 314 |
|
| 315 |
def start_execution_sequence():
|
| 316 |
return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
|
|
@@ -334,15 +318,14 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 334 |
return gr.update(choices=[], value=None)
|
| 335 |
return gr.update(choices=models, value=models[0])
|
| 336 |
|
| 337 |
-
# RESET MISSION function
|
| 338 |
def reset_mission():
|
| 339 |
"""Total system reset: clear all fields and reset to defaults"""
|
| 340 |
-
# Determine initial models for reset
|
| 341 |
coder_models_for_reset = CLIENT_CONFIG['coder_by_provider'].get(initial_coder_provider, [])
|
| 342 |
strategist_models_for_reset = CLIENT_CONFIG['strategist_by_provider'].get(initial_strategist_provider, [])
|
| 343 |
|
| 344 |
-
coder_reset_value =
|
| 345 |
-
strategist_reset_value =
|
| 346 |
|
| 347 |
return (
|
| 348 |
"", # blueprint_input
|
|
@@ -355,14 +338,14 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 355 |
gr.update(choices=coder_models_for_reset, value=coder_reset_value), # coder_model
|
| 356 |
gr.update(value=initial_strategist_provider), # strategist_provider
|
| 357 |
gr.update(choices=strategist_models_for_reset, value=strategist_reset_value), # strategist_model
|
| 358 |
-
False
|
| 359 |
)
|
| 360 |
|
| 361 |
with gr.Blocks(title="Project: Conductor V4.0 Client") as interface:
|
| 362 |
gr.Markdown("# Project: Conductor V4.0 (Client Mode)")
|
| 363 |
gr.Markdown(f"### The Command Center: Connected to MCP Server at `{MCP_SERVER_URL}`")
|
| 364 |
|
| 365 |
-
# PRIMARY INTERFACE ROW - Three Columns
|
| 366 |
with gr.Row():
|
| 367 |
# COLUMN 1 - CODER (Left Flank)
|
| 368 |
with gr.Column():
|
|
@@ -375,7 +358,7 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 375 |
)
|
| 376 |
coder_model = gr.Dropdown(
|
| 377 |
choices=CLIENT_CONFIG['coder_by_provider'].get(initial_coder_provider, []),
|
| 378 |
-
value=
|
| 379 |
label="Model",
|
| 380 |
interactive=True
|
| 381 |
)
|
|
@@ -424,7 +407,7 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 424 |
)
|
| 425 |
strategist_model = gr.Dropdown(
|
| 426 |
choices=CLIENT_CONFIG['strategist_by_provider'].get(initial_strategist_provider, []),
|
| 427 |
-
value=
|
| 428 |
label="Model",
|
| 429 |
interactive=True
|
| 430 |
)
|
|
@@ -439,11 +422,8 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 439 |
demo_btn = gr.Button("LOAD DEMO MODE", variant="secondary")
|
| 440 |
execute_btn = gr.Button("EXECUTE VIA MCP", variant="primary")
|
| 441 |
reset_btn = gr.Button("RESET MISSION", variant="secondary")
|
|
|
|
| 442 |
|
| 443 |
-
# TASK 4: Audit Checkbox
|
| 444 |
-
with gr.Row():
|
| 445 |
-
audit_checkbox = gr.Checkbox(label="ENABLE AUDIT LOOP (Strategist Review)", value=False)
|
| 446 |
-
|
| 447 |
# LOG ROWS
|
| 448 |
with gr.Row():
|
| 449 |
system_terminal = gr.Textbox(label="SYSTEM LOG", interactive=False, lines=15, max_lines=15)
|
|
@@ -471,14 +451,14 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 471 |
outputs=[strategist_model]
|
| 472 |
)
|
| 473 |
|
| 474 |
-
# Demo button
|
| 475 |
demo_btn.click(
|
| 476 |
fn=load_demo_data,
|
| 477 |
inputs=None,
|
| 478 |
outputs=[blueprint_input, intent_input, coder_model]
|
| 479 |
)
|
| 480 |
|
| 481 |
-
# Execute button
|
| 482 |
execute_btn.click(
|
| 483 |
fn=start_execution_sequence,
|
| 484 |
inputs=None,
|
|
@@ -500,7 +480,7 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 500 |
outputs=[default_image, working_video, celebrate_video]
|
| 501 |
)
|
| 502 |
|
| 503 |
-
# RESET MISSION button
|
| 504 |
reset_btn.click(
|
| 505 |
fn=reset_mission,
|
| 506 |
inputs=[],
|
|
@@ -520,11 +500,11 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 520 |
)
|
| 521 |
|
| 522 |
gr.Markdown("---")
|
| 523 |
-
gr.Markdown("**Note:** This client requires the Conductor MCP Server V4.
|
| 524 |
|
| 525 |
return interface
|
| 526 |
|
| 527 |
if __name__ == "__main__":
|
| 528 |
app = create_interface()
|
| 529 |
app.queue()
|
| 530 |
-
app.launch()
|
|
|
|
| 8 |
|
| 9 |
MCP_SERVER_URL = "https://mcp-1st-birthday-project-conductor-core-mcp.hf.space/execute"
|
| 10 |
|
| 11 |
+
# HARDCODED PROVIDER MAPPING
|
| 12 |
PROVIDER_MODEL_MAPPING = {
|
| 13 |
"Google Gemini": [],
|
| 14 |
"Anthropic": [],
|
|
|
|
| 86 |
return "\n".join(log_lines)
|
| 87 |
|
| 88 |
def build_master_log(system_log_list, coder_log_list, strategist_log_list, audit_log_list, start_time, final_code_block=None):
|
| 89 |
+
"""TASK 3: Added final_code_block parameter"""
|
| 90 |
actor_styles = {
|
| 91 |
'SYSTEM': {'icon': '🔧', 'color': '#ef4444'},
|
| 92 |
'CODER': {'icon': '💻', 'color': '#3b82f6'},
|
|
|
|
| 169 |
master_entries.append(html_entry)
|
| 170 |
seq_counter += 1
|
| 171 |
|
| 172 |
+
# TASK 3: Append final code block if provided
|
| 173 |
if final_code_block:
|
| 174 |
+
code_html = f'''
|
| 175 |
+
<div style="margin-top: 20px; padding: 16px; background-color: #0d1117; border: 2px solid #10b981; border-radius: 8px;">
|
| 176 |
+
<h3 style="color: #10b981; margin-top: 0;">🎯 GENERATED CODE:</h3>
|
| 177 |
+
<pre style="background-color: #1e1e1e; padding: 12px; border-radius: 4px; overflow-x: auto; color: #e0e0e0;"><code>{final_code_block}</code></pre>
|
| 178 |
</div>
|
| 179 |
'''
|
| 180 |
+
master_entries.append(code_html)
|
| 181 |
+
|
| 182 |
if not master_entries:
|
| 183 |
return '<div style="font-family: monospace; color: #6b7280;">No log data captured.</div>'
|
| 184 |
|
|
|
|
| 191 |
return html_output
|
| 192 |
|
| 193 |
def execute_remote_workflow(blueprint, intent, coder_model_label, strategist_model_label, enable_audit):
|
| 194 |
+
"""TASK 3 & 4: Added enable_audit parameter and final_code tracking"""
|
| 195 |
mission_start_time = time.time()
|
| 196 |
+
final_code = None
|
| 197 |
|
| 198 |
payload = {
|
| 199 |
"blueprint": blueprint,
|
| 200 |
"intent": intent,
|
| 201 |
"coder_model_label": coder_model_label,
|
| 202 |
"strategist_model_label": strategist_model_label,
|
| 203 |
+
"enable_audit": enable_audit # TASK 4: Add audit flag to payload
|
| 204 |
}
|
| 205 |
|
| 206 |
try:
|
|
|
|
| 214 |
|
| 215 |
response.raise_for_status()
|
| 216 |
|
|
|
|
|
|
|
| 217 |
for line in response.iter_lines():
|
| 218 |
if not line:
|
| 219 |
continue
|
|
|
|
| 232 |
if data.get("status") == "complete":
|
| 233 |
break
|
| 234 |
|
| 235 |
+
# TASK 3: Watch for final_code key
|
| 236 |
+
if "final_code" in data:
|
| 237 |
+
final_code = data["final_code"]
|
| 238 |
+
|
| 239 |
system_log_list = data.get("system_log", [])
|
| 240 |
coder_log_list = data.get("coder_log", [])
|
| 241 |
strategist_log_list = data.get("strategist_log", [])
|
| 242 |
audit_log_list = data.get("audit_log", [])
|
| 243 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
sys_log = "\n".join(system_log_list)
|
| 245 |
cod_log = format_conversation_log(coder_log_list)
|
| 246 |
strat_log = format_conversation_log(strategist_log_list)
|
| 247 |
master_log = build_master_log(system_log_list, coder_log_list,
|
| 248 |
strategist_log_list, audit_log_list,
|
| 249 |
+
mission_start_time, final_code) # TASK 3: Pass final_code
|
| 250 |
|
| 251 |
yield sys_log, cod_log, strat_log, master_log
|
| 252 |
|
|
|
|
| 267 |
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."""
|
| 268 |
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."""
|
| 269 |
|
| 270 |
+
# TASK 1: Use existing defaults from config
|
| 271 |
coder_default = CLIENT_CONFIG['coder_default']
|
| 272 |
strategist_default = CLIENT_CONFIG['strategist_default']
|
| 273 |
|
|
|
|
| 281 |
if strategist_default:
|
| 282 |
initial_strategist_provider = classify_model_by_provider(strategist_default)
|
| 283 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
def load_demo_data():
|
| 285 |
+
"""TASK 2: Switch Coder to gemini 2.5 pro when demo loaded"""
|
| 286 |
+
# Find the gemini 2.5 pro model in config
|
| 287 |
+
demo_coder_model = None
|
| 288 |
+
for model_label in CLIENT_CONFIG['coder_models']:
|
| 289 |
+
if '2.5' in model_label and 'pro' in model_label.lower():
|
| 290 |
+
demo_coder_model = model_label
|
| 291 |
+
break
|
| 292 |
+
|
| 293 |
+
if demo_coder_model:
|
| 294 |
+
return DEMO_BLUEPRINT, DEMO_INTENT, gr.update(value=demo_coder_model)
|
| 295 |
+
else:
|
| 296 |
+
# Fallback: return without model change if 2.5 pro not found
|
| 297 |
+
return DEMO_BLUEPRINT, DEMO_INTENT, gr.update()
|
|
|
|
|
|
|
| 298 |
|
| 299 |
def start_execution_sequence():
|
| 300 |
return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
|
|
|
|
| 318 |
return gr.update(choices=[], value=None)
|
| 319 |
return gr.update(choices=models, value=models[0])
|
| 320 |
|
| 321 |
+
# RESET MISSION function
|
| 322 |
def reset_mission():
|
| 323 |
"""Total system reset: clear all fields and reset to defaults"""
|
|
|
|
| 324 |
coder_models_for_reset = CLIENT_CONFIG['coder_by_provider'].get(initial_coder_provider, [])
|
| 325 |
strategist_models_for_reset = CLIENT_CONFIG['strategist_by_provider'].get(initial_strategist_provider, [])
|
| 326 |
|
| 327 |
+
coder_reset_value = coder_models_for_reset[0] if coder_models_for_reset else None
|
| 328 |
+
strategist_reset_value = strategist_models_for_reset[0] if strategist_models_for_reset else None
|
| 329 |
|
| 330 |
return (
|
| 331 |
"", # blueprint_input
|
|
|
|
| 338 |
gr.update(choices=coder_models_for_reset, value=coder_reset_value), # coder_model
|
| 339 |
gr.update(value=initial_strategist_provider), # strategist_provider
|
| 340 |
gr.update(choices=strategist_models_for_reset, value=strategist_reset_value), # strategist_model
|
| 341 |
+
gr.update(value=False) # TASK 4: Reset audit checkbox
|
| 342 |
)
|
| 343 |
|
| 344 |
with gr.Blocks(title="Project: Conductor V4.0 Client") as interface:
|
| 345 |
gr.Markdown("# Project: Conductor V4.0 (Client Mode)")
|
| 346 |
gr.Markdown(f"### The Command Center: Connected to MCP Server at `{MCP_SERVER_URL}`")
|
| 347 |
|
| 348 |
+
# PRIMARY INTERFACE ROW - Three Columns
|
| 349 |
with gr.Row():
|
| 350 |
# COLUMN 1 - CODER (Left Flank)
|
| 351 |
with gr.Column():
|
|
|
|
| 358 |
)
|
| 359 |
coder_model = gr.Dropdown(
|
| 360 |
choices=CLIENT_CONFIG['coder_by_provider'].get(initial_coder_provider, []),
|
| 361 |
+
value=coder_default if coder_default else None, # TASK 1: Use existing default
|
| 362 |
label="Model",
|
| 363 |
interactive=True
|
| 364 |
)
|
|
|
|
| 407 |
)
|
| 408 |
strategist_model = gr.Dropdown(
|
| 409 |
choices=CLIENT_CONFIG['strategist_by_provider'].get(initial_strategist_provider, []),
|
| 410 |
+
value=strategist_default if strategist_default else None, # TASK 1: Use existing default
|
| 411 |
label="Model",
|
| 412 |
interactive=True
|
| 413 |
)
|
|
|
|
| 422 |
demo_btn = gr.Button("LOAD DEMO MODE", variant="secondary")
|
| 423 |
execute_btn = gr.Button("EXECUTE VIA MCP", variant="primary")
|
| 424 |
reset_btn = gr.Button("RESET MISSION", variant="secondary")
|
| 425 |
+
audit_checkbox = gr.Checkbox(label="AUDIT", value=False) # TASK 4: Add audit checkbox
|
| 426 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 427 |
# LOG ROWS
|
| 428 |
with gr.Row():
|
| 429 |
system_terminal = gr.Textbox(label="SYSTEM LOG", interactive=False, lines=15, max_lines=15)
|
|
|
|
| 451 |
outputs=[strategist_model]
|
| 452 |
)
|
| 453 |
|
| 454 |
+
# Demo button - TASK 2: Now updates coder_model
|
| 455 |
demo_btn.click(
|
| 456 |
fn=load_demo_data,
|
| 457 |
inputs=None,
|
| 458 |
outputs=[blueprint_input, intent_input, coder_model]
|
| 459 |
)
|
| 460 |
|
| 461 |
+
# Execute button - TASK 4: Now passes audit_checkbox
|
| 462 |
execute_btn.click(
|
| 463 |
fn=start_execution_sequence,
|
| 464 |
inputs=None,
|
|
|
|
| 480 |
outputs=[default_image, working_video, celebrate_video]
|
| 481 |
)
|
| 482 |
|
| 483 |
+
# RESET MISSION button - TASK 4: Now includes audit_checkbox in outputs
|
| 484 |
reset_btn.click(
|
| 485 |
fn=reset_mission,
|
| 486 |
inputs=[],
|
|
|
|
| 500 |
)
|
| 501 |
|
| 502 |
gr.Markdown("---")
|
| 503 |
+
gr.Markdown("**Note:** This client requires the Conductor MCP Server V4.0 with streaming support. Logs now update in real-time with color-coded visual differentiation. **AUDIT mode will loop code back to Strategist for review.**")
|
| 504 |
|
| 505 |
return interface
|
| 506 |
|
| 507 |
if __name__ == "__main__":
|
| 508 |
app = create_interface()
|
| 509 |
app.queue()
|
| 510 |
+
app.launch()
|