Update app.py
Browse files
app.py
CHANGED
@@ -86,6 +86,12 @@ def generate_image(prompt, guidance_scale, num_inference_steps, randomize_seed,
|
|
86 |
|
87 |
return image, seed
|
88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
# Gradio UI
|
90 |
with gr.Blocks() as demo:
|
91 |
gr.Markdown("# Text-to-Image Generator with Object Addition")
|
@@ -93,16 +99,15 @@ with gr.Blocks() as demo:
|
|
93 |
# Put prompt and submit button in the same row
|
94 |
with gr.Group():
|
95 |
with gr.Row():
|
96 |
-
#
|
97 |
prompt = gr.Text(
|
98 |
-
label="Prompt",
|
99 |
-
show_label=False,
|
100 |
-
max_lines=1,
|
101 |
-
placeholder="Enter your prompt here",
|
102 |
-
container=False
|
103 |
)
|
104 |
-
|
105 |
-
submit_button = gr.Button("Submit Prompt", scale=0) # Add scale for button size
|
106 |
|
107 |
# Always visible DataFrame
|
108 |
objects_display = gr.Dataframe(
|
@@ -115,6 +120,7 @@ with gr.Blocks() as demo:
|
|
115 |
bbox_input = gr.Textbox(label="Bounding Box (x1,y1,x2,y2)", placeholder="Enter bounding box coordinates")
|
116 |
|
117 |
add_button = gr.Button("Add Object")
|
|
|
118 |
|
119 |
# Advanced settings in a collapsible accordion
|
120 |
with gr.Accordion("Advanced Settings", open=False):
|
@@ -144,7 +150,7 @@ with gr.Blocks() as demo:
|
|
144 |
submit_button.click(
|
145 |
fn=submit_prompt,
|
146 |
inputs=prompt,
|
147 |
-
outputs=[objects_display, prompt]
|
148 |
)
|
149 |
|
150 |
# Add object and update display
|
@@ -154,6 +160,13 @@ with gr.Blocks() as demo:
|
|
154 |
outputs=[objects_display]
|
155 |
)
|
156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
# Generate image based on added objects
|
158 |
generate_button.click(
|
159 |
fn=generate_image,
|
@@ -162,4 +175,4 @@ with gr.Blocks() as demo:
|
|
162 |
)
|
163 |
|
164 |
if __name__ == "__main__":
|
165 |
-
demo.launch()
|
|
|
86 |
|
87 |
return image, seed
|
88 |
|
89 |
+
# Function to clear all arrays and reset the UI
|
90 |
+
def clear_arrays():
|
91 |
+
object_classes_list.clear()
|
92 |
+
object_bboxes_list.clear()
|
93 |
+
return [], gr.update(value="", interactive=True) # Clear the objects and reset the prompt
|
94 |
+
|
95 |
# Gradio UI
|
96 |
with gr.Blocks() as demo:
|
97 |
gr.Markdown("# Text-to-Image Generator with Object Addition")
|
|
|
99 |
# Put prompt and submit button in the same row
|
100 |
with gr.Group():
|
101 |
with gr.Row():
|
102 |
+
# Prompt input and submit button
|
103 |
prompt = gr.Text(
|
104 |
+
label="Prompt",
|
105 |
+
show_label=False,
|
106 |
+
max_lines=1,
|
107 |
+
placeholder="Enter your prompt here",
|
108 |
+
container=False
|
109 |
)
|
110 |
+
submit_button = gr.Button("Submit Prompt", scale=0)
|
|
|
111 |
|
112 |
# Always visible DataFrame
|
113 |
objects_display = gr.Dataframe(
|
|
|
120 |
bbox_input = gr.Textbox(label="Bounding Box (x1,y1,x2,y2)", placeholder="Enter bounding box coordinates")
|
121 |
|
122 |
add_button = gr.Button("Add Object")
|
123 |
+
refresh_button = gr.Button("Refresh") # New Refresh button
|
124 |
|
125 |
# Advanced settings in a collapsible accordion
|
126 |
with gr.Accordion("Advanced Settings", open=False):
|
|
|
150 |
submit_button.click(
|
151 |
fn=submit_prompt,
|
152 |
inputs=prompt,
|
153 |
+
outputs=[objects_display, prompt]
|
154 |
)
|
155 |
|
156 |
# Add object and update display
|
|
|
160 |
outputs=[objects_display]
|
161 |
)
|
162 |
|
163 |
+
# Refresh button to clear arrays and reset inputs
|
164 |
+
refresh_button.click(
|
165 |
+
fn=clear_arrays,
|
166 |
+
inputs=None,
|
167 |
+
outputs=[objects_display, prompt]
|
168 |
+
)
|
169 |
+
|
170 |
# Generate image based on added objects
|
171 |
generate_button.click(
|
172 |
fn=generate_image,
|
|
|
175 |
)
|
176 |
|
177 |
if __name__ == "__main__":
|
178 |
+
demo.launch()
|