AndyRaoTHU commited on
Commit
af6c0a4
·
1 Parent(s): dc057d1
Files changed (1) hide show
  1. app.py +51 -32
app.py CHANGED
@@ -280,41 +280,60 @@ class Handler:
280
 
281
  if __name__ == "__main__":
282
  # create the model handler
283
- handler = Handler(device=device)
284
-
285
- print("Creating Gradio interface...")
286
-
287
- # Demo 1 接口:图像重建
288
- demo1 = gr.Interface(
289
- fn=handler.process_image,
290
- inputs=gr.Image(label="Input Image", type="numpy"),
291
- outputs=[
292
- gr.Image(label="BaseVQ Reconstruction", type="numpy"),
293
- gr.Image(label="VQGAN Reconstruction", type="numpy"),
294
- gr.Image(label="ReVQ Reconstruction", type="numpy"),
295
- ],
296
- title="Demo 1: Image Reconstruction",
297
- description="Upload an image to see how different VQ models (BaseVQ, VQGAN, ReVQ) reconstruct it from latent codes."
298
- )
299
-
300
- demo2 = gr.Interface(
301
- fn=draw_reset_result, # 不再需要 handler 包装
302
- inputs=[
303
- gr.Slider(label="num_data", value=16, minimum=10, maximum=20, step=1),
304
- gr.Slider(label="num_code", value=12, minimum=8, maximum=16, step=1),
305
- ],
306
- outputs=[
307
- gr.Image(label="With Reset"),
308
- gr.Image(label="Without Reset")
309
- ],
310
- title="Demo 2: Codebook Reset Strategy Visualization",
311
- description="Visualizes codebook and data movement at different training steps."
312
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
313
 
314
  # 合并两个 interface 成 Tabbed UI
 
 
 
 
315
  demo = gr.TabbedInterface(
316
- interface_list=[demo1, demo2],
317
- tab_names=["Image Reconstruction", "Reset Strategy"]
318
  )
319
 
320
  demo.launch(share=True)
 
280
 
281
  if __name__ == "__main__":
282
  # create the model handler
283
+ # handler = Handler(device=device)
284
+
285
+ # print("Creating Gradio interface...")
286
+
287
+ # # Demo 1 接口:图像重建
288
+ # demo1 = gr.Interface(
289
+ # fn=handler.process_image,
290
+ # inputs=gr.Image(label="Input Image", type="numpy"),
291
+ # outputs=[
292
+ # gr.Image(label="BaseVQ Reconstruction", type="numpy"),
293
+ # gr.Image(label="VQGAN Reconstruction", type="numpy"),
294
+ # gr.Image(label="ReVQ Reconstruction", type="numpy"),
295
+ # ],
296
+ # title="Demo 1: Image Reconstruction",
297
+ # description="Upload an image to see how different VQ models (BaseVQ, VQGAN, ReVQ) reconstruct it from latent codes."
298
+ # )
299
+
300
+ # demo2 = gr.Interface(
301
+ # fn=draw_reset_result, # 不再需要 handler 包装
302
+ # inputs=[
303
+ # gr.Slider(label="num_data", value=16, minimum=10, maximum=20, step=1),
304
+ # gr.Slider(label="num_code", value=12, minimum=8, maximum=16, step=1),
305
+ # ],
306
+ # outputs=[
307
+ # gr.Image(label="With Reset"),
308
+ # gr.Image(label="Without Reset")
309
+ # ],
310
+ # title="Demo 2: Codebook Reset Strategy Visualization",
311
+ # description="Visualizes codebook and data movement at different training steps."
312
+ # )
313
+ with gr.Blocks() as demo2:
314
+ gr.Markdown("## Demo 2: Codebook Reset Strategy Visualization")
315
+ gr.Markdown("Visualizes codebook and data movement at different training steps.")
316
+
317
+ with gr.Row():
318
+ num_data = gr.Slider(label="num_data", value=16, minimum=10, maximum=20, step=1)
319
+ num_code = gr.Slider(label="num_code", value=12, minimum=8, maximum=16, step=1)
320
+
321
+ submit_btn = gr.Button("Run Visualization")
322
+
323
+ with gr.Column(): # 垂直输出
324
+ out_with_reset = gr.Image(label="With Reset")
325
+ out_without_reset = gr.Image(label="Without Reset")
326
+
327
+ submit_btn.click(fn=draw_reset_result, inputs=[num_data, num_code], outputs=[out_with_reset, out_without_reset])
328
 
329
  # 合并两个 interface 成 Tabbed UI
330
+ # demo = gr.TabbedInterface(
331
+ # interface_list=[demo1, demo2],
332
+ # tab_names=["Image Reconstruction", "Reset Strategy"]
333
+ # )
334
  demo = gr.TabbedInterface(
335
+ interface_list=[demo2],
336
+ tab_names=["Reset Strategy"]
337
  )
338
 
339
  demo.launch(share=True)