Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -71,33 +71,37 @@ async def api_generate(request: Request):
|
|
71 |
# Gradio Interface
|
72 |
def make_me():
|
73 |
with gr.Row():
|
74 |
-
with gr.Column(scale=
|
75 |
txt_input = gr.Textbox(
|
76 |
label='Your prompt:',
|
77 |
lines=4,
|
78 |
container=False,
|
79 |
elem_id="custom_textbox",
|
80 |
-
placeholder="
|
81 |
)
|
82 |
-
|
83 |
-
with gr.Column(scale=1):
|
84 |
-
gen_button = gr.Button('Generate image', elem_id="custom_gen_button")
|
85 |
-
stop_button = gr.Button('Stop', variant='secondary', interactive=False,
|
86 |
-
elem_id="custom_stop_button")
|
87 |
-
|
88 |
-
def on_generate_click():
|
89 |
-
return gr.Button('Generate image', elem_id="custom_gen_button"), gr.Button('Stop', variant='secondary', interactive=True, elem_id="custom_stop_button")
|
90 |
|
91 |
-
|
92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
101 |
output_image = gr.Image(
|
102 |
label="Generated Image",
|
103 |
width=512,
|
@@ -107,34 +111,30 @@ def make_me():
|
|
107 |
interactive=False
|
108 |
)
|
109 |
|
110 |
-
# JSON output
|
111 |
-
json_output = gr.JSON(label="API Response")
|
112 |
-
|
113 |
def generate_wrapper(model_str, prompt):
|
114 |
# Translate prompt to English
|
115 |
translated_prompt = translator.translate(prompt)
|
116 |
image = gen_image(model_str, translated_prompt)
|
117 |
if image is None:
|
118 |
-
return None
|
|
|
119 |
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
gen_event = gen_button.click(generate_wrapper, [model_dropdown, txt_input],
|
132 |
-
[output_image, json_output])
|
133 |
-
stop_button.click(on_stop_click, inputs=None,
|
134 |
-
outputs=[gen_button, stop_button], cancels=[gen_event])
|
135 |
|
136 |
# Create Gradio app
|
137 |
-
with gr.Blocks(css=css_code) as demo:
|
|
|
|
|
138 |
make_me()
|
139 |
|
140 |
# Enable queue before mounting
|
|
|
71 |
# Gradio Interface
|
72 |
def make_me():
|
73 |
with gr.Row():
|
74 |
+
with gr.Column(scale=3):
|
75 |
txt_input = gr.Textbox(
|
76 |
label='Your prompt:',
|
77 |
lines=4,
|
78 |
container=False,
|
79 |
elem_id="custom_textbox",
|
80 |
+
placeholder="Enter your prompt here..."
|
81 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
+
with gr.Row():
|
84 |
+
gen_button = gr.Button('Generate', variant='primary', elem_id="custom_gen_button")
|
85 |
+
stop_button = gr.Button('Stop', variant='secondary', interactive=False,
|
86 |
+
elem_id="custom_stop_button")
|
87 |
+
|
88 |
+
def on_generate_click():
|
89 |
+
return gr.Button('Generating...', interactive=False, elem_id="custom_gen_button"), gr.Button('Stop', variant='secondary', interactive=True, elem_id="custom_stop_button")
|
90 |
+
|
91 |
+
def on_stop_click():
|
92 |
+
return gr.Button('Generate', variant='primary', elem_id="custom_gen_button"), gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
|
93 |
+
|
94 |
+
gen_button.click(on_generate_click, inputs=None, outputs=[gen_button, stop_button])
|
95 |
+
stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button])
|
96 |
|
97 |
+
model_dropdown = gr.Dropdown(
|
98 |
+
models,
|
99 |
+
label="Select Model",
|
100 |
+
value=models[0] if models else None,
|
101 |
+
interactive=True
|
102 |
+
)
|
103 |
+
|
104 |
+
with gr.Column(scale=2):
|
105 |
output_image = gr.Image(
|
106 |
label="Generated Image",
|
107 |
width=512,
|
|
|
111 |
interactive=False
|
112 |
)
|
113 |
|
|
|
|
|
|
|
114 |
def generate_wrapper(model_str, prompt):
|
115 |
# Translate prompt to English
|
116 |
translated_prompt = translator.translate(prompt)
|
117 |
image = gen_image(model_str, translated_prompt)
|
118 |
if image is None:
|
119 |
+
return None
|
120 |
+
return image
|
121 |
|
122 |
+
gen_event = gen_button.click(
|
123 |
+
generate_wrapper,
|
124 |
+
[model_dropdown, txt_input],
|
125 |
+
output_image
|
126 |
+
)
|
127 |
+
stop_button.click(
|
128 |
+
on_stop_click,
|
129 |
+
inputs=None,
|
130 |
+
outputs=[gen_button, stop_button],
|
131 |
+
cancels=[gen_event]
|
132 |
+
)
|
|
|
|
|
|
|
|
|
133 |
|
134 |
# Create Gradio app
|
135 |
+
with gr.Blocks(css=css_code, title="Image Generator") as demo:
|
136 |
+
gr.Markdown("# Image Generation Tool")
|
137 |
+
gr.Markdown("Enter your prompt and select a model to generate an image")
|
138 |
make_me()
|
139 |
|
140 |
# Enable queue before mounting
|