Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -85,7 +85,7 @@ def format_conversation_log(history: List[Dict[str, Any]]) -> str:
|
|
| 85 |
log_lines.append("")
|
| 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):
|
| 89 |
actor_styles = {
|
| 90 |
'SYSTEM': {'icon': '🔧', 'color': '#ef4444'},
|
| 91 |
'CODER': {'icon': '💻', 'color': '#3b82f6'},
|
|
@@ -168,6 +168,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 |
if not master_entries:
|
| 172 |
return '<div style="font-family: monospace; color: #6b7280;">No log data captured.</div>'
|
| 173 |
|
|
@@ -179,7 +189,7 @@ def build_master_log(system_log_list, coder_log_list, strategist_log_list, audit
|
|
| 179 |
|
| 180 |
return html_output
|
| 181 |
|
| 182 |
-
def execute_remote_workflow(blueprint, intent, coder_model_label, strategist_model_label):
|
| 183 |
"""Streaming workflow execution with real-time log updates"""
|
| 184 |
mission_start_time = time.time()
|
| 185 |
|
|
@@ -187,7 +197,8 @@ def execute_remote_workflow(blueprint, intent, coder_model_label, strategist_mod
|
|
| 187 |
"blueprint": blueprint,
|
| 188 |
"intent": intent,
|
| 189 |
"coder_model_label": coder_model_label,
|
| 190 |
-
"strategist_model_label": strategist_model_label
|
|
|
|
| 191 |
}
|
| 192 |
|
| 193 |
try:
|
|
@@ -201,6 +212,8 @@ def execute_remote_workflow(blueprint, intent, coder_model_label, strategist_mod
|
|
| 201 |
|
| 202 |
response.raise_for_status()
|
| 203 |
|
|
|
|
|
|
|
| 204 |
for line in response.iter_lines():
|
| 205 |
if not line:
|
| 206 |
continue
|
|
@@ -224,12 +237,16 @@ def execute_remote_workflow(blueprint, intent, coder_model_label, strategist_mod
|
|
| 224 |
strategist_log_list = data.get("strategist_log", [])
|
| 225 |
audit_log_list = data.get("audit_log", [])
|
| 226 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
sys_log = "\n".join(system_log_list)
|
| 228 |
cod_log = format_conversation_log(coder_log_list)
|
| 229 |
strat_log = format_conversation_log(strategist_log_list)
|
| 230 |
master_log = build_master_log(system_log_list, coder_log_list,
|
| 231 |
strategist_log_list, audit_log_list,
|
| 232 |
-
mission_start_time)
|
| 233 |
|
| 234 |
yield sys_log, cod_log, strat_log, master_log
|
| 235 |
|
|
@@ -264,8 +281,36 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 264 |
if strategist_default:
|
| 265 |
initial_strategist_provider = classify_model_by_provider(strategist_default)
|
| 266 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
def load_demo_data():
|
| 268 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
|
| 270 |
def start_execution_sequence():
|
| 271 |
return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
|
|
@@ -296,8 +341,8 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 296 |
coder_models_for_reset = CLIENT_CONFIG['coder_by_provider'].get(initial_coder_provider, [])
|
| 297 |
strategist_models_for_reset = CLIENT_CONFIG['strategist_by_provider'].get(initial_strategist_provider, [])
|
| 298 |
|
| 299 |
-
coder_reset_value =
|
| 300 |
-
strategist_reset_value =
|
| 301 |
|
| 302 |
return (
|
| 303 |
"", # blueprint_input
|
|
@@ -309,7 +354,8 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 309 |
gr.update(value=initial_coder_provider), # coder_provider
|
| 310 |
gr.update(choices=coder_models_for_reset, value=coder_reset_value), # coder_model
|
| 311 |
gr.update(value=initial_strategist_provider), # strategist_provider
|
| 312 |
-
gr.update(choices=strategist_models_for_reset, value=strategist_reset_value) # strategist_model
|
|
|
|
| 313 |
)
|
| 314 |
|
| 315 |
with gr.Blocks(title="Project: Conductor V4.0 Client") as interface:
|
|
@@ -329,7 +375,7 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 329 |
)
|
| 330 |
coder_model = gr.Dropdown(
|
| 331 |
choices=CLIENT_CONFIG['coder_by_provider'].get(initial_coder_provider, []),
|
| 332 |
-
value=
|
| 333 |
label="Model",
|
| 334 |
interactive=True
|
| 335 |
)
|
|
@@ -378,7 +424,7 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 378 |
)
|
| 379 |
strategist_model = gr.Dropdown(
|
| 380 |
choices=CLIENT_CONFIG['strategist_by_provider'].get(initial_strategist_provider, []),
|
| 381 |
-
value=
|
| 382 |
label="Model",
|
| 383 |
interactive=True
|
| 384 |
)
|
|
@@ -394,6 +440,10 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 394 |
execute_btn = gr.Button("EXECUTE VIA MCP", variant="primary")
|
| 395 |
reset_btn = gr.Button("RESET MISSION", variant="secondary")
|
| 396 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
# LOG ROWS
|
| 398 |
with gr.Row():
|
| 399 |
system_terminal = gr.Textbox(label="SYSTEM LOG", interactive=False, lines=15, max_lines=15)
|
|
@@ -425,7 +475,7 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 425 |
demo_btn.click(
|
| 426 |
fn=load_demo_data,
|
| 427 |
inputs=None,
|
| 428 |
-
outputs=[blueprint_input, intent_input]
|
| 429 |
)
|
| 430 |
|
| 431 |
# Execute button
|
|
@@ -435,7 +485,7 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 435 |
outputs=[default_image, working_video, celebrate_video]
|
| 436 |
).then(
|
| 437 |
fn=execute_remote_workflow,
|
| 438 |
-
inputs=[blueprint_input, intent_input, coder_model, strategist_model],
|
| 439 |
outputs=[system_terminal, coder_log, strategist_log, master_log_output]
|
| 440 |
).then(
|
| 441 |
fn=end_execution_sequence,
|
|
@@ -464,12 +514,13 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
|
|
| 464 |
coder_provider,
|
| 465 |
coder_model,
|
| 466 |
strategist_provider,
|
| 467 |
-
strategist_model
|
|
|
|
| 468 |
]
|
| 469 |
)
|
| 470 |
|
| 471 |
gr.Markdown("---")
|
| 472 |
-
gr.Markdown("**Note:** This client requires the Conductor MCP Server V4.
|
| 473 |
|
| 474 |
return interface
|
| 475 |
|
|
|
|
| 85 |
log_lines.append("")
|
| 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 |
master_entries.append(html_entry)
|
| 169 |
seq_counter += 1
|
| 170 |
|
| 171 |
+
# Append Final Code Block if available
|
| 172 |
+
if final_code_block:
|
| 173 |
+
html_entry = f'''
|
| 174 |
+
<div style="margin-top: 20px; border-top: 2px solid #10b981; padding-top: 10px;">
|
| 175 |
+
<h3 style="color: #10b981; font-family: monospace;">🚀 GENERATED CODE:</h3>
|
| 176 |
+
<pre style="background-color: #000; padding: 10px; border-radius: 5px; overflow-x: auto; color: #a5f3fc;"><code>{final_code_block}</code></pre>
|
| 177 |
+
</div>
|
| 178 |
+
'''
|
| 179 |
+
master_entries.append(html_entry)
|
| 180 |
+
|
| 181 |
if not master_entries:
|
| 182 |
return '<div style="font-family: monospace; color: #6b7280;">No log data captured.</div>'
|
| 183 |
|
|
|
|
| 189 |
|
| 190 |
return html_output
|
| 191 |
|
| 192 |
+
def execute_remote_workflow(blueprint, intent, coder_model_label, strategist_model_label, enable_audit):
|
| 193 |
"""Streaming workflow execution with real-time log updates"""
|
| 194 |
mission_start_time = time.time()
|
| 195 |
|
|
|
|
| 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 |
|
| 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
|
|
|
|
| 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, final_code_content)
|
| 250 |
|
| 251 |
yield sys_log, cod_log, strat_log, master_log
|
| 252 |
|
|
|
|
| 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 |
+
# TASK 2: "Load Demo" Button Model Switch
|
| 300 |
+
# Switch to a high-end model for the demo
|
| 301 |
+
demo_model_label = "gemini-2.5-pro" # Assumes this key exists or will be handled
|
| 302 |
+
# Fallback if exact label not found, try to find a 'pro' model
|
| 303 |
+
models = CLIENT_CONFIG['coder_by_provider'].get("Google Gemini", [])
|
| 304 |
+
target_model = demo_model_label
|
| 305 |
+
if demo_model_label not in models:
|
| 306 |
+
# Try to find a pro model
|
| 307 |
+
pro_models = [m for m in models if 'pro' in m.lower()]
|
| 308 |
+
if pro_models:
|
| 309 |
+
target_model = pro_models[0]
|
| 310 |
+
elif models:
|
| 311 |
+
target_model = models[0]
|
| 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)
|
|
|
|
| 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 = initial_coder_model_val
|
| 345 |
+
strategist_reset_value = initial_strategist_model_val
|
| 346 |
|
| 347 |
return (
|
| 348 |
"", # blueprint_input
|
|
|
|
| 354 |
gr.update(value=initial_coder_provider), # coder_provider
|
| 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 # audit_checkbox
|
| 359 |
)
|
| 360 |
|
| 361 |
with gr.Blocks(title="Project: Conductor V4.0 Client") as interface:
|
|
|
|
| 375 |
)
|
| 376 |
coder_model = gr.Dropdown(
|
| 377 |
choices=CLIENT_CONFIG['coder_by_provider'].get(initial_coder_provider, []),
|
| 378 |
+
value=initial_coder_model_val,
|
| 379 |
label="Model",
|
| 380 |
interactive=True
|
| 381 |
)
|
|
|
|
| 424 |
)
|
| 425 |
strategist_model = gr.Dropdown(
|
| 426 |
choices=CLIENT_CONFIG['strategist_by_provider'].get(initial_strategist_provider, []),
|
| 427 |
+
value=initial_strategist_model_val,
|
| 428 |
label="Model",
|
| 429 |
interactive=True
|
| 430 |
)
|
|
|
|
| 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)
|
|
|
|
| 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
|
|
|
|
| 485 |
outputs=[default_image, working_video, celebrate_video]
|
| 486 |
).then(
|
| 487 |
fn=execute_remote_workflow,
|
| 488 |
+
inputs=[blueprint_input, intent_input, coder_model, strategist_model, audit_checkbox],
|
| 489 |
outputs=[system_terminal, coder_log, strategist_log, master_log_output]
|
| 490 |
).then(
|
| 491 |
fn=end_execution_sequence,
|
|
|
|
| 514 |
coder_provider,
|
| 515 |
coder_model,
|
| 516 |
strategist_provider,
|
| 517 |
+
strategist_model,
|
| 518 |
+
audit_checkbox
|
| 519 |
]
|
| 520 |
)
|
| 521 |
|
| 522 |
gr.Markdown("---")
|
| 523 |
+
gr.Markdown("**Note:** This client requires the Conductor MCP Server V4.1 with streaming and audit support. Logs now update in real-time with color-coded visual differentiation.")
|
| 524 |
|
| 525 |
return interface
|
| 526 |
|