kr-cen commited on
Commit
297f899
·
1 Parent(s): 6a440db
Files changed (2) hide show
  1. .xet +1 -0
  2. app.py +86 -17
.xet ADDED
@@ -0,0 +1 @@
 
 
1
+ {}
app.py CHANGED
@@ -325,23 +325,92 @@ with gr.Blocks(title="Qwen-Image-MICo", theme=gr.themes.Soft(), css=custom_css)
325
 
326
  # --- Examples Section ---
327
  # Create an 'examples' folder in your space and add img1.jpg, img2.jpg to enable this.
328
- if os.path.exists("examples"):
329
- gr.Markdown("### 🧩 Examples")
330
- gr.Examples(
331
- examples=[
332
- # Format: [[images], prompt, neg_prompt, cfg, seed, width, height, steps]
333
- [
334
- ["examples/img1.jpg", "examples/img2.jpg"],
335
- "Make the cat from image 1 sit on the car from image 2, sunset background",
336
- "blurry, low quality",
337
- 4.0, 42, 1024, 1024, 30
338
- ],
339
- ],
340
- inputs=[
341
- input_gallery, prompt_input, negative_prompt_input,
342
- cfg_input, seed_input, width_input, height_input, inference_steps_input
343
- ],
344
- # cache_examples=False # Disable caching to save GPU quota on startup
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
345
  )
346
 
347
  # Event Binding
 
325
 
326
  # --- Examples Section ---
327
  # Create an 'examples' folder in your space and add img1.jpg, img2.jpg to enable this.
328
+ # if os.path.exists("assets"):
329
+ # gr.Markdown("### 🧩 Examples")
330
+ # gr.Examples(
331
+ # examples=[
332
+ # # Format: [[images], prompt, neg_prompt, cfg, seed, width, height, steps]
333
+ # [
334
+ # ["assets/ex-input1.png", "assets/ex-input2.png", "assets/ex-input3.png", "assets/ex-input4.png"],
335
+ # "Make the cat from image 1 sit on the car from image 2, sunset background",
336
+ # "blurry, low quality",
337
+ # 4.0, 42, 1024, 1024, 30
338
+ # ],
339
+ # ],
340
+ # inputs=[
341
+ # input_gallery, prompt_input, negative_prompt_input,
342
+ # cfg_input, seed_input, width_input, height_input, inference_steps_input
343
+ # ],
344
+ # # cache_examples=False # Disable caching to save GPU quota on startup
345
+ # )
346
+
347
+ # 定义示例数据
348
+ # 格式: [
349
+ # "展示用的封面图(output)",
350
+ # [输入图片列表],
351
+ # prompt,
352
+ # negative_prompt,
353
+ # cfg, seed, width, height, steps
354
+ # ]
355
+ example_data = [
356
+ [
357
+ "assets/ex1-output.png", # 封面图 (也是 Output)
358
+ ["assets/ex1-input1.png", "assets/ex1-input2.png", "assets/ex1-input3.png", "assets/ex1-input4.png"], # Input Gallery
359
+ "Underneath the tall and iconic Parisian landmark from image 1, a fast and maneuverable aquatic vehicle from image 2 glides gracefully along the Seine. Nearby, a compact travel caravan for outdoor adventures from image 3 is parked, while a bike with extended handlebars and low seat from image 4 leans against it, creating a vibrant setting of exploration and leisure by the riverbank.", # Prompt
360
+ "", # Negative Prompt
361
+ 4.0, 42, 1024, 1024, 30 # Params
362
+ ],
363
+ # 你可以添加更多...
364
+ ]
365
+
366
+ if os.path.exists("assets"): # 确保文件夹存在
367
+ gr.Markdown("### 🧩 Examples (Click output to load inputs)")
368
+
369
+ # 1. 创建一个 Gallery 用来展示“最终效果图”作为按钮
370
+ example_gallery = gr.Gallery(
371
+ label="Example Results",
372
+ value=[item[0] for item in example_data], # 只展示封面图
373
+ columns=4,
374
+ height=200,
375
+ allow_preview=False, # 禁止预览放大,强制作为按钮
376
+ show_label=False,
377
+ elem_id="example-gallery"
378
+ )
379
+
380
+ # 2. 定义点击事件的回调函数
381
+ def apply_example(evt: gr.SelectData):
382
+ # evt.index 获取用户点击了第几张图
383
+ index = evt.index
384
+ data = example_data[index]
385
+
386
+ # 返回对应的数据,顺序必须和 outputs 列表一致
387
+ return (
388
+ data[1], # input_gallery
389
+ data[2], # prompt
390
+ data[3], # negative_prompt
391
+ data[4], # cfg
392
+ data[5], # seed
393
+ data[6], # width
394
+ data[7], # height
395
+ data[8], # steps
396
+ data[0] # output_image (直接把封面图填回 Output 区域)
397
+ )
398
+
399
+ # 3. 绑定事件
400
+ example_gallery.select(
401
+ fn=apply_example,
402
+ inputs=None,
403
+ outputs=[
404
+ input_gallery,
405
+ prompt_input,
406
+ negative_prompt_input,
407
+ cfg_input,
408
+ seed_input,
409
+ width_input,
410
+ height_input,
411
+ inference_steps_input,
412
+ output_image # 这里关键:把 Input 和 Output 同时填上
413
+ ]
414
  )
415
 
416
  # Event Binding