WhoDat55 commited on
Commit
a3169f8
·
verified ·
1 Parent(s): 15192d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -28
app.py CHANGED
@@ -4,6 +4,7 @@ import json
4
  import os
5
  import time
6
  import tempfile
 
7
  from configparser import ConfigParser
8
  from typing import List, Dict, Any
9
 
@@ -216,7 +217,7 @@ def build_master_log(system_log_list, coder_log_list, strategist_log_list, audit
216
  return html_output
217
 
218
  def execute_remote_workflow(blueprint, intent, coder_model_label, strategist_model_label, enable_audit):
219
- """Execute workflow with final_code tracking"""
220
  mission_start_time = time.time()
221
  final_code = None
222
 
@@ -234,7 +235,7 @@ def execute_remote_workflow(blueprint, intent, coder_model_label, strategist_mod
234
 
235
  with requests.post(target_url, json=payload, stream=True, timeout=300) as response:
236
  if response.status_code == 404:
237
- yield f"ERROR 404: Streaming endpoint not found at {target_url}. Check server version.", "", "", "", None
238
  return
239
 
240
  response.raise_for_status()
@@ -273,7 +274,8 @@ def execute_remote_workflow(blueprint, intent, coder_model_label, strategist_mod
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:
279
  error_detail = str(e)
@@ -281,10 +283,10 @@ def execute_remote_workflow(blueprint, intent, coder_model_label, strategist_mod
281
  error_detail += f"\nServer Response: {e.response.text}"
282
 
283
  error_msg = f"CONNECTION ERROR: Could not connect to MCP Server.\nDetails: {error_detail}"
284
- yield error_msg, "", "", "", None
285
  except Exception as e:
286
  error_msg = f"CLIENT ERROR: {str(e)}"
287
- yield error_msg, "", "", "", None
288
 
289
  def create_interface():
290
  DEMO_BLUEPRINT = """# Gradio Application Blueprint
@@ -330,19 +332,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
- # 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():
@@ -361,7 +364,7 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
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() == "":
@@ -380,6 +383,35 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
380
 
381
  return filepath
382
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
383
  # RESET MISSION function
384
  def reset_mission():
385
  """Total system reset: clear all fields and reset to defaults"""
@@ -402,15 +434,17 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
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:
409
  gr.Markdown("# Project: Conductor V4.0 (Client Mode)")
410
  gr.Markdown(f"### The Command Center: Connected to MCP Server at `{MCP_SERVER_URL}`")
411
 
412
- # Hidden state for final code
413
  final_code_state = gr.State(value=None)
 
414
 
415
  # PRIMARY INTERFACE ROW - Three Columns
416
  with gr.Row():
@@ -503,13 +537,18 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
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
 
@@ -541,18 +580,24 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
541
  ).then(
542
  fn=execute_remote_workflow,
543
  inputs=[blueprint_input, intent_input, coder_model, strategist_model, audit_checkbox],
544
- outputs=[system_terminal, coder_log, strategist_log, master_log_output, final_code_state]
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],
555
- outputs=[download_btn]
 
 
 
 
 
 
556
  )
557
 
558
  # Celebrate video auto-reset
@@ -562,7 +607,7 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
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=[],
@@ -579,7 +624,8 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
579
  strategist_model,
580
  audit_checkbox,
581
  final_code_state,
582
- download_btn
 
583
  ]
584
  )
585
 
 
4
  import os
5
  import time
6
  import tempfile
7
+ import re
8
  from configparser import ConfigParser
9
  from typing import List, Dict, Any
10
 
 
217
  return html_output
218
 
219
  def execute_remote_workflow(blueprint, intent, coder_model_label, strategist_model_label, enable_audit):
220
+ """Execute workflow with final_code and master_log tracking"""
221
  mission_start_time = time.time()
222
  final_code = None
223
 
 
235
 
236
  with requests.post(target_url, json=payload, stream=True, timeout=300) as response:
237
  if response.status_code == 404:
238
+ yield f"ERROR 404: Streaming endpoint not found at {target_url}. Check server version.", "", "", "", None, None
239
  return
240
 
241
  response.raise_for_status()
 
274
  strategist_log_list, audit_log_list,
275
  mission_start_time, final_code)
276
 
277
+ # DIRECTIVE #3: Update both master_log_output AND master_log_state
278
+ yield sys_log, cod_log, strat_log, master_log, final_code, master_log
279
 
280
  except requests.exceptions.RequestException as e:
281
  error_detail = str(e)
 
283
  error_detail += f"\nServer Response: {e.response.text}"
284
 
285
  error_msg = f"CONNECTION ERROR: Could not connect to MCP Server.\nDetails: {error_detail}"
286
+ yield error_msg, "", "", "", None, None
287
  except Exception as e:
288
  error_msg = f"CLIENT ERROR: {str(e)}"
289
+ yield error_msg, "", "", "", None, None
290
 
291
  def create_interface():
292
  DEMO_BLUEPRINT = """# Gradio Application Blueprint
 
332
  def start_execution_sequence():
333
  return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
334
 
335
+ # DIRECTIVE #3: Button visibility control in end sequence
336
+ def end_execution_sequence(sys_log, cod_log, strat_log, master_log, final_code, master_log_html):
337
+ # Buttons become visible only when final_code exists
338
  button_visibility = final_code is not None and final_code.strip() != ""
339
  return (
340
  sys_log,
341
  cod_log,
342
  strat_log,
343
  master_log,
344
+ final_code,
345
+ master_log_html,
346
  gr.update(visible=False), # working_video
347
  gr.update(visible=True), # celebrate_video
348
+ gr.update(visible=button_visibility) # download_buttons_row
349
  )
350
 
351
  def reset_to_default():
 
364
  return gr.update(choices=[], value=None)
365
  return gr.update(choices=models, value=models[0])
366
 
367
+ # DIRECTIVE #1: NO LOGIC CHANGE - Existing download_code function preserved
368
  def download_code(final_code_content):
369
  """Generate downloadable Python file from final code"""
370
  if not final_code_content or final_code_content.strip() == "":
 
383
 
384
  return filepath
385
 
386
+ # DIRECTIVE #2: NEW FUNCTION - Download master log
387
+ def download_master_log(master_log_html):
388
+ """Generate downloadable text file from master log HTML"""
389
+ if not master_log_html or master_log_html.strip() == "":
390
+ return None
391
+
392
+ # Strip all HTML tags using regex
393
+ clean_text = re.sub(r'<[^>]+>', '', master_log_html)
394
+
395
+ # Decode HTML entities
396
+ clean_text = clean_text.replace('&lt;', '<').replace('&gt;', '>').replace('&amp;', '&')
397
+
398
+ # Clean up extra whitespace
399
+ clean_text = re.sub(r'\n\s*\n', '\n\n', clean_text)
400
+ clean_text = clean_text.strip()
401
+
402
+ # Create temporary file with timestamp
403
+ timestamp = time.strftime("%Y%m%d_%H%M%S")
404
+ filename = f"master_log_{timestamp}.txt"
405
+
406
+ # Write to temporary file and return filepath
407
+ temp_dir = tempfile.gettempdir()
408
+ filepath = os.path.join(temp_dir, filename)
409
+
410
+ with open(filepath, 'w', encoding='utf-8') as f:
411
+ f.write(clean_text)
412
+
413
+ return filepath
414
+
415
  # RESET MISSION function
416
  def reset_mission():
417
  """Total system reset: clear all fields and reset to defaults"""
 
434
  gr.update(choices=strategist_models_for_reset, value=strategist_reset_value), # strategist_model
435
  gr.update(value=False), # audit_checkbox
436
  None, # final_code_state
437
+ None, # master_log_state
438
+ gr.update(visible=False) # DIRECTIVE #3: Hide download buttons row on reset
439
  )
440
 
441
  with gr.Blocks(title="Project: Conductor V4.0 Client") as interface:
442
  gr.Markdown("# Project: Conductor V4.0 (Client Mode)")
443
  gr.Markdown(f"### The Command Center: Connected to MCP Server at `{MCP_SERVER_URL}`")
444
 
445
+ # DIRECTIVE #3: Hidden states for final code and master log
446
  final_code_state = gr.State(value=None)
447
+ master_log_state = gr.State(value=None)
448
 
449
  # PRIMARY INTERFACE ROW - Three Columns
450
  with gr.Row():
 
537
  label="MASTER LOG WINDOW"
538
  )
539
 
540
+ # DIRECTIVE #3: Two-button layout with clean, constrained width
541
+ with gr.Row(visible=False) as download_buttons_row:
542
+ with gr.Column():
543
+ download_code_btn = gr.DownloadButton(
544
+ label="DOWNLOAD GENERATED CODE",
545
+ variant="primary"
546
+ )
547
+ with gr.Column():
548
+ download_log_btn = gr.DownloadButton(
549
+ label="DOWNLOAD MASTER LOG",
550
+ variant="secondary"
551
+ )
552
 
553
  # EVENT HANDLERS
554
 
 
580
  ).then(
581
  fn=execute_remote_workflow,
582
  inputs=[blueprint_input, intent_input, coder_model, strategist_model, audit_checkbox],
583
+ outputs=[system_terminal, coder_log, strategist_log, master_log_output, final_code_state, master_log_state]
584
  ).then(
585
  fn=end_execution_sequence,
586
+ inputs=[system_terminal, coder_log, strategist_log, master_log_output, final_code_state, master_log_state],
587
+ outputs=[system_terminal, coder_log, strategist_log, master_log_output, final_code_state, master_log_state, working_video, celebrate_video, download_buttons_row]
588
  )
589
 
590
+ # DIRECTIVE #1 & #2: Download button handlers
591
+ download_code_btn.click(
592
  fn=download_code,
593
  inputs=[final_code_state],
594
+ outputs=[download_code_btn]
595
+ )
596
+
597
+ download_log_btn.click(
598
+ fn=download_master_log,
599
+ inputs=[master_log_state],
600
+ outputs=[download_log_btn]
601
  )
602
 
603
  # Celebrate video auto-reset
 
607
  outputs=[default_image, working_video, celebrate_video]
608
  )
609
 
610
+ # RESET MISSION button with download buttons row visibility control
611
  reset_btn.click(
612
  fn=reset_mission,
613
  inputs=[],
 
624
  strategist_model,
625
  audit_checkbox,
626
  final_code_state,
627
+ master_log_state,
628
+ download_buttons_row
629
  ]
630
  )
631