Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- app.py +13 -13
- dark-miku.webp +0 -0
- light-miku-faded.webp +0 -0
- light-miku.webp +0 -0
- theme_dropdown.py +57 -0
app.py
CHANGED
|
@@ -6,7 +6,7 @@ from gradio.themes.utils.theme_dropdown import create_theme_dropdown
|
|
| 6 |
dropdown, js = create_theme_dropdown()
|
| 7 |
|
| 8 |
with gr.Blocks(theme='John6666/Yntec_Theme') as demo:
|
| 9 |
-
with gr.Row(
|
| 10 |
with gr.Column(scale=10):
|
| 11 |
gr.Markdown(
|
| 12 |
"""
|
|
@@ -17,7 +17,7 @@ with gr.Blocks(theme='John6666/Yntec_Theme') as demo:
|
|
| 17 |
"""
|
| 18 |
)
|
| 19 |
with gr.Column(scale=3):
|
| 20 |
-
with gr.
|
| 21 |
dropdown.render()
|
| 22 |
toggle_dark = gr.Button(value="Toggle Dark")
|
| 23 |
|
|
@@ -63,17 +63,18 @@ with gr.Blocks(theme='John6666/Yntec_Theme') as demo:
|
|
| 63 |
check = gr.Checkbox(label="Go")
|
| 64 |
with gr.Column(variant="panel", scale=2):
|
| 65 |
img = gr.Image(
|
| 66 |
-
"https://
|
| 67 |
label="Image",
|
| 68 |
-
|
| 69 |
-
)
|
| 70 |
with gr.Row():
|
| 71 |
-
go_btn = gr.Button("Go", variant="primary")
|
| 72 |
-
clear_btn = gr.Button(
|
|
|
|
|
|
|
| 73 |
|
| 74 |
def go(*args):
|
| 75 |
time.sleep(3)
|
| 76 |
-
return "https://
|
| 77 |
|
| 78 |
go_btn.click(go, [radio, drop, drop_2, check, name], img, api_name="go")
|
| 79 |
|
|
@@ -84,9 +85,9 @@ with gr.Blocks(theme='John6666/Yntec_Theme') as demo:
|
|
| 84 |
clear_btn.click(clear, None, img)
|
| 85 |
|
| 86 |
with gr.Row():
|
| 87 |
-
btn1 = gr.Button("Button 1"
|
| 88 |
-
btn2 = gr.UploadButton(size="sm")
|
| 89 |
-
stop_btn = gr.Button("Stop",
|
| 90 |
|
| 91 |
with gr.Row():
|
| 92 |
gr.Dataframe(value=[[1, 2, 3], [4, 5, 6], [7, 8, 9]], label="Dataframe")
|
|
@@ -112,8 +113,7 @@ with gr.Blocks(theme='John6666/Yntec_Theme') as demo:
|
|
| 112 |
"https://gradio-static-files.s3.us-west-2.amazonaws.com/tower.jpg",
|
| 113 |
"tower",
|
| 114 |
),
|
| 115 |
-
]
|
| 116 |
-
height=200,
|
| 117 |
)
|
| 118 |
|
| 119 |
with gr.Row():
|
|
|
|
| 6 |
dropdown, js = create_theme_dropdown()
|
| 7 |
|
| 8 |
with gr.Blocks(theme='John6666/Yntec_Theme') as demo:
|
| 9 |
+
with gr.Row():
|
| 10 |
with gr.Column(scale=10):
|
| 11 |
gr.Markdown(
|
| 12 |
"""
|
|
|
|
| 17 |
"""
|
| 18 |
)
|
| 19 |
with gr.Column(scale=3):
|
| 20 |
+
with gr.Box():
|
| 21 |
dropdown.render()
|
| 22 |
toggle_dark = gr.Button(value="Toggle Dark")
|
| 23 |
|
|
|
|
| 63 |
check = gr.Checkbox(label="Go")
|
| 64 |
with gr.Column(variant="panel", scale=2):
|
| 65 |
img = gr.Image(
|
| 66 |
+
"https://i.ibb.co/F4hKFrZ/dark-miku.webp",
|
| 67 |
label="Image",
|
| 68 |
+
).style(height=320)
|
|
|
|
| 69 |
with gr.Row():
|
| 70 |
+
go_btn = gr.Button("Go", label="Primary Button", variant="primary")
|
| 71 |
+
clear_btn = gr.Button(
|
| 72 |
+
"Clear", label="Secondary Button", variant="secondary"
|
| 73 |
+
)
|
| 74 |
|
| 75 |
def go(*args):
|
| 76 |
time.sleep(3)
|
| 77 |
+
return "https://i.ibb.co/0rfK9Wm/light-miku-faded.webp"
|
| 78 |
|
| 79 |
go_btn.click(go, [radio, drop, drop_2, check, name], img, api_name="go")
|
| 80 |
|
|
|
|
| 85 |
clear_btn.click(clear, None, img)
|
| 86 |
|
| 87 |
with gr.Row():
|
| 88 |
+
btn1 = gr.Button("Button 1").style(size="sm")
|
| 89 |
+
btn2 = gr.UploadButton().style(size="sm")
|
| 90 |
+
stop_btn = gr.Button("Stop", label="Stop Button", variant="stop")
|
| 91 |
|
| 92 |
with gr.Row():
|
| 93 |
gr.Dataframe(value=[[1, 2, 3], [4, 5, 6], [7, 8, 9]], label="Dataframe")
|
|
|
|
| 113 |
"https://gradio-static-files.s3.us-west-2.amazonaws.com/tower.jpg",
|
| 114 |
"tower",
|
| 115 |
),
|
| 116 |
+
]
|
|
|
|
| 117 |
)
|
| 118 |
|
| 119 |
with gr.Row():
|
dark-miku.webp
ADDED
|
light-miku-faded.webp
ADDED
|
light-miku.webp
ADDED
|
theme_dropdown.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import pathlib
|
| 3 |
+
|
| 4 |
+
from gradio.themes.utils import ThemeAsset
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def create_theme_dropdown():
|
| 8 |
+
import gradio as gr
|
| 9 |
+
|
| 10 |
+
asset_path = pathlib.Path(__file__).parent / "themes"
|
| 11 |
+
themes = []
|
| 12 |
+
for theme_asset in os.listdir(str(asset_path)):
|
| 13 |
+
themes.append(
|
| 14 |
+
(ThemeAsset(theme_asset), gr.Theme.load(str(asset_path / theme_asset)))
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
def make_else_if(theme_asset):
|
| 18 |
+
return f"""
|
| 19 |
+
else if (theme == '{str(theme_asset[0].version)}') {{
|
| 20 |
+
var theme_css = `{theme_asset[1]._get_theme_css()}`
|
| 21 |
+
}}"""
|
| 22 |
+
|
| 23 |
+
head, tail = themes[0], themes[1:]
|
| 24 |
+
if_statement = f"""
|
| 25 |
+
if (theme == "{str(head[0].version)}") {{
|
| 26 |
+
var theme_css = `{head[1]._get_theme_css()}`
|
| 27 |
+
}} {" ".join(make_else_if(t) for t in tail)}
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
latest_to_oldest = sorted([t[0] for t in themes], key=lambda asset: asset.version)[
|
| 31 |
+
::-1
|
| 32 |
+
]
|
| 33 |
+
latest_to_oldest = [str(t.version) for t in latest_to_oldest]
|
| 34 |
+
|
| 35 |
+
component = gr.Dropdown(
|
| 36 |
+
choices=latest_to_oldest,
|
| 37 |
+
value=latest_to_oldest[0],
|
| 38 |
+
render=False,
|
| 39 |
+
label="Select Version",
|
| 40 |
+
).style(container=False)
|
| 41 |
+
|
| 42 |
+
return (
|
| 43 |
+
component,
|
| 44 |
+
f"""
|
| 45 |
+
(theme) => {{
|
| 46 |
+
if (!document.querySelector('.theme-css')) {{
|
| 47 |
+
var theme_elem = document.createElement('style');
|
| 48 |
+
theme_elem.classList.add('theme-css');
|
| 49 |
+
document.head.appendChild(theme_elem);
|
| 50 |
+
}} else {{
|
| 51 |
+
var theme_elem = document.querySelector('.theme-css');
|
| 52 |
+
}}
|
| 53 |
+
{if_statement}
|
| 54 |
+
theme_elem.innerHTML = theme_css;
|
| 55 |
+
}}
|
| 56 |
+
""",
|
| 57 |
+
)
|