Spaces:
Running
on
Zero
Running
on
Zero
Commit
•
cd2465c
1
Parent(s):
97644ca
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
def generate(slider_x, slider_y, prompt):
|
4 |
+
comma_concepts_x = ', '.join(slider_x)
|
5 |
+
comma_concepts_y = ', '.join(slider_y)
|
6 |
+
return gr.update(label=comma_concepts_x, interactive=True),gr.update(label=comma_concepts_y, interactive=True), gr.update()
|
7 |
+
|
8 |
+
def update_x(slider_x):
|
9 |
+
return gr.update()
|
10 |
+
|
11 |
+
def update_y(slider_y):
|
12 |
+
return gr.update()
|
13 |
+
|
14 |
+
css = '''
|
15 |
+
#group {
|
16 |
+
position: relative;
|
17 |
+
width: 420px;
|
18 |
+
height: 420px;
|
19 |
+
margin-bottom: 20px;
|
20 |
+
background-color: white
|
21 |
+
}
|
22 |
+
#x {
|
23 |
+
position: absolute;
|
24 |
+
bottom: 0;
|
25 |
+
left: 25px;
|
26 |
+
width: 400px;
|
27 |
+
}
|
28 |
+
#y {
|
29 |
+
position: absolute;
|
30 |
+
bottom: 20px;
|
31 |
+
left: 190px;
|
32 |
+
width: 400px;
|
33 |
+
transform: rotate(-90deg);
|
34 |
+
transform-origin: left bottom;
|
35 |
+
}
|
36 |
+
#image_out{position:absolute; width: 80%; right: 10px; top: 40px}
|
37 |
+
'''
|
38 |
+
with gr.Blocks(css=css) as demo:
|
39 |
+
with gr.Group(elem_id="group"):
|
40 |
+
x = gr.Slider(minimum=-10, value=0, maximum=10, elem_id="x", interactive=False)
|
41 |
+
y = gr.Slider(minimum=-10, value=0, maximum=10, elem_id="y", interactive=False)
|
42 |
+
output_image = gr.Image(elem_id="image_out")
|
43 |
+
|
44 |
+
slider_x = gr.Dropdown(label="Slider X concept range", allow_custom_value=True, multiselect=True, max_choices=2)
|
45 |
+
slider_y = gr.Dropdown(label="Slider X concept range", allow_custom_value=True, multiselect=True, max_choices=2)
|
46 |
+
prompt = gr.Textbox(label="Prompt")
|
47 |
+
submit = gr.Button("Submit")
|
48 |
+
submit.click(fn=generate,
|
49 |
+
inputs=[slider_x, slider_y, prompt],
|
50 |
+
outputs=[x, y, output_image])
|
51 |
+
x.change(fn=update_x, inputs=[slider_x], outputs=[output_image])
|
52 |
+
y.change(fn=update_y, inputs=[slider_y], outputs=[output_image])
|
53 |
+
if __name__ == "__main__":
|
54 |
+
demo.launch()
|