Fabrice-TIERCELIN commited on
Commit
d43450e
·
verified ·
1 Parent(s): 64f7080

Invite to fill the prompt

Browse files
Files changed (1) hide show
  1. gradio_demo.py +24 -13
gradio_demo.py CHANGED
@@ -319,7 +319,7 @@ def restore(
319
 
320
  if torch.cuda.device_count() == 0:
321
  gr.Warning('Set this space to GPU config to make it work.')
322
- return None, None, None, None
323
 
324
  if output_format == "input":
325
  if noisy_image is None:
@@ -327,6 +327,11 @@ def restore(
327
  else:
328
  output_format = noisy_image.format
329
 
 
 
 
 
 
330
  input_image = noisy_image if denoise_image is None else denoise_image
331
  if 1 < downscale:
332
  input_height, input_width, input_channel = np.array(input_image).shape
@@ -407,7 +412,11 @@ def restore(
407
  print(information)
408
 
409
  # Only one image can be shown in the slider
410
- return [noisy_image] + [results[0]], gr.update(format = output_format, value = [noisy_image] + results), gr.update(value = information, visible = True), event_id
 
 
 
 
411
 
412
  def load_and_reset(param_setting):
413
  print('load_and_reset ==>>')
@@ -448,7 +457,7 @@ def log_information(result_gallery):
448
  print('log_information')
449
  if result_gallery is not None:
450
  for i, result in enumerate(result_gallery):
451
- print(result[0][0])
452
 
453
  def on_select_result(result_gallery, evt: gr.SelectData):
454
  print('on_select_result')
@@ -507,15 +516,8 @@ with gr.Blocks(title="SUPIR") as interface:
507
 
508
  input_image = gr.Image(label="Input", show_label=True, type="numpy", height=600, elem_id="image-input")
509
  with gr.Group():
510
- prompt = gr.Textbox(label="Image description for LlaVa", value="", placeholder="A person, walking, in a town, Summer, photorealistic", lines=3, visible=False)
511
- a_prompt = gr.Textbox(label="Image description",
512
- info="Help the AI understand what the image represents; describe as much as possible",
513
- value='Cinematic, High Contrast, highly detailed, taken using a Canon EOS R '
514
- 'camera, hyper detailed photo - realistic maximum detail, 32k, Color '
515
- 'Grading, ultra HD, extreme meticulous detailing, skin pore detailing, '
516
- 'hyper sharpness, perfect without deformations.',
517
- lines=3)
518
- a_prompt_hint = gr.HTML("You can use a <a href='"'https://huggingface.co/spaces/MaziyarPanahi/llava-llama-3-8b'"'>LlaVa space</a> to auto-generate the description of your image.")
519
  upscale = gr.Radio([["x1", 1], ["x2", 2], ["x3", 3], ["x4", 4], ["x5", 5], ["x6", 6], ["x7", 7], ["x8", 8]], label="Upscale factor", info="Resolution x1 to x8", value=2, interactive=True)
520
  output_format = gr.Radio([["*.png", "png"], ["*.webp", "webp"], ["*.jpeg", "jpeg"], ["*.gif", "gif"], ["*.bmp", "bmp"]], label="Image format for result", info="File extention", value="png", interactive=True)
521
 
@@ -531,6 +533,13 @@ with gr.Blocks(title="SUPIR") as interface:
531
  qs = gr.Textbox(label="Question", info="Ask LLaVa what description you want", value="Describe the image and its style in a very detailed manner. The image is a realistic photography, not an art painting.", lines=3)
532
 
533
  with gr.Accordion("Advanced options", open=False):
 
 
 
 
 
 
 
534
  n_prompt = gr.Textbox(label="Anti image description",
535
  info="Disambiguate by listing what the image does NOT represent",
536
  value='painting, oil painting, illustration, drawing, art, sketch, anime, '
@@ -586,6 +595,7 @@ with gr.Blocks(title="SUPIR") as interface:
586
  restore_information = gr.HTML(value="Restart the process to get another result.", visible=False)
587
  result_slider = ImageSlider(label='Output', show_label=True, elem_id="slider1")
588
  result_gallery = gr.Gallery(label='Output', show_label=True, elem_id="gallery1")
 
589
 
590
  with gr.Accordion("Feedback", open=True, visible=False):
591
  fb_score = gr.Slider(label="Feedback Score", minimum=1, maximum=5, value=3, step=1, interactive=True)
@@ -629,7 +639,8 @@ with gr.Blocks(title="SUPIR") as interface:
629
  result_slider,
630
  result_gallery,
631
  restore_information,
632
- event_id
 
633
  ],
634
  examples = [
635
  [
 
319
 
320
  if torch.cuda.device_count() == 0:
321
  gr.Warning('Set this space to GPU config to make it work.')
322
+ return [noisy_image] * 2, [noisy_image] * 2, None, None, noisy_image
323
 
324
  if output_format == "input":
325
  if noisy_image is None:
 
327
  else:
328
  output_format = noisy_image.format
329
 
330
+ if prompt != "" and a_prompt != "":
331
+ a_prompt = prompt + ", " + a_prompt
332
+ else:
333
+ a_prompt = prompt + a_prompt
334
+ print("Final prompt: " + str(a_prompt))
335
  input_image = noisy_image if denoise_image is None else denoise_image
336
  if 1 < downscale:
337
  input_height, input_width, input_channel = np.array(input_image).shape
 
412
  print(information)
413
 
414
  # Only one image can be shown in the slider
415
+ return [noisy_image] + [results[0]],
416
+ gr.update(format = output_format, value = [noisy_image] + results),
417
+ gr.update(value = information, visible = True),
418
+ event_id,
419
+ results[0]
420
 
421
  def load_and_reset(param_setting):
422
  print('load_and_reset ==>>')
 
457
  print('log_information')
458
  if result_gallery is not None:
459
  for i, result in enumerate(result_gallery):
460
+ print(result[0])
461
 
462
  def on_select_result(result_gallery, evt: gr.SelectData):
463
  print('on_select_result')
 
516
 
517
  input_image = gr.Image(label="Input", show_label=True, type="numpy", height=600, elem_id="image-input")
518
  with gr.Group():
519
+ prompt = gr.Textbox(label="Image description", info="Help the AI understand what the image represents; describe as much as possible", value="", placeholder="A person, walking, in a town, Summer, photorealistic", lines=3)
520
+ prompt_hint = gr.HTML("You can use a <a href='"'https://huggingface.co/spaces/MaziyarPanahi/llava-llama-3-8b'"'>LlaVa space</a> to auto-generate the description of your image.")
 
 
 
 
 
 
 
521
  upscale = gr.Radio([["x1", 1], ["x2", 2], ["x3", 3], ["x4", 4], ["x5", 5], ["x6", 6], ["x7", 7], ["x8", 8]], label="Upscale factor", info="Resolution x1 to x8", value=2, interactive=True)
522
  output_format = gr.Radio([["*.png", "png"], ["*.webp", "webp"], ["*.jpeg", "jpeg"], ["*.gif", "gif"], ["*.bmp", "bmp"]], label="Image format for result", info="File extention", value="png", interactive=True)
523
 
 
533
  qs = gr.Textbox(label="Question", info="Ask LLaVa what description you want", value="Describe the image and its style in a very detailed manner. The image is a realistic photography, not an art painting.", lines=3)
534
 
535
  with gr.Accordion("Advanced options", open=False):
536
+ a_prompt = gr.Textbox(label="Additional image description",
537
+ info="Completes the main image description",
538
+ value='Cinematic, High Contrast, highly detailed, taken using a Canon EOS R '
539
+ 'camera, hyper detailed photo - realistic maximum detail, 32k, Color '
540
+ 'Grading, ultra HD, extreme meticulous detailing, skin pore detailing, '
541
+ 'hyper sharpness, perfect without deformations.',
542
+ lines=3)
543
  n_prompt = gr.Textbox(label="Anti image description",
544
  info="Disambiguate by listing what the image does NOT represent",
545
  value='painting, oil painting, illustration, drawing, art, sketch, anime, '
 
595
  restore_information = gr.HTML(value="Restart the process to get another result.", visible=False)
596
  result_slider = ImageSlider(label='Output', show_label=True, elem_id="slider1")
597
  result_gallery = gr.Gallery(label='Output', show_label=True, elem_id="gallery1")
598
+ hidden_result_1 = gr.Image(type="filepath")
599
 
600
  with gr.Accordion("Feedback", open=True, visible=False):
601
  fb_score = gr.Slider(label="Feedback Score", minimum=1, maximum=5, value=3, step=1, interactive=True)
 
639
  result_slider,
640
  result_gallery,
641
  restore_information,
642
+ event_id,
643
+ hidden_result_1
644
  ],
645
  examples = [
646
  [