twarner commited on
Commit
d4e8482
·
1 Parent(s): 8218730

Fix dark mode: use explicit dark theme and colors

Browse files
Files changed (1) hide show
  1. app.py +156 -73
app.py CHANGED
@@ -610,34 +610,20 @@ def gcode_to_svg(gcode: str) -> str:
610
 
611
  svg = f'''<svg xmlns="http://www.w3.org/2000/svg"
612
  viewBox="{BOUNDS["left"] - padding} {-BOUNDS["top"] - padding} {w + 2*padding} {h + 2*padding}"
613
- style="width: 100%; height: 480px; border: 1px solid var(--border, #e0e0e0); border-radius: 4px;">
614
- <style>
615
- @media (prefers-color-scheme: dark) {{
616
- .bg {{ fill: #2a2b30; }}
617
- .work {{ fill: #212226; stroke: #3a3b40; }}
618
- .stroke {{ stroke: #e8e8e8; }}
619
- .label {{ fill: #666; }}
620
- }}
621
- @media (prefers-color-scheme: light) {{
622
- .bg {{ fill: #fff; }}
623
- .work {{ fill: #fafafa; stroke: #ccc; }}
624
- .stroke {{ stroke: #1a1a1a; }}
625
- .label {{ fill: #999; }}
626
- }}
627
- </style>
628
- <rect class="bg" x="{BOUNDS["left"] - padding}" y="{-BOUNDS["top"] - padding}" width="{w + 2*padding}" height="{h + 2*padding}"/>
629
- <rect class="work" x="{BOUNDS["left"]}" y="{-BOUNDS["top"]}" width="{w}" height="{h}" stroke-width="1"/>
630
  '''
631
 
632
  for path in paths:
633
  if len(path) < 2:
634
  continue
635
  d = " ".join(f"{'M' if i == 0 else 'L'}{p[0]:.1f},{-p[1]:.1f}" for i, p in enumerate(path))
636
- svg += f'<path class="stroke" d="{d}" fill="none" stroke-width="1" stroke-linecap="round" stroke-linejoin="round"/>'
637
 
638
  total_points = sum(len(p) for p in paths)
639
  svg += f'''
640
- <text class="label" x="{BOUNDS["left"] + 8}" y="{-BOUNDS["top"] + 20}" font-family="monospace" font-size="12">
641
  {len(paths)} paths / {total_points} points
642
  </text>
643
  '''
@@ -833,35 +819,16 @@ def generate(prompt: str, temperature: float, max_tokens: int, num_steps: int, g
833
  css = """
834
  @import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&display=swap');
835
 
836
- :root {
837
- --bg: #ffffff;
838
- --bg-secondary: #fafafa;
839
- --text: #1a1a1a;
840
- --text-secondary: #666;
841
- --border: #e0e0e0;
842
- --btn-bg: #f0f0f0;
843
- --btn-hover: #e0e0e0;
844
- }
845
-
846
- @media (prefers-color-scheme: dark) {
847
- :root {
848
- --bg: #212226;
849
- --bg-secondary: #2a2b30;
850
- --text: #e8e8e8;
851
- --text-secondary: #999;
852
- --border: #3a3b40;
853
- --btn-bg: #3a3b40;
854
- --btn-hover: #4a4b50;
855
- }
856
- }
857
-
858
  * {
859
  font-family: 'IBM Plex Mono', monospace !important;
860
  }
861
 
862
- body, .gradio-container {
863
- background: var(--bg) !important;
864
- color: var(--text) !important;
 
 
865
  }
866
 
867
  .gradio-container {
@@ -869,57 +836,173 @@ body, .gradio-container {
869
  margin: auto;
870
  }
871
 
872
- .gr-button {
873
- background: var(--btn-bg) !important;
874
- border: 1px solid var(--border) !important;
875
- color: var(--text) !important;
876
- font-weight: 500 !important;
877
  }
878
 
879
- .gr-button:hover {
880
- background: var(--btn-hover) !important;
 
881
  }
882
 
883
- .gr-examples {
884
- margin-top: 8px !important;
 
 
 
 
 
 
 
885
  }
886
 
887
- footer {
888
- display: none !important;
889
  }
890
 
891
- h1, h2, h3, p, span, label {
892
- color: var(--text) !important;
 
 
 
 
 
 
893
  }
894
 
895
- .gr-box, .gr-panel, .gr-form {
896
- background: var(--bg-secondary) !important;
897
- border: 1px solid var(--border) !important;
898
- border-radius: 4px !important;
 
 
899
  }
900
 
901
- input, textarea {
902
- background: var(--bg) !important;
903
- color: var(--text) !important;
904
- border: 1px solid var(--border) !important;
905
- border-radius: 4px !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
906
  }
907
 
908
- .gr-accordion {
909
- background: var(--bg-secondary) !important;
910
- border: 1px solid var(--border) !important;
911
  }
912
 
913
- a {
914
- color: var(--text-secondary) !important;
 
915
  }
916
 
917
  a:hover {
918
- color: var(--text) !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
919
  }
920
  """
921
 
922
- with gr.Blocks(css=css, theme=gr.themes.Base()) as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
923
  gr.Markdown("# dcode")
924
  gr.Markdown("text → polargraph gcode via stable diffusion")
925
 
 
610
 
611
  svg = f'''<svg xmlns="http://www.w3.org/2000/svg"
612
  viewBox="{BOUNDS["left"] - padding} {-BOUNDS["top"] - padding} {w + 2*padding} {h + 2*padding}"
613
+ style="width: 100%; height: 480px; border: 1px solid #3a3b40; border-radius: 4px; background: #2a2b30;">
614
+ <rect fill="#2a2b30" x="{BOUNDS["left"] - padding}" y="{-BOUNDS["top"] - padding}" width="{w + 2*padding}" height="{h + 2*padding}"/>
615
+ <rect fill="#212226" stroke="#3a3b40" x="{BOUNDS["left"]}" y="{-BOUNDS["top"]}" width="{w}" height="{h}" stroke-width="1"/>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
616
  '''
617
 
618
  for path in paths:
619
  if len(path) < 2:
620
  continue
621
  d = " ".join(f"{'M' if i == 0 else 'L'}{p[0]:.1f},{-p[1]:.1f}" for i, p in enumerate(path))
622
+ svg += f'<path d="{d}" fill="none" stroke="#e8e8e8" stroke-width="1" stroke-linecap="round" stroke-linejoin="round"/>'
623
 
624
  total_points = sum(len(p) for p in paths)
625
  svg += f'''
626
+ <text x="{BOUNDS["left"] + 8}" y="{-BOUNDS["top"] + 20}" font-family="monospace" font-size="12" fill="#666">
627
  {len(paths)} paths / {total_points} points
628
  </text>
629
  '''
 
819
  css = """
820
  @import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&display=swap');
821
 
822
+ /* Force dark mode everywhere */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
823
  * {
824
  font-family: 'IBM Plex Mono', monospace !important;
825
  }
826
 
827
+ html, body, .gradio-container, .main, .wrap, .contain,
828
+ #component-0, .app, [class*="container"], [class*="wrapper"] {
829
+ background: #212226 !important;
830
+ background-color: #212226 !important;
831
+ color: #e8e8e8 !important;
832
  }
833
 
834
  .gradio-container {
 
836
  margin: auto;
837
  }
838
 
839
+ /* All text elements */
840
+ h1, h2, h3, h4, p, span, label, .label-wrap, .label-text,
841
+ [class*="label"], [class*="markdown"], .prose, .prose * {
842
+ color: #e8e8e8 !important;
 
843
  }
844
 
845
+ /* Secondary/muted text */
846
+ .secondary, .muted, small, .info, .description {
847
+ color: #999 !important;
848
  }
849
 
850
+ /* Input elements */
851
+ input, textarea, select, .input-text, .textbox,
852
+ input[type="text"], input[type="number"],
853
+ [class*="textbox"], [class*="input"] {
854
+ background: #2a2b30 !important;
855
+ background-color: #2a2b30 !important;
856
+ color: #e8e8e8 !important;
857
+ border: 1px solid #3a3b40 !important;
858
+ border-radius: 4px !important;
859
  }
860
 
861
+ input::placeholder, textarea::placeholder {
862
+ color: #666 !important;
863
  }
864
 
865
+ /* Panels, boxes, accordions */
866
+ .panel, .box, .form, .block, .accordion,
867
+ [class*="panel"], [class*="box"], [class*="accordion"],
868
+ [class*="block"], [class*="group"], .gr-group {
869
+ background: #2a2b30 !important;
870
+ background-color: #2a2b30 !important;
871
+ border: 1px solid #3a3b40 !important;
872
+ border-radius: 4px !important;
873
  }
874
 
875
+ /* Code blocks */
876
+ code, pre, .code, [class*="code"] {
877
+ background: #2a2b30 !important;
878
+ background-color: #2a2b30 !important;
879
+ color: #e8e8e8 !important;
880
+ border: 1px solid #3a3b40 !important;
881
  }
882
 
883
+ /* Buttons */
884
+ button, .button, .btn, [class*="button"], [class*="btn"] {
885
+ background: #3a3b40 !important;
886
+ background-color: #3a3b40 !important;
887
+ border: 1px solid #4a4b50 !important;
888
+ color: #e8e8e8 !important;
889
+ font-weight: 500 !important;
890
+ }
891
+
892
+ button:hover, .button:hover, .btn:hover {
893
+ background: #4a4b50 !important;
894
+ background-color: #4a4b50 !important;
895
+ }
896
+
897
+ /* Generate button - accent */
898
+ .primary, [class*="primary"] {
899
+ background: #4a4b50 !important;
900
+ background-color: #4a4b50 !important;
901
+ }
902
+
903
+ /* Examples */
904
+ .examples, [class*="example"] {
905
+ background: transparent !important;
906
+ }
907
+
908
+ .examples button, [class*="example"] button {
909
+ background: #2a2b30 !important;
910
+ border: 1px solid #3a3b40 !important;
911
  }
912
 
913
+ /* Sliders */
914
+ input[type="range"], .range, [class*="slider"] {
915
+ background: #3a3b40 !important;
916
  }
917
 
918
+ /* Links */
919
+ a, a:visited {
920
+ color: #999 !important;
921
  }
922
 
923
  a:hover {
924
+ color: #e8e8e8 !important;
925
+ }
926
+
927
+ /* Borders and dividers */
928
+ hr, .divider, [class*="divider"] {
929
+ border-color: #3a3b40 !important;
930
+ }
931
+
932
+ /* Hide footer */
933
+ footer {
934
+ display: none !important;
935
+ }
936
+
937
+ /* Dropdown menus */
938
+ .dropdown, [class*="dropdown"], .menu, [class*="menu"] {
939
+ background: #2a2b30 !important;
940
+ border: 1px solid #3a3b40 !important;
941
+ }
942
+
943
+ /* Tabs */
944
+ .tab, [class*="tab"] {
945
+ background: #2a2b30 !important;
946
+ color: #e8e8e8 !important;
947
+ }
948
+
949
+ /* Number inputs */
950
+ input[type="number"] {
951
+ background: #2a2b30 !important;
952
+ color: #e8e8e8 !important;
953
+ }
954
+
955
+ /* Make sure accordion headers are visible */
956
+ .accordion-header, summary, [class*="accordion"] > * {
957
+ color: #e8e8e8 !important;
958
  }
959
  """
960
 
961
+ # Create dark theme
962
+ dark_theme = gr.themes.Base(
963
+ primary_hue="gray",
964
+ secondary_hue="gray",
965
+ neutral_hue="gray",
966
+ ).set(
967
+ body_background_fill="#212226",
968
+ body_background_fill_dark="#212226",
969
+ body_text_color="#e8e8e8",
970
+ body_text_color_dark="#e8e8e8",
971
+ background_fill_primary="#212226",
972
+ background_fill_primary_dark="#212226",
973
+ background_fill_secondary="#2a2b30",
974
+ background_fill_secondary_dark="#2a2b30",
975
+ block_background_fill="#2a2b30",
976
+ block_background_fill_dark="#2a2b30",
977
+ block_border_color="#3a3b40",
978
+ block_border_color_dark="#3a3b40",
979
+ block_label_background_fill="#2a2b30",
980
+ block_label_background_fill_dark="#2a2b30",
981
+ block_label_text_color="#e8e8e8",
982
+ block_label_text_color_dark="#e8e8e8",
983
+ block_title_text_color="#e8e8e8",
984
+ block_title_text_color_dark="#e8e8e8",
985
+ input_background_fill="#2a2b30",
986
+ input_background_fill_dark="#2a2b30",
987
+ input_border_color="#3a3b40",
988
+ input_border_color_dark="#3a3b40",
989
+ input_placeholder_color="#666666",
990
+ input_placeholder_color_dark="#666666",
991
+ button_primary_background_fill="#3a3b40",
992
+ button_primary_background_fill_dark="#3a3b40",
993
+ button_primary_text_color="#e8e8e8",
994
+ button_primary_text_color_dark="#e8e8e8",
995
+ button_secondary_background_fill="#3a3b40",
996
+ button_secondary_background_fill_dark="#3a3b40",
997
+ button_secondary_text_color="#e8e8e8",
998
+ button_secondary_text_color_dark="#e8e8e8",
999
+ border_color_primary="#3a3b40",
1000
+ border_color_primary_dark="#3a3b40",
1001
+ color_accent="#4a4b50",
1002
+ color_accent_dark="#4a4b50",
1003
+ )
1004
+
1005
+ with gr.Blocks(css=css, theme=dark_theme) as demo:
1006
  gr.Markdown("# dcode")
1007
  gr.Markdown("text → polargraph gcode via stable diffusion")
1008