abreza commited on
Commit
820cfc0
1 Parent(s): 6d7a5b2

chore: Update Gradio UI layout for image generation and processing

Browse files
Files changed (1) hide show
  1. app.py +71 -78
app.py CHANGED
@@ -190,100 +190,93 @@ pipe = StableDiffusionXLPipeline.from_pretrained(
190
 
191
  print('Loading Finished!')
192
 
193
- # Gradio UI
194
  with gr.Blocks() as demo:
195
  with gr.Group():
196
  with gr.Row():
197
- prompt = gr.Textbox(label='Enter your prompt (English)', scale=8)
198
  submit_prompt = gr.Button(
199
  'Generate Image', scale=1, variant='primary')
200
- img = gr.Image(label='SDXL-Lightning Generated Image')
201
-
202
- with gr.Row(variant="panel"):
203
- with gr.Column():
204
- with gr.Row():
205
- input_image = gr.Image(
206
- label="Input Image",
207
- image_mode="RGBA",
208
- sources="upload",
209
- type="pil",
210
- elem_id="content_image",
211
- )
212
- processed_image = gr.Image(
213
- label="Processed Image",
214
- image_mode="RGBA",
215
- type="pil",
216
- interactive=False
217
- )
218
- with gr.Row():
219
- with gr.Group():
220
- do_remove_background = gr.Checkbox(
221
- label="Remove Background", value=True)
222
- sample_seed = gr.Number(
223
- value=42, label="Seed Value", precision=0)
224
- sample_steps = gr.Slider(
225
- label="Sample Steps", minimum=30, maximum=75, value=75, step=5)
226
-
227
- with gr.Row():
228
- submit_mesh = gr.Button(
229
- "Generate", elem_id="generate", variant="primary")
230
 
 
231
  with gr.Row(variant="panel"):
232
- gr.Examples(
233
- examples=[os.path.join("examples", img_name)
234
- for img_name in sorted(os.listdir("examples"))],
235
- inputs=[input_image],
236
- label="Examples",
237
- cache_examples=False,
238
- examples_per_page=16
239
- )
240
-
241
- with gr.Column():
242
- with gr.Row():
243
  with gr.Column():
244
- mv_show_images = gr.Image(
245
- label="Generated Multi-views",
246
- type="pil",
247
- width=379,
248
- interactive=False
249
- )
250
-
251
- with gr.Row():
252
- with gr.Tab("OBJ"):
253
- output_model_obj = gr.Model3D(
254
- label="Output Model (OBJ Format)",
255
- interactive=False,
256
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
257
  gr.Markdown(
258
- "Note: Downloaded .obj model will be flipped. Export .glb instead or manually flip it before usage.")
259
- with gr.Tab("GLB"):
260
- output_model_glb = gr.Model3D(
261
- label="Output Model (GLB Format)",
262
- interactive=False,
263
- )
264
- gr.Markdown(
265
- "Note: The model shown here has a darker appearance. Download to get correct results.")
266
-
267
- with gr.Row():
268
- gr.Markdown(
269
- '''Try a different <b>seed value</b> if the result is unsatisfying (Default: 42).''')
270
 
271
  mv_images = gr.State()
272
 
273
  submit_prompt.click(fn=generate_image, inputs=[prompt], outputs=img)
274
-
275
  submit_mesh.click(fn=check_input_image, inputs=[input_image]).success(
276
- fn=preprocess,
277
- inputs=[input_image, do_remove_background],
278
- outputs=[processed_image],
279
  ).success(
280
- fn=generate_mvs,
281
- inputs=[processed_image, sample_steps, sample_seed],
282
- outputs=[mv_images, mv_show_images]
283
  ).success(
284
- fn=make3d,
285
- inputs=[mv_images],
286
- outputs=[output_model_obj, output_model_glb]
287
  )
288
 
289
  demo.launch()
 
190
 
191
  print('Loading Finished!')
192
 
 
193
  with gr.Blocks() as demo:
194
  with gr.Group():
195
  with gr.Row():
196
+ prompt = gr.Textbox(label='Enter your prompt (English)', scale=2)
197
  submit_prompt = gr.Button(
198
  'Generate Image', scale=1, variant='primary')
199
+ img = gr.Image()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
 
201
+ with gr.Tab("Image Processing"):
202
  with gr.Row(variant="panel"):
 
 
 
 
 
 
 
 
 
 
 
203
  with gr.Column():
204
+ with gr.Row():
205
+ input_image = gr.Image(
206
+ label="Input Image",
207
+ image_mode="RGBA",
208
+ sources="upload",
209
+ type="pil",
210
+ elem_id="content_image",
211
+ )
212
+ processed_image = gr.Image(
213
+ label="Processed Image",
214
+ image_mode="RGBA",
215
+ type="pil",
216
+ interactive=False
217
+ )
218
+ with gr.Row():
219
+ with gr.Group():
220
+ do_remove_background = gr.Checkbox(
221
+ label="Remove Background", value=True)
222
+ sample_seed = gr.Number(
223
+ value=42, label="Seed Value", precision=0)
224
+ sample_steps = gr.Slider(
225
+ label="Sample Steps", minimum=30, maximum=75, value=75, step=5)
226
+ with gr.Row():
227
+ submit_mesh = gr.Button(
228
+ "Generate", elem_id="generate", variant="primary")
229
+ with gr.Row(variant="panel"):
230
+ gr.Examples(
231
+ examples=[os.path.join("examples", img_name) for img_name in sorted(
232
+ os.listdir("examples"))],
233
+ inputs=[input_image],
234
+ label="Examples",
235
+ cache_examples=False,
236
+ examples_per_page=16
237
+ )
238
+
239
+ with gr.Tab("3D Model"):
240
+ with gr.Column():
241
+ with gr.Row():
242
+ with gr.Column():
243
+ mv_show_images = gr.Image(
244
+ label="Generated Multi-views",
245
+ type="pil",
246
+ width=379,
247
+ interactive=False
248
+ )
249
+ with gr.Row():
250
+ with gr.Tab("OBJ"):
251
+ output_model_obj = gr.Model3D(
252
+ label="Output Model (OBJ Format)",
253
+ interactive=False,
254
+ )
255
+ gr.Markdown(
256
+ "Note: Downloaded .obj model will be flipped. Export .glb instead or manually flip it before usage.")
257
+ with gr.Tab("GLB"):
258
+ output_model_glb = gr.Model3D(
259
+ label="Output Model (GLB Format)",
260
+ interactive=False,
261
+ )
262
+ gr.Markdown(
263
+ "Note: The model shown here has a darker appearance. Download to get correct results.")
264
+ with gr.Row():
265
  gr.Markdown(
266
+ '''Try a different <b>seed value</b> if the result is unsatisfying (Default: 42).''')
 
 
 
 
 
 
 
 
 
 
 
267
 
268
  mv_images = gr.State()
269
 
270
  submit_prompt.click(fn=generate_image, inputs=[prompt], outputs=img)
 
271
  submit_mesh.click(fn=check_input_image, inputs=[input_image]).success(
272
+ fn=preprocess, inputs=[input_image,
273
+ do_remove_background], outputs=[processed_image],
 
274
  ).success(
275
+ fn=generate_mvs, inputs=[processed_image, sample_steps, sample_seed], outputs=[
276
+ mv_images, mv_show_images]
 
277
  ).success(
278
+ fn=make3d, inputs=[mv_images], outputs=[
279
+ output_model_obj, output_model_glb]
 
280
  )
281
 
282
  demo.launch()