Spaces:
Sleeping
Sleeping
Update run.py
Browse files
run.py
CHANGED
|
@@ -69,17 +69,39 @@ def compute(primary_color, secondary_color, neutral_color):
|
|
| 69 |
|
| 70 |
return css
|
| 71 |
|
| 72 |
-
with gr.Blocks(
|
| 73 |
primary_color_input = gr.ColorPicker(label="Primary color", value="#f97316")
|
| 74 |
secondary_color_input = gr.ColorPicker(label="Secondary color", value="#3b82f6")
|
| 75 |
neutral_color_input = gr.ColorPicker(label="Neutral color", value="#6b7280")
|
| 76 |
|
| 77 |
css_output = gr.Textbox(label="Custom css", lines=10)
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
gr.Interface(
|
| 80 |
-
fn=
|
| 81 |
inputs=[primary_color_input, secondary_color_input, neutral_color_input],
|
| 82 |
-
outputs=[css_output
|
| 83 |
)
|
| 84 |
|
| 85 |
if __name__ == "__main__":
|
|
|
|
| 69 |
|
| 70 |
return css
|
| 71 |
|
| 72 |
+
with gr.Blocks() as demo:
|
| 73 |
primary_color_input = gr.ColorPicker(label="Primary color", value="#f97316")
|
| 74 |
secondary_color_input = gr.ColorPicker(label="Secondary color", value="#3b82f6")
|
| 75 |
neutral_color_input = gr.ColorPicker(label="Neutral color", value="#6b7280")
|
| 76 |
|
| 77 |
css_output = gr.Textbox(label="Custom css", lines=10)
|
| 78 |
+
|
| 79 |
+
def update_css(primary_color, secondary_color, neutral_color):
|
| 80 |
+
new_css = compute(primary_color, secondary_color, neutral_color)
|
| 81 |
+
js_code = f"""
|
| 82 |
+
<style id="dynamic-css">{new_css}</style>
|
| 83 |
+
<script>
|
| 84 |
+
var styleElement = document.getElementById('dynamic-css');
|
| 85 |
+
if (styleElement) {{
|
| 86 |
+
styleElement.innerHTML = `{new_css}`;
|
| 87 |
+
}} else {{
|
| 88 |
+
styleElement = document.createElement('style');
|
| 89 |
+
styleElement.id = 'dynamic-css';
|
| 90 |
+
styleElement.innerHTML = `{new_css}`;
|
| 91 |
+
document.head.appendChild(styleElement);
|
| 92 |
+
}}
|
| 93 |
+
</script>
|
| 94 |
+
"""
|
| 95 |
+
return new_css, gr.HTML(js_code)
|
| 96 |
+
|
| 97 |
+
primary_color_input.change(fn=update_css, inputs=[primary_color_input, secondary_color_input, neutral_color_input], outputs=[css_output, gr.HTML()])
|
| 98 |
+
secondary_color_input.change(fn=update_css, inputs=[primary_color_input, secondary_color_input, neutral_color_input], outputs=[css_output, gr.HTML()])
|
| 99 |
+
neutral_color_input.change(fn=update_css, inputs=[primary_color_input, secondary_color_input, neutral_color_input], outputs=[css_output, gr.HTML()])
|
| 100 |
+
|
| 101 |
gr.Interface(
|
| 102 |
+
fn=update_css,
|
| 103 |
inputs=[primary_color_input, secondary_color_input, neutral_color_input],
|
| 104 |
+
outputs=[css_output, gr.HTML()]
|
| 105 |
)
|
| 106 |
|
| 107 |
if __name__ == "__main__":
|