Support dynamic light/dark theme switching
Browse files
app.py
CHANGED
|
@@ -610,20 +610,32 @@ 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
|
| 614 |
-
<
|
| 615 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 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"
|
| 627 |
{len(paths)} paths / {total_points} points
|
| 628 |
</text>
|
| 629 |
'''
|
|
@@ -819,188 +831,65 @@ def generate(prompt: str, temperature: float, max_tokens: int, num_steps: int, g
|
|
| 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 {
|
| 835 |
max-width: 900px !important;
|
| 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
|
| 962 |
-
|
| 963 |
primary_hue="gray",
|
| 964 |
secondary_hue="gray",
|
| 965 |
neutral_hue="gray",
|
| 966 |
).set(
|
| 967 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
)
|
| 1002 |
|
| 1003 |
-
with gr.Blocks(css=css, theme=
|
| 1004 |
gr.Markdown("# dcode")
|
| 1005 |
gr.Markdown("text → polargraph gcode via stable diffusion")
|
| 1006 |
|
|
|
|
| 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-radius: 4px;">
|
| 614 |
+
<style>
|
| 615 |
+
.svg-bg {{ fill: #fafafa; }}
|
| 616 |
+
.svg-work {{ fill: #ffffff; stroke: #e0e0e0; }}
|
| 617 |
+
.svg-stroke {{ stroke: #1a1a1a; }}
|
| 618 |
+
.svg-label {{ fill: #999; }}
|
| 619 |
+
@media (prefers-color-scheme: dark) {{
|
| 620 |
+
.svg-bg {{ fill: #2a2b30; }}
|
| 621 |
+
.svg-work {{ fill: #212226; stroke: #3a3b40; }}
|
| 622 |
+
.svg-stroke {{ stroke: #e8e8e8; }}
|
| 623 |
+
.svg-label {{ fill: #666; }}
|
| 624 |
+
}}
|
| 625 |
+
</style>
|
| 626 |
+
<rect class="svg-bg" x="{BOUNDS["left"] - padding}" y="{-BOUNDS["top"] - padding}" width="{w + 2*padding}" height="{h + 2*padding}"/>
|
| 627 |
+
<rect class="svg-work" x="{BOUNDS["left"]}" y="{-BOUNDS["top"]}" width="{w}" height="{h}" stroke-width="1"/>
|
| 628 |
'''
|
| 629 |
|
| 630 |
for path in paths:
|
| 631 |
if len(path) < 2:
|
| 632 |
continue
|
| 633 |
d = " ".join(f"{'M' if i == 0 else 'L'}{p[0]:.1f},{-p[1]:.1f}" for i, p in enumerate(path))
|
| 634 |
+
svg += f'<path class="svg-stroke" d="{d}" fill="none" stroke-width="1" stroke-linecap="round" stroke-linejoin="round"/>'
|
| 635 |
|
| 636 |
total_points = sum(len(p) for p in paths)
|
| 637 |
svg += f'''
|
| 638 |
+
<text class="svg-label" x="{BOUNDS["left"] + 8}" y="{-BOUNDS["top"] + 20}" font-family="monospace" font-size="12">
|
| 639 |
{len(paths)} paths / {total_points} points
|
| 640 |
</text>
|
| 641 |
'''
|
|
|
|
| 831 |
css = """
|
| 832 |
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&display=swap');
|
| 833 |
|
|
|
|
| 834 |
* {
|
| 835 |
font-family: 'IBM Plex Mono', monospace !important;
|
| 836 |
}
|
| 837 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 838 |
.gradio-container {
|
| 839 |
max-width: 900px !important;
|
| 840 |
margin: auto;
|
| 841 |
}
|
| 842 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 843 |
footer {
|
| 844 |
display: none !important;
|
| 845 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 846 |
"""
|
| 847 |
|
| 848 |
+
# Create theme with proper light/dark mode support
|
| 849 |
+
theme = gr.themes.Base(
|
| 850 |
primary_hue="gray",
|
| 851 |
secondary_hue="gray",
|
| 852 |
neutral_hue="gray",
|
| 853 |
).set(
|
| 854 |
+
# Light mode
|
| 855 |
+
body_background_fill="#ffffff",
|
| 856 |
+
body_text_color="#1a1a1a",
|
| 857 |
+
background_fill_primary="#ffffff",
|
| 858 |
+
background_fill_secondary="#fafafa",
|
| 859 |
+
block_background_fill="#fafafa",
|
| 860 |
+
block_border_color="#e0e0e0",
|
| 861 |
+
block_label_background_fill="#fafafa",
|
| 862 |
+
block_label_text_color="#1a1a1a",
|
| 863 |
+
block_title_text_color="#1a1a1a",
|
| 864 |
+
input_background_fill="#ffffff",
|
| 865 |
+
input_border_color="#e0e0e0",
|
| 866 |
+
input_placeholder_color="#999999",
|
| 867 |
+
button_primary_background_fill="#f0f0f0",
|
| 868 |
+
button_primary_text_color="#1a1a1a",
|
| 869 |
+
button_secondary_background_fill="#f0f0f0",
|
| 870 |
+
button_secondary_text_color="#1a1a1a",
|
| 871 |
+
border_color_primary="#e0e0e0",
|
| 872 |
+
# Dark mode
|
| 873 |
body_background_fill_dark="#212226",
|
|
|
|
| 874 |
body_text_color_dark="#e8e8e8",
|
|
|
|
| 875 |
background_fill_primary_dark="#212226",
|
|
|
|
| 876 |
background_fill_secondary_dark="#2a2b30",
|
|
|
|
| 877 |
block_background_fill_dark="#2a2b30",
|
|
|
|
| 878 |
block_border_color_dark="#3a3b40",
|
|
|
|
| 879 |
block_label_background_fill_dark="#2a2b30",
|
|
|
|
| 880 |
block_label_text_color_dark="#e8e8e8",
|
|
|
|
| 881 |
block_title_text_color_dark="#e8e8e8",
|
|
|
|
| 882 |
input_background_fill_dark="#2a2b30",
|
|
|
|
| 883 |
input_border_color_dark="#3a3b40",
|
|
|
|
| 884 |
input_placeholder_color_dark="#666666",
|
|
|
|
| 885 |
button_primary_background_fill_dark="#3a3b40",
|
|
|
|
| 886 |
button_primary_text_color_dark="#e8e8e8",
|
|
|
|
| 887 |
button_secondary_background_fill_dark="#3a3b40",
|
|
|
|
| 888 |
button_secondary_text_color_dark="#e8e8e8",
|
|
|
|
| 889 |
border_color_primary_dark="#3a3b40",
|
| 890 |
)
|
| 891 |
|
| 892 |
+
with gr.Blocks(css=css, theme=theme) as demo:
|
| 893 |
gr.Markdown("# dcode")
|
| 894 |
gr.Markdown("text → polargraph gcode via stable diffusion")
|
| 895 |
|