Fabrice-TIERCELIN commited on
Commit
79919d7
1 Parent(s): 3142592

Prompt and additional prompt

Browse files
Files changed (1) hide show
  1. gradio_demo.py +36 -16
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,20 @@ 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 +421,10 @@ 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 +465,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')
@@ -487,6 +504,9 @@ title_html = """
487
  claim_md = """
488
  ## **Piracy**
489
  The images are not stored but the logs are saved during a month.
 
 
 
490
  ## **Terms of use**
491
  By using this service, users are required to agree to the following terms: The service is a research preview intended for non-commercial use only. It only provides limited safety measures and may generate offensive content. It must not be used for any illegal, harmful, violent, racist, or sexual purposes. The service may collect user dialogue data for future research. Please submit a feedback to us if you get any inappropriate answer! We will collect those to keep improving our models. For an optimal experience, please use desktop computers for this demo, as mobile devices may compromise its quality.
492
  ## **License**
@@ -507,15 +527,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 +544,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, '
@@ -635,8 +655,8 @@ with gr.Blocks(title="SUPIR") as interface:
635
  [
636
  "./Examples/Example1.png",
637
  None,
638
- None,
639
- "Group of people, walking, happy, in the street, photorealistic, 8k, extremely detailled, Cinematic, High Contrast, highly detailed, taken using a Canon EOS R camera, hyper detailed photo - realistic maximum detail, 32k, Color Grading, ultra HD, extreme meticulous detailing, skin pore detailing, hyper sharpness, perfect without deformations.",
640
  "painting, oil painting, illustration, drawing, art, sketch, anime, cartoon, CG Style, 3D render, unreal engine, blurring, bokeh, ugly, dirty, messy, worst quality, low quality, frames, watermark, signature, jpeg artifacts, deformed, lowres, over-smooth",
641
  1,
642
  1024,
@@ -665,8 +685,8 @@ with gr.Blocks(title="SUPIR") as interface:
665
  [
666
  "./Examples/Example2.jpeg",
667
  None,
668
- None,
669
- "The head of a tabby cat, in a house, photorealistic, 8k, extremely detailled, Cinematic, High Contrast, highly detailed, taken using a Canon EOS R camera, hyper detailed photo - realistic maximum detail, 32k, Color Grading, ultra HD, extreme meticulous detailing, skin pore detailing, hyper sharpness, perfect without deformations.",
670
  "painting, oil painting, illustration, drawing, art, sketch, anime, cartoon, CG Style, 3D render, unreal engine, blurring, bokeh, ugly, dirty, messy, worst quality, low quality, frames, watermark, signature, jpeg artifacts, deformed, lowres, over-smooth",
671
  1,
672
  1024,
 
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
323
 
324
  if output_format == "input":
325
  if noisy_image is None:
 
327
  else:
328
  output_format = noisy_image.format
329
 
330
+ if prompt is None:
331
+ prompt = ""
332
+
333
+ if a_prompt is None:
334
+ a_prompt = ""
335
+
336
+ if n_prompt is None:
337
+ n_prompt = ""
338
+
339
+ if prompt != "" and a_prompt != "":
340
+ a_prompt = prompt + ", " + a_prompt
341
+ else:
342
+ a_prompt = prompt + a_prompt
343
+ print("Final prompt: " + str(a_prompt))
344
  input_image = noisy_image if denoise_image is None else denoise_image
345
  if 1 < downscale:
346
  input_height, input_width, input_channel = np.array(input_image).shape
 
421
  print(information)
422
 
423
  # Only one image can be shown in the slider
424
+ return [noisy_image] + [results[0]],
425
+ gr.update(format = output_format, value = [noisy_image] + results),
426
+ gr.update(value = information, visible = True),
427
+ event_id
428
 
429
  def load_and_reset(param_setting):
430
  print('load_and_reset ==>>')
 
465
  print('log_information')
466
  if result_gallery is not None:
467
  for i, result in enumerate(result_gallery):
468
+ print(result[0])
469
 
470
  def on_select_result(result_gallery, evt: gr.SelectData):
471
  print('on_select_result')
 
504
  claim_md = """
505
  ## **Piracy**
506
  The images are not stored but the logs are saved during a month.
507
+ ## **How to get SUPIR**
508
+ You can get SUPIR on HuggingFace by [https://huggingface.co/spaces/Fabrice-TIERCELIN/SUPIR?duplicate=true](duplicating this space) and set GPU.
509
+ You can also install SUPIR on your computer following [https://huggingface.co/blog/MonsterMMORPG/supir-sota-image-upscale-better-than-magnific-ai](this tutorial).
510
  ## **Terms of use**
511
  By using this service, users are required to agree to the following terms: The service is a research preview intended for non-commercial use only. It only provides limited safety measures and may generate offensive content. It must not be used for any illegal, harmful, violent, racist, or sexual purposes. The service may collect user dialogue data for future research. Please submit a feedback to us if you get any inappropriate answer! We will collect those to keep improving our models. For an optimal experience, please use desktop computers for this demo, as mobile devices may compromise its quality.
512
  ## **License**
 
527
 
528
  input_image = gr.Image(label="Input", show_label=True, type="numpy", height=600, elem_id="image-input")
529
  with gr.Group():
530
+ prompt = gr.Textbox(label="Image description", info="Help the AI understand what the image represents; describe as much as possible; I advise you to write in English as other languages may not be handled", value="", placeholder="A person, walking, in a town, Summer, photorealistic", lines=3)
531
+ 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.")
 
 
 
 
 
 
 
532
  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)
533
  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)
534
 
 
544
  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)
545
 
546
  with gr.Accordion("Advanced options", open=False):
547
+ a_prompt = gr.Textbox(label="Additional image description",
548
+ info="Completes the main image description",
549
+ value='Cinematic, High Contrast, highly detailed, taken using a Canon EOS R '
550
+ 'camera, hyper detailed photo - realistic maximum detail, 32k, Color '
551
+ 'Grading, ultra HD, extreme meticulous detailing, skin pore detailing, '
552
+ 'hyper sharpness, perfect without deformations.',
553
+ lines=3)
554
  n_prompt = gr.Textbox(label="Anti image description",
555
  info="Disambiguate by listing what the image does NOT represent",
556
  value='painting, oil painting, illustration, drawing, art, sketch, anime, '
 
655
  [
656
  "./Examples/Example1.png",
657
  None,
658
+ "Group of people, walking, happy, in the street, photorealistic, 8k, extremely detailled",
659
+ "Cinematic, High Contrast, highly detailed, taken using a Canon EOS R camera, hyper detailed photo - realistic maximum detail, 32k, Color Grading, ultra HD, extreme meticulous detailing, skin pore detailing, hyper sharpness, perfect without deformations.",
660
  "painting, oil painting, illustration, drawing, art, sketch, anime, cartoon, CG Style, 3D render, unreal engine, blurring, bokeh, ugly, dirty, messy, worst quality, low quality, frames, watermark, signature, jpeg artifacts, deformed, lowres, over-smooth",
661
  1,
662
  1024,
 
685
  [
686
  "./Examples/Example2.jpeg",
687
  None,
688
+ "The head of a tabby cat, in a house, photorealistic, 8k, extremely detailled",
689
+ "Cinematic, High Contrast, highly detailed, taken using a Canon EOS R camera, hyper detailed photo - realistic maximum detail, 32k, Color Grading, ultra HD, extreme meticulous detailing, skin pore detailing, hyper sharpness, perfect without deformations.",
690
  "painting, oil painting, illustration, drawing, art, sketch, anime, cartoon, CG Style, 3D render, unreal engine, blurring, bokeh, ugly, dirty, messy, worst quality, low quality, frames, watermark, signature, jpeg artifacts, deformed, lowres, over-smooth",
691
  1,
692
  1024,