Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,141 +1,150 @@
|
|
| 1 |
import time
|
| 2 |
-
|
| 3 |
-
from theme_dropdown import create_theme_dropdown # noqa: F401
|
| 4 |
-
|
| 5 |
import gradio as gr
|
|
|
|
| 6 |
|
| 7 |
dropdown, js = create_theme_dropdown()
|
| 8 |
|
| 9 |
-
with gr.Blocks(theme=
|
| 10 |
-
|
|
|
|
| 11 |
with gr.Column(scale=10):
|
| 12 |
gr.Markdown(
|
| 13 |
"""
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
)
|
|
|
|
| 20 |
with gr.Column(scale=3):
|
| 21 |
with gr.Box():
|
| 22 |
dropdown.render()
|
| 23 |
-
toggle_dark = gr.Button(
|
| 24 |
|
| 25 |
dropdown.change(None, dropdown, None, _js=js)
|
|
|
|
| 26 |
toggle_dark.click(
|
| 27 |
None,
|
| 28 |
_js="""
|
| 29 |
() => {
|
| 30 |
document.body.classList.toggle('dark');
|
| 31 |
-
document.querySelector('gradio-app').style.backgroundColor =
|
|
|
|
| 32 |
}
|
| 33 |
""",
|
| 34 |
)
|
| 35 |
|
| 36 |
name = gr.Textbox(
|
| 37 |
label="Name",
|
| 38 |
-
info="Full name, including middle name. No special characters.",
|
| 39 |
placeholder="John Doe",
|
| 40 |
value="John Doe",
|
| 41 |
-
interactive=True,
|
| 42 |
)
|
| 43 |
|
| 44 |
with gr.Row():
|
| 45 |
slider1 = gr.Slider(label="Slider 1")
|
| 46 |
slider2 = gr.Slider(label="Slider 2")
|
|
|
|
| 47 |
gr.CheckboxGroup(["A", "B", "C"], label="Checkbox Group")
|
| 48 |
|
| 49 |
with gr.Row():
|
|
|
|
| 50 |
with gr.Column(variant="panel", scale=1):
|
|
|
|
| 51 |
gr.Markdown("## Panel 1")
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
| 56 |
)
|
| 57 |
-
|
| 58 |
drop_2 = gr.Dropdown(
|
| 59 |
["Option A", "Option B", "Option C"],
|
| 60 |
multiselect=True,
|
| 61 |
value=["Option A"],
|
| 62 |
label="Dropdown",
|
| 63 |
-
interactive=True,
|
| 64 |
)
|
|
|
|
| 65 |
check = gr.Checkbox(label="Go")
|
|
|
|
| 66 |
with gr.Column(variant="panel", scale=2):
|
| 67 |
-
img = gr.Image(
|
| 68 |
-
"https://gradio.app/assets/img/header-image.jpg", label="Image"
|
| 69 |
-
).style(height=320)
|
| 70 |
-
with gr.Row():
|
| 71 |
-
go_btn = gr.Button("Go", label="Primary Button", variant="primary")
|
| 72 |
-
clear_btn = gr.Button(
|
| 73 |
-
"Clear", label="Secondary Button", variant="secondary"
|
| 74 |
-
)
|
| 75 |
|
| 76 |
-
|
| 77 |
-
time.sleep(3)
|
| 78 |
-
return "https://gradio.app/assets/img/header-image.jpg"
|
| 79 |
|
| 80 |
-
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
with gr.Row():
|
| 89 |
-
btn1 = gr.Button("Button 1"
|
| 90 |
-
btn2 = gr.UploadButton(
|
| 91 |
-
stop_btn = gr.Button("Stop",
|
| 92 |
-
size="sm"
|
| 93 |
-
)
|
| 94 |
|
| 95 |
with gr.Row():
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
gr.JSON(
|
| 98 |
-
value={"a":
|
|
|
|
| 99 |
)
|
| 100 |
-
|
|
|
|
|
|
|
| 101 |
gr.File()
|
|
|
|
| 102 |
with gr.Row():
|
|
|
|
| 103 |
gr.ColorPicker()
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
gr.Gallery(
|
| 106 |
[
|
| 107 |
-
(
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
),
|
| 115 |
-
(
|
| 116 |
-
"https://gradio-static-files.s3.us-west-2.amazonaws.com/tower.jpg",
|
| 117 |
-
"tower",
|
| 118 |
-
),
|
| 119 |
-
]
|
| 120 |
-
).style(height="200px", grid=2)
|
| 121 |
|
| 122 |
with gr.Row():
|
|
|
|
| 123 |
with gr.Column(scale=2):
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
chat_btn = gr.Button("Add messages")
|
| 126 |
|
| 127 |
def chat(history):
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
chat_btn.click(
|
| 132 |
-
|
| 133 |
-
+ [["How are you?", "I am good."]]
|
| 134 |
-
+ (time.sleep(2) or []),
|
| 135 |
-
chatbot,
|
| 136 |
-
chatbot,
|
| 137 |
-
)
|
| 138 |
with gr.Column(scale=1):
|
|
|
|
| 139 |
with gr.Accordion("Advanced Settings"):
|
| 140 |
gr.Markdown("Hello")
|
| 141 |
gr.Number(label="Chatbot control 1")
|
|
@@ -144,4 +153,4 @@ with gr.Blocks(theme='rottenlittlecreature/Moon_Goblin') as demo:
|
|
| 144 |
|
| 145 |
|
| 146 |
if __name__ == "__main__":
|
| 147 |
-
demo.queue().launch()
|
|
|
|
| 1 |
import time
|
|
|
|
|
|
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
+
from theme_dropdown import create_theme_dropdown
|
| 4 |
|
| 5 |
dropdown, js = create_theme_dropdown()
|
| 6 |
|
| 7 |
+
with gr.Blocks(theme="rottenlittlecreature/Moon_Goblin") as demo:
|
| 8 |
+
|
| 9 |
+
with gr.Row(equal_height=True):
|
| 10 |
with gr.Column(scale=10):
|
| 11 |
gr.Markdown(
|
| 12 |
"""
|
| 13 |
+
# Theme preview: `Moon_Goblin`
|
| 14 |
+
|
| 15 |
+
To use this theme, set
|
| 16 |
+
`theme='rottenlittlecreature/Moon_Goblin'`
|
| 17 |
+
"""
|
| 18 |
)
|
| 19 |
+
|
| 20 |
with gr.Column(scale=3):
|
| 21 |
with gr.Box():
|
| 22 |
dropdown.render()
|
| 23 |
+
toggle_dark = gr.Button("Toggle Dark")
|
| 24 |
|
| 25 |
dropdown.change(None, dropdown, None, _js=js)
|
| 26 |
+
|
| 27 |
toggle_dark.click(
|
| 28 |
None,
|
| 29 |
_js="""
|
| 30 |
() => {
|
| 31 |
document.body.classList.toggle('dark');
|
| 32 |
+
document.querySelector('gradio-app').style.backgroundColor =
|
| 33 |
+
'var(--color-background-primary)'
|
| 34 |
}
|
| 35 |
""",
|
| 36 |
)
|
| 37 |
|
| 38 |
name = gr.Textbox(
|
| 39 |
label="Name",
|
|
|
|
| 40 |
placeholder="John Doe",
|
| 41 |
value="John Doe",
|
|
|
|
| 42 |
)
|
| 43 |
|
| 44 |
with gr.Row():
|
| 45 |
slider1 = gr.Slider(label="Slider 1")
|
| 46 |
slider2 = gr.Slider(label="Slider 2")
|
| 47 |
+
|
| 48 |
gr.CheckboxGroup(["A", "B", "C"], label="Checkbox Group")
|
| 49 |
|
| 50 |
with gr.Row():
|
| 51 |
+
|
| 52 |
with gr.Column(variant="panel", scale=1):
|
| 53 |
+
|
| 54 |
gr.Markdown("## Panel 1")
|
| 55 |
+
|
| 56 |
+
radio = gr.Radio(["A", "B", "C"], label="Radio")
|
| 57 |
+
|
| 58 |
+
drop = gr.Dropdown(
|
| 59 |
+
["Option 1", "Option 2", "Option 3"],
|
| 60 |
+
show_label=False
|
| 61 |
)
|
| 62 |
+
|
| 63 |
drop_2 = gr.Dropdown(
|
| 64 |
["Option A", "Option B", "Option C"],
|
| 65 |
multiselect=True,
|
| 66 |
value=["Option A"],
|
| 67 |
label="Dropdown",
|
|
|
|
| 68 |
)
|
| 69 |
+
|
| 70 |
check = gr.Checkbox(label="Go")
|
| 71 |
+
|
| 72 |
with gr.Column(variant="panel", scale=2):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
+
img = gr.Image(label="Image", height=320)
|
|
|
|
|
|
|
| 75 |
|
| 76 |
+
with gr.Row():
|
| 77 |
+
go_btn = gr.Button("Go", variant="primary")
|
| 78 |
+
clear_btn = gr.Button("Clear", variant="secondary")
|
| 79 |
|
| 80 |
+
def go(*args):
|
| 81 |
+
time.sleep(2)
|
| 82 |
+
return "https://gradio.app/assets/img/header-image.jpg"
|
| 83 |
|
| 84 |
+
def clear():
|
| 85 |
+
return None
|
| 86 |
+
|
| 87 |
+
go_btn.click(go, [radio, drop, drop_2, check, name], img)
|
| 88 |
+
clear_btn.click(clear, None, img)
|
| 89 |
|
| 90 |
with gr.Row():
|
| 91 |
+
btn1 = gr.Button("Button 1", size="sm")
|
| 92 |
+
btn2 = gr.UploadButton("Upload", size="sm")
|
| 93 |
+
stop_btn = gr.Button("Stop", variant="stop", size="sm")
|
|
|
|
|
|
|
| 94 |
|
| 95 |
with gr.Row():
|
| 96 |
+
|
| 97 |
+
gr.Dataframe(
|
| 98 |
+
value=[[1,2,3],[4,5,6],[7,8,9]],
|
| 99 |
+
label="Dataframe"
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
gr.JSON(
|
| 103 |
+
value={"a":1,"b":2,"c":{"test":"a","test2":[1,2,3]}},
|
| 104 |
+
label="JSON"
|
| 105 |
)
|
| 106 |
+
|
| 107 |
+
gr.Label({"cat":0.7,"dog":0.2,"fish":0.1})
|
| 108 |
+
|
| 109 |
gr.File()
|
| 110 |
+
|
| 111 |
with gr.Row():
|
| 112 |
+
|
| 113 |
gr.ColorPicker()
|
| 114 |
+
|
| 115 |
+
gr.Video(
|
| 116 |
+
"https://gradio-static-files.s3.us-west-2.amazonaws.com/world.mp4"
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
gr.Gallery(
|
| 120 |
[
|
| 121 |
+
("https://gradio-static-files.s3.us-west-2.amazonaws.com/lion.jpg","lion"),
|
| 122 |
+
("https://gradio-static-files.s3.us-west-2.amazonaws.com/logo.png","logo"),
|
| 123 |
+
("https://gradio-static-files.s3.us-west-2.amazonaws.com/tower.jpg","tower"),
|
| 124 |
+
],
|
| 125 |
+
height=200,
|
| 126 |
+
columns=2
|
| 127 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
with gr.Row():
|
| 130 |
+
|
| 131 |
with gr.Column(scale=2):
|
| 132 |
+
|
| 133 |
+
chatbot = gr.Chatbot(
|
| 134 |
+
value=[("Hello","Hi")],
|
| 135 |
+
label="Chatbot"
|
| 136 |
+
)
|
| 137 |
+
|
| 138 |
chat_btn = gr.Button("Add messages")
|
| 139 |
|
| 140 |
def chat(history):
|
| 141 |
+
history.append(("How are you?","I am good."))
|
| 142 |
+
return history
|
| 143 |
+
|
| 144 |
+
chat_btn.click(chat, chatbot, chatbot)
|
| 145 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
with gr.Column(scale=1):
|
| 147 |
+
|
| 148 |
with gr.Accordion("Advanced Settings"):
|
| 149 |
gr.Markdown("Hello")
|
| 150 |
gr.Number(label="Chatbot control 1")
|
|
|
|
| 153 |
|
| 154 |
|
| 155 |
if __name__ == "__main__":
|
| 156 |
+
demo.queue().launch(server_name="0.0.0.0", server_port=7860)
|