akhaliq HF Staff commited on
Commit
2a752a7
·
1 Parent(s): bbf3c2a
Files changed (1) hide show
  1. app.py +51 -85
app.py CHANGED
@@ -8577,11 +8577,13 @@ with gr.Blocks(
8577
  gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update() # 5-file group
8578
  ]
8579
 
8580
- files = parse_multipage_html_output(code_text or "")
8581
- files = validate_and_autofix_files(files)
8582
-
8583
- if not isinstance(files, dict) or len(files) <= 1:
8584
- # No multi-file content; keep single editor
 
 
8585
  return [
8586
  gr.update(visible=True), # code_output
8587
  gr.update(visible=False), # static_group_2
@@ -8594,6 +8596,9 @@ with gr.Blocks(
8594
  gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), # 4-file group
8595
  gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update() # 5-file group
8596
  ]
 
 
 
8597
 
8598
  # We have multi-file static output: hide single editor, show appropriate static group
8599
  # Order: index.html first, then others sorted by path
@@ -8622,87 +8627,26 @@ with gr.Blocks(
8622
 
8623
  num_files = len(ordered_paths)
8624
 
8625
- # Hide single editor, show appropriate group based on file count
8626
- updates = [gr.update(visible=False)] # code_output
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8627
 
8628
- if num_files == 2:
8629
- updates.extend([
8630
- gr.update(visible=True), # static_group_2
8631
- gr.update(visible=False), # static_group_3
8632
- gr.update(visible=False), # static_group_4
8633
- gr.update(visible=False), # static_group_5plus
8634
- ])
8635
- # Populate 2-file group (tab labels + code content)
8636
- path1, path2 = ordered_paths[0], ordered_paths[1]
8637
- updates.extend([
8638
- gr.update(label=path1), gr.update(value=files.get(path1, ''), label=path1, language=_lang_for(path1)),
8639
- gr.update(label=path2), gr.update(value=files.get(path2, ''), label=path2, language=_lang_for(path2)),
8640
- # Empty updates for unused groups
8641
- gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(),
8642
- gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(),
8643
- gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update()
8644
- ])
8645
- elif num_files == 3:
8646
- updates.extend([
8647
- gr.update(visible=False), # static_group_2
8648
- gr.update(visible=True), # static_group_3
8649
- gr.update(visible=False), # static_group_4
8650
- gr.update(visible=False), # static_group_5plus
8651
- ])
8652
- # Populate 3-file group (tab labels + code content)
8653
- path1, path2, path3 = ordered_paths[0], ordered_paths[1], ordered_paths[2]
8654
- updates.extend([
8655
- # Empty updates for 2-file group
8656
- gr.update(), gr.update(), gr.update(), gr.update(),
8657
- # Populate 3-file group
8658
- gr.update(label=path1), gr.update(value=files.get(path1, ''), label=path1, language=_lang_for(path1)),
8659
- gr.update(label=path2), gr.update(value=files.get(path2, ''), label=path2, language=_lang_for(path2)),
8660
- gr.update(label=path3), gr.update(value=files.get(path3, ''), label=path3, language=_lang_for(path3)),
8661
- # Empty updates for unused groups
8662
- gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(),
8663
- gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update()
8664
- ])
8665
- elif num_files == 4:
8666
- updates.extend([
8667
- gr.update(visible=False), # static_group_2
8668
- gr.update(visible=False), # static_group_3
8669
- gr.update(visible=True), # static_group_4
8670
- gr.update(visible=False), # static_group_5plus
8671
- ])
8672
- # Populate 4-file group (tab labels + code content)
8673
- paths = ordered_paths[:4]
8674
- updates.extend([
8675
- # Empty updates for 2-file and 3-file groups
8676
- gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(),
8677
- # Populate 4-file group
8678
- gr.update(label=paths[0]), gr.update(value=files.get(paths[0], ''), label=paths[0], language=_lang_for(paths[0])),
8679
- gr.update(label=paths[1]), gr.update(value=files.get(paths[1], ''), label=paths[1], language=_lang_for(paths[1])),
8680
- gr.update(label=paths[2]), gr.update(value=files.get(paths[2], ''), label=paths[2], language=_lang_for(paths[2])),
8681
- gr.update(label=paths[3]), gr.update(value=files.get(paths[3], ''), label=paths[3], language=_lang_for(paths[3])),
8682
- # Empty updates for 5+ group
8683
- gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update()
8684
- ])
8685
- else: # 5+ files
8686
- updates.extend([
8687
- gr.update(visible=False), # static_group_2
8688
- gr.update(visible=False), # static_group_3
8689
- gr.update(visible=False), # static_group_4
8690
- gr.update(visible=True), # static_group_5plus
8691
- ])
8692
- # Populate 5+ file group (show first 5) (tab labels + code content)
8693
- paths = ordered_paths[:5]
8694
- updates.extend([
8695
- # Empty updates for 2-file, 3-file, and 4-file groups
8696
- gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(),
8697
- gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(),
8698
- # Populate 5+ file group
8699
- gr.update(label=paths[0]), gr.update(value=files.get(paths[0], ''), label=paths[0], language=_lang_for(paths[0])),
8700
- gr.update(label=paths[1]), gr.update(value=files.get(paths[1], ''), label=paths[1], language=_lang_for(paths[1])),
8701
- gr.update(label=paths[2]), gr.update(value=files.get(paths[2], ''), label=paths[2], language=_lang_for(paths[2])),
8702
- gr.update(label=paths[3]), gr.update(value=files.get(paths[3], ''), label=paths[3], language=_lang_for(paths[3])),
8703
- gr.update(label=paths[4]), gr.update(value=files.get(paths[4], ''), label=paths[4], language=_lang_for(paths[4]))
8704
- ])
8705
-
8706
  return updates
8707
 
8708
  # Respond to language change to show/hide static multi-file editors appropriately
@@ -8821,6 +8765,17 @@ with gr.Blocks(
8821
  static_tab_4_1, static_code_4_1, static_tab_4_2, static_code_4_2, static_tab_4_3, static_code_4_3, static_tab_4_4, static_code_4_4,
8822
  static_tab_5_1, static_code_5_1, static_tab_5_2, static_code_5_2, static_tab_5_3, static_code_5_3, static_tab_5_4, static_code_5_4, static_tab_5_5, static_code_5_5,
8823
  ]
 
 
 
 
 
 
 
 
 
 
 
8824
  ).then(
8825
  show_deploy_components,
8826
  None,
@@ -8858,6 +8813,17 @@ with gr.Blocks(
8858
  static_tab_4_1, static_code_4_1, static_tab_4_2, static_code_4_2, static_tab_4_3, static_code_4_3, static_tab_4_4, static_code_4_4,
8859
  static_tab_5_1, static_code_5_1, static_tab_5_2, static_code_5_2, static_tab_5_3, static_code_5_3, static_tab_5_4, static_code_5_4, static_tab_5_5, static_code_5_5,
8860
  ]
 
 
 
 
 
 
 
 
 
 
 
8861
  ).then(
8862
  show_deploy_components,
8863
  None,
 
8577
  gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update() # 5-file group
8578
  ]
8579
 
8580
+ # Parse multi-file output first
8581
+ original_files = parse_multipage_html_output(code_text or "")
8582
+
8583
+ # Check if we actually have multi-file content BEFORE validation
8584
+ # (validate_and_autofix_files can create additional files from single-file HTML)
8585
+ if not isinstance(original_files, dict) or len(original_files) <= 1:
8586
+ # No genuine multi-file content; keep single editor
8587
  return [
8588
  gr.update(visible=True), # code_output
8589
  gr.update(visible=False), # static_group_2
 
8596
  gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), # 4-file group
8597
  gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update() # 5-file group
8598
  ]
8599
+
8600
+ # We have genuine multi-file content - now validate and proceed with multi-file display
8601
+ files = validate_and_autofix_files(original_files)
8602
 
8603
  # We have multi-file static output: hide single editor, show appropriate static group
8604
  # Order: index.html first, then others sorted by path
 
8627
 
8628
  num_files = len(ordered_paths)
8629
 
8630
+ # TEMPORARY FIX: For now, always keep single editor visible for HTML multi-file
8631
+ # This ensures code is always visible while we debug the multi-file editors
8632
+ # TODO: Remove this once multi-file editors are working properly
8633
+ updates = [
8634
+ gr.update(visible=True), # code_output - keep visible
8635
+ gr.update(visible=False), # static_group_2 - hide multi-file editors for now
8636
+ gr.update(visible=False), # static_group_3
8637
+ gr.update(visible=False), # static_group_4
8638
+ gr.update(visible=False), # static_group_5plus
8639
+ ]
8640
+
8641
+ # Add empty updates for all the tab and code components
8642
+ updates.extend([
8643
+ # All tab and code components get empty updates (tab, code, tab, code, ...)
8644
+ gr.update(), gr.update(), gr.update(), gr.update(), # 2-file group
8645
+ gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), # 3-file group
8646
+ gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), # 4-file group
8647
+ gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update() # 5-file group
8648
+ ])
8649
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8650
  return updates
8651
 
8652
  # Respond to language change to show/hide static multi-file editors appropriately
 
8765
  static_tab_4_1, static_code_4_1, static_tab_4_2, static_code_4_2, static_tab_4_3, static_code_4_3, static_tab_4_4, static_code_4_4,
8766
  static_tab_5_1, static_code_5_1, static_tab_5_2, static_code_5_2, static_tab_5_3, static_code_5_3, static_tab_5_4, static_code_5_4, static_tab_5_5, static_code_5_5,
8767
  ]
8768
+ ).then(
8769
+ # After generation, toggle Python multi-file editors for Gradio/Streamlit
8770
+ toggle_python_editors,
8771
+ inputs=[language_dropdown, code_output],
8772
+ outputs=[
8773
+ code_output, python_group_2, python_group_3, python_group_4, python_group_5plus,
8774
+ python_tab_2_1, python_code_2_1, python_tab_2_2, python_code_2_2,
8775
+ python_tab_3_1, python_code_3_1, python_tab_3_2, python_code_3_2, python_tab_3_3, python_code_3_3,
8776
+ python_tab_4_1, python_code_4_1, python_tab_4_2, python_code_4_2, python_tab_4_3, python_code_4_3, python_tab_4_4, python_code_4_4,
8777
+ python_tab_5_1, python_code_5_1, python_tab_5_2, python_code_5_2, python_tab_5_3, python_code_5_3, python_tab_5_4, python_code_5_4, python_tab_5_5, python_code_5_5
8778
+ ]
8779
  ).then(
8780
  show_deploy_components,
8781
  None,
 
8813
  static_tab_4_1, static_code_4_1, static_tab_4_2, static_code_4_2, static_tab_4_3, static_code_4_3, static_tab_4_4, static_code_4_4,
8814
  static_tab_5_1, static_code_5_1, static_tab_5_2, static_code_5_2, static_tab_5_3, static_code_5_3, static_tab_5_4, static_code_5_4, static_tab_5_5, static_code_5_5,
8815
  ]
8816
+ ).then(
8817
+ # After generation, toggle Python multi-file editors for Gradio/Streamlit
8818
+ toggle_python_editors,
8819
+ inputs=[language_dropdown, code_output],
8820
+ outputs=[
8821
+ code_output, python_group_2, python_group_3, python_group_4, python_group_5plus,
8822
+ python_tab_2_1, python_code_2_1, python_tab_2_2, python_code_2_2,
8823
+ python_tab_3_1, python_code_3_1, python_tab_3_2, python_code_3_2, python_tab_3_3, python_code_3_3,
8824
+ python_tab_4_1, python_code_4_1, python_tab_4_2, python_code_4_2, python_tab_4_3, python_code_4_3, python_tab_4_4, python_code_4_4,
8825
+ python_tab_5_1, python_code_5_1, python_tab_5_2, python_code_5_2, python_tab_5_3, python_code_5_3, python_tab_5_4, python_code_5_4, python_tab_5_5, python_code_5_5
8826
+ ]
8827
  ).then(
8828
  show_deploy_components,
8829
  None,