Update app.py
Browse files
app.py
CHANGED
@@ -175,25 +175,9 @@ def gen(prompt: str, system_prompt: str, token: str, accountId: str):
|
|
175 |
for i, p in enumerate(failed_prompts, 1):
|
176 |
text += f"\n{i}. {p}"
|
177 |
|
178 |
-
|
179 |
-
if images:
|
180 |
-
cols = min(5, len(images))
|
181 |
-
rows = (len(images) + cols - 1) // cols
|
182 |
-
grid_width = cols * 512 # assuming each image is 512x512
|
183 |
-
grid_height = rows * 512
|
184 |
-
grid_image = Image.new('RGB', (grid_width, grid_height))
|
185 |
-
|
186 |
-
for idx, img in enumerate(images):
|
187 |
-
x = (idx % cols) * 512
|
188 |
-
y = (idx // cols) * 512
|
189 |
-
img = img.resize((512, 512))
|
190 |
-
grid_image.paste(img, (x, y))
|
191 |
-
|
192 |
-
return text, grid_image
|
193 |
-
else:
|
194 |
-
return text, None
|
195 |
|
196 |
-
# Gradio
|
197 |
with gr.Blocks(theme="ocean") as demo:
|
198 |
gr.HTML("<h1><center>ImagenX</center></h1>")
|
199 |
prompt = gr.Textbox(label='Enter Your Prompt', placeholder="Enter prompt...")
|
@@ -201,7 +185,15 @@ with gr.Blocks(theme="ocean") as demo:
|
|
201 |
sendBtn = gr.Button(variant='primary')
|
202 |
clearBtn = gr.ClearButton([prompt])
|
203 |
gen_text = gr.Textbox(label="Optimization")
|
204 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
with gr.Accordion("Advanced Options", open=True):
|
206 |
system_prompt = gr.Textbox(
|
207 |
value = PRESET_PROMPT,
|
@@ -231,7 +223,4 @@ with gr.Blocks(theme="ocean") as demo:
|
|
231 |
accountId
|
232 |
],
|
233 |
outputs=[gen_text, gen_img]
|
234 |
-
)
|
235 |
-
|
236 |
-
if __name__ == "__main__":
|
237 |
-
demo.queue(api_open=False).launch(show_api=False, share=False)
|
|
|
175 |
for i, p in enumerate(failed_prompts, 1):
|
176 |
text += f"\n{i}. {p}"
|
177 |
|
178 |
+
return text, images
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
|
180 |
+
# Modify Gradio interface
|
181 |
with gr.Blocks(theme="ocean") as demo:
|
182 |
gr.HTML("<h1><center>ImagenX</center></h1>")
|
183 |
prompt = gr.Textbox(label='Enter Your Prompt', placeholder="Enter prompt...")
|
|
|
185 |
sendBtn = gr.Button(variant='primary')
|
186 |
clearBtn = gr.ClearButton([prompt])
|
187 |
gen_text = gr.Textbox(label="Optimization")
|
188 |
+
# Ganti Image dengan Gallery
|
189 |
+
gen_img = gr.Gallery(
|
190 |
+
label="Generated Images",
|
191 |
+
show_label=True,
|
192 |
+
elem_id="gallery",
|
193 |
+
columns=[5],
|
194 |
+
rows=[2],
|
195 |
+
height="auto"
|
196 |
+
)
|
197 |
with gr.Accordion("Advanced Options", open=True):
|
198 |
system_prompt = gr.Textbox(
|
199 |
value = PRESET_PROMPT,
|
|
|
223 |
accountId
|
224 |
],
|
225 |
outputs=[gen_text, gen_img]
|
226 |
+
)
|
|
|
|
|
|