JasperHaozhe commited on
Commit
a0709c9
·
verified ·
1 Parent(s): 76526f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -45
app.py CHANGED
@@ -289,30 +289,34 @@ def create_instruction(prompt, task_type):
289
  raise ValueError(f"Unknown task type: {task_type}")
290
 
291
  def update_ui_for_task(task_type):
292
- """Update image component visibility and labels based on selected task type."""
293
  if task_type == "Pointwise - Image Editing":
294
  return (
295
  gr.update(visible=True, label="Source Image"),
296
  gr.update(visible=True, label="Edited Image"),
297
  gr.update(visible=False, label="Image B", value=None),
 
298
  )
299
  elif task_type == "Pointwise - T2I Generation":
300
  return (
301
  gr.update(visible=True, label="Generated Image"),
302
  gr.update(visible=False, label="(unused)", value=None),
303
  gr.update(visible=False, label="(unused)", value=None),
 
304
  )
305
  elif task_type == "Pairwise - Image Editing":
306
  return (
307
  gr.update(visible=True, label="Source Image"),
308
  gr.update(visible=True, label="Image A"),
309
  gr.update(visible=True, label="Image B"),
 
310
  )
311
  elif task_type == "Pairwise - T2I Generation":
312
  return (
313
  gr.update(visible=True, label="Image A"),
314
  gr.update(visible=True, label="Image B"),
315
  gr.update(visible=False, label="(unused)", value=None),
 
316
  )
317
 
318
  @spaces.GPU
@@ -383,72 +387,93 @@ def model_inference(task_type, instruction_text, image1, image2, image3):
383
  # Gradio UI
384
  # ============================================================
385
 
386
- with gr.Blocks() as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
387
  gr.HTML(html_header)
388
 
389
- with gr.Row():
390
- task_selector = gr.Radio(
391
- choices=TASK_CHOICES,
392
- value="Pointwise - Image Editing",
393
- label="Task Type",
394
- info="Select the evaluation task",
395
- )
 
 
 
 
 
396
 
397
- with gr.Row():
398
- with gr.Column(scale=1):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
399
  instruction = gr.Textbox(
400
- label="User Instruction",
401
- lines=5,
402
- placeholder="Enter the user instruction / prompt here..."
403
  )
404
  submit_btn = gr.Button("Evaluate", variant="primary")
405
 
406
- with gr.Column(scale=1):
407
- image1 = gr.Image(
408
- label="Source Image",
409
- type="filepath",
410
- sources=["upload", "clipboard"],
 
411
  )
412
 
 
413
  with gr.Column(scale=1):
414
- image2 = gr.Image(
415
- label="Edited Image",
416
- type="filepath",
417
- sources=["upload", "clipboard"],
418
- )
419
 
420
- with gr.Column(scale=1):
421
- image3 = gr.Image(
422
- label="Image B",
423
- type="filepath",
424
- sources=["upload", "clipboard"],
425
- visible=False,
426
- )
427
-
428
- output = gr.Textbox(label="Evaluation Result", lines=25)
429
-
430
- # Wire task selector to update image visibility/labels
431
  task_selector.change(
432
  fn=update_ui_for_task,
433
  inputs=[task_selector],
434
- outputs=[image1, image2, image3],
435
  )
436
 
437
- # Wire evaluate button
438
  submit_btn.click(
439
  fn=model_inference,
440
  inputs=[task_selector, instruction, image1, image2, image3],
441
  outputs=output,
442
  )
443
 
444
- # Examples for different tasks
445
- gr.Examples(
446
- examples=[
447
- ["Pointwise - Image Editing", "Remove the arrows from the blue sign and add the text of Detour ahead, no right turns.", "example_images/0016cb70b187efe39969766dc4b3f9ed_b63ed6db519f685c33b860b511879cfe2fa7351059a17ebe5eafa83213e222fb_13_source.png", "example_images/0016cb70b187efe39969766dc4b3f9ed_b63ed6db519f685c33b860b511879cfe2fa7351059a17ebe5eafa83213e222fb_13_ovis_u1_Image A.png", None],
448
- ],
449
- inputs=[task_selector, instruction, image1, image2, image3],
450
- )
451
-
452
  gr.Markdown(tos_markdown)
453
  gr.Markdown(learn_more_markdown)
454
  gr.Markdown(bibtext)
 
289
  raise ValueError(f"Unknown task type: {task_type}")
290
 
291
  def update_ui_for_task(task_type):
292
+ """Update image component visibility/labels and instruction label based on selected task type."""
293
  if task_type == "Pointwise - Image Editing":
294
  return (
295
  gr.update(visible=True, label="Source Image"),
296
  gr.update(visible=True, label="Edited Image"),
297
  gr.update(visible=False, label="Image B", value=None),
298
+ gr.update(label="Editing Instruction", placeholder="Describe the edit that was applied to the source image…"),
299
  )
300
  elif task_type == "Pointwise - T2I Generation":
301
  return (
302
  gr.update(visible=True, label="Generated Image"),
303
  gr.update(visible=False, label="(unused)", value=None),
304
  gr.update(visible=False, label="(unused)", value=None),
305
+ gr.update(label="Text-to-Image Prompt", placeholder="Enter the text-to-image generation prompt…"),
306
  )
307
  elif task_type == "Pairwise - Image Editing":
308
  return (
309
  gr.update(visible=True, label="Source Image"),
310
  gr.update(visible=True, label="Image A"),
311
  gr.update(visible=True, label="Image B"),
312
+ gr.update(label="Editing Instruction", placeholder="Describe the edit that was applied to the source image…"),
313
  )
314
  elif task_type == "Pairwise - T2I Generation":
315
  return (
316
  gr.update(visible=True, label="Image A"),
317
  gr.update(visible=True, label="Image B"),
318
  gr.update(visible=False, label="(unused)", value=None),
319
+ gr.update(label="Text-to-Image Prompt", placeholder="Enter the text-to-image generation prompt…"),
320
  )
321
 
322
  @spaces.GPU
 
387
  # Gradio UI
388
  # ============================================================
389
 
390
+ OVERVIEW_MD = """
391
+ ### 📋 Task Overview
392
+
393
+ This demo supports **four evaluation tasks**. Select one to get started:
394
+
395
+ | Task | Description |
396
+ |------|-------------|
397
+ | **Pointwise – Image Editing** | Rate a single edited image against its source image and the editing instruction. Produces per-aspect scores and a refined request. |
398
+ | **Pointwise – T2I Generation** | Rate a single generated image against a text-to-image prompt. Produces per-aspect scores and a refined prompt. |
399
+ | **Pairwise – Image Editing** | Compare two edited images (A vs B) given a source image and editing instruction. Determines which edit is better per aspect. |
400
+ | **Pairwise – T2I Generation** | Compare two generated images (A vs B) given a text-to-image prompt. Determines which generation is better per aspect. |
401
+ """
402
+
403
+ with gr.Blocks(css="""
404
+ #input-panel { max-height: 85vh; overflow-y: auto; padding-right: 8px; }
405
+ """) as demo:
406
  gr.HTML(html_header)
407
 
408
+ # ---- Overview ----
409
+ gr.Markdown(OVERVIEW_MD)
410
+
411
+ with gr.Row(equal_height=False):
412
+ # ============ LEFT COLUMN – all inputs (scrollable) ============
413
+ with gr.Column(scale=1, elem_id="input-panel"):
414
+ task_selector = gr.Radio(
415
+ choices=TASK_CHOICES,
416
+ value="Pointwise - Image Editing",
417
+ label="Task Type",
418
+ info="Select the evaluation task",
419
+ )
420
 
421
+ # ---- Image upload row ----
422
+ with gr.Row():
423
+ with gr.Column(scale=1, min_width=160):
424
+ image1 = gr.Image(
425
+ label="Source Image",
426
+ type="filepath",
427
+ sources=["upload", "clipboard"],
428
+ )
429
+ with gr.Column(scale=1, min_width=160):
430
+ image2 = gr.Image(
431
+ label="Edited Image",
432
+ type="filepath",
433
+ sources=["upload", "clipboard"],
434
+ )
435
+ with gr.Column(scale=1, min_width=160):
436
+ image3 = gr.Image(
437
+ label="Image B",
438
+ type="filepath",
439
+ sources=["upload", "clipboard"],
440
+ visible=False,
441
+ )
442
+
443
+ # ---- Instruction + Evaluate ----
444
  instruction = gr.Textbox(
445
+ label="Editing Instruction",
446
+ lines=3,
447
+ placeholder="Describe the edit that was applied to the source image…",
448
  )
449
  submit_btn = gr.Button("Evaluate", variant="primary")
450
 
451
+ # ---- Examples ----
452
+ gr.Examples(
453
+ examples=[
454
+ ["Pointwise - Image Editing", "Remove the arrows from the blue sign and add the text of Detour ahead, no right turns.", "example_images/0016cb70b187efe39969766dc4b3f9ed_b63ed6db519f685c33b860b511879cfe2fa7351059a17ebe5eafa83213e222fb_13_source.png", "example_images/0016cb70b187efe39969766dc4b3f9ed_b63ed6db519f685c33b860b511879cfe2fa7351059a17ebe5eafa83213e222fb_13_ovis_u1_Image A.png", None],
455
+ ],
456
+ inputs=[task_selector, instruction, image1, image2, image3],
457
  )
458
 
459
+ # ============ RIGHT COLUMN – evaluation output ============
460
  with gr.Column(scale=1):
461
+ output = gr.Textbox(label="Evaluation Result", lines=30)
 
 
 
 
462
 
463
+ # ---- Wire task selector to update image visibility/labels + instruction label ----
 
 
 
 
 
 
 
 
 
 
464
  task_selector.change(
465
  fn=update_ui_for_task,
466
  inputs=[task_selector],
467
+ outputs=[image1, image2, image3, instruction],
468
  )
469
 
470
+ # ---- Wire evaluate button ----
471
  submit_btn.click(
472
  fn=model_inference,
473
  inputs=[task_selector, instruction, image1, image2, image3],
474
  outputs=output,
475
  )
476
 
 
 
 
 
 
 
 
 
477
  gr.Markdown(tos_markdown)
478
  gr.Markdown(learn_more_markdown)
479
  gr.Markdown(bibtext)