mv-lab commited on
Commit
d5b9c19
β€’
1 Parent(s): f8653c8

gradio app is ready!

Browse files
Files changed (2) hide show
  1. app.py +20 -26
  2. images/real_fog.png +0 -0
app.py CHANGED
@@ -6,7 +6,7 @@ import os
6
  import torch
7
  import numpy as np
8
  import yaml
9
-
10
  #from gradio_imageslider import ImageSlider
11
 
12
  ## local code
@@ -25,9 +25,12 @@ def dict2namespace(config):
25
  return namespace
26
 
27
 
 
 
 
28
  CONFIG = "configs/eval5d.yml"
29
- LM_MODEL = "models/lm_instructir-7d.pt"
30
- MODEL_NAME = "models/im_instructir-7d.pt"
31
 
32
  # parse config file
33
  with open(os.path.join(CONFIG), "r") as f:
@@ -89,9 +92,9 @@ description = ''' ## [High-Quality Image Restoration Following Human Instruction
89
  Computer Vision Lab, University of Wuerzburg | Sony PlayStation, FTG
90
 
91
  ### TL;DR: quickstart
92
- InstructIR takes as input an image and a human-written instruction for how to improve that image. The neural model performs all-in-one image restoration. InstructIR achieves state-of-the-art results on several restoration tasks including image denoising, deraining, deblurring, dehazing, and (low-light) image enhancement.
93
-
94
- **πŸš€ You can start with the [demo tutorial](https://github.com/mv-lab/InstructIR/blob/main/demo.ipynb)**
95
 
96
  <details>
97
  <summary> <b> Abstract</b> (click me to read)</summary>
@@ -100,23 +103,27 @@ Image restoration is a fundamental problem that involves recovering a high-quali
100
  </p>
101
  </details>
102
 
103
- > Disclaimer: please remember this is not a product, thus, you will notice some limitations.
104
-
105
  **This demo expects an image with some degradations (blur, noise, rain, low-light, haze) and a prompt requesting what should be done.**
106
- Due to the GPU memory limitations, the app might crash if you feed a high-resolution image (2K, 4K).
 
 
 
107
 
108
  <br>
109
  '''
110
- # **Demo notebook can be found [here](https://github.com/NielsRogge/Transformers-Tutorials/blob/master/Swin2SR/Perform_image_super_resolution_with_Swin2SR.ipynb).
111
 
112
  article = "<p style='text-align: center'><a href='https://github.com/mv-lab/InstructIR' target='_blank'>High-Quality Image Restoration Following Human Instructions</a></p>"
113
 
 
114
  examples = [['images/rain-020.png', "I love this photo, could you remove the raindrops? please keep the content intact"],
115
  ['images/gradio_demo_images/city.jpg', "I took this photo during a foggy day, can you improve it?"],
116
  ['images/gradio_demo_images/frog.png', "can you remove the tiny dots in the image? it is very unpleasant"],
117
  ["images/lol_748.png", "my image is too dark, I cannot see anything, can you fix it?"],
118
  ["images/gopro.png", "I took this photo while I was running, can you stabilize the image? it is too blurry"],
119
- ["images/a0010.jpg", "please I want this image for my photo album, can you edit it as a photographer"]]
 
120
 
121
  css = """
122
  .image-frame img, .image-container img {
@@ -132,7 +139,7 @@ demo = gr.Interface(
132
  gr.Image(type="pil", label="Input"),
133
  gr.Text(label="Prompt")
134
  ],
135
- outputs=[gr.Image(type="pil", label="Ouput")], #ImageSlider(position=0.5, type="pil", label="SideBySide")], #gr.Image(type="pil", label="Ouput"), #
136
  title=title,
137
  description=description,
138
  article=article,
@@ -141,17 +148,4 @@ demo = gr.Interface(
141
  )
142
 
143
  if __name__ == "__main__":
144
- demo.launch()
145
-
146
- # with gr.Blocks() as demo:
147
- # with gr.Row(equal_height=True):
148
- # with gr.Column(scale=1):
149
- # input = gr.Image(type="pil", label="Input")
150
- # with gr.Column(scale=1):
151
- # prompt = gr.Text(label="Prompt")
152
- # process_btn = gr.Button("Process")
153
- # with gr.Row(equal_height=True):
154
- # output = gr.Image(type="pil", label="Ouput")
155
- # slider = ImageSlider(position=0.5, type="pil", label="SideBySide")
156
- # process_btn.click(fn=process_img, inputs=[input, prompt], outputs=[output, slider])
157
- # demo.launch(share=True)
 
6
  import torch
7
  import numpy as np
8
  import yaml
9
+ from huggingface_hub import hf_hub_download
10
  #from gradio_imageslider import ImageSlider
11
 
12
  ## local code
 
25
  return namespace
26
 
27
 
28
+ hf_hub_download(repo_id="marcosv/InstructIR", filename="im_instructir-7d.pt", local_dir="./")
29
+ hf_hub_download(repo_id="marcosv/InstructIR", filename="lm_instructir-7d.pt", local_dir="./")
30
+
31
  CONFIG = "configs/eval5d.yml"
32
+ LM_MODEL = "lm_instructir-7d.pt"
33
+ MODEL_NAME = "im_instructir-7d.pt"
34
 
35
  # parse config file
36
  with open(os.path.join(CONFIG), "r") as f:
 
92
  Computer Vision Lab, University of Wuerzburg | Sony PlayStation, FTG
93
 
94
  ### TL;DR: quickstart
95
+ ***InstructIR takes as input an image and a human-written instruction for how to improve that image.***
96
+ The (single) neural model performs all-in-one image restoration. InstructIR achieves state-of-the-art results on several restoration tasks including image denoising, deraining, deblurring, dehazing, and (low-light) image enhancement.
97
+ **πŸš€ You can start with the [demo tutorial.](https://github.com/mv-lab/InstructIR/blob/main/demo.ipynb)** Check [our github](https://github.com/mv-lab/InstructIR) for more information
98
 
99
  <details>
100
  <summary> <b> Abstract</b> (click me to read)</summary>
 
103
  </p>
104
  </details>
105
 
106
+ > **Disclaimer:** please remember this is not a product, thus, you will notice some limitations.
 
107
  **This demo expects an image with some degradations (blur, noise, rain, low-light, haze) and a prompt requesting what should be done.**
108
+ Due to the GPU memory limitations, the app might crash if you feed a high-resolution image (2K, 4K). <br>
109
+ The model was trained using mostly synthetic data, thus it might not work great on real-world complex images.
110
+ However, it works surprisingly well on real-world foggy and low-light images.
111
+ You can also try general image enhancement prompts (e.g., "retouch this image", "enhance the colors") and see how it improves the colors.
112
 
113
  <br>
114
  '''
115
+
116
 
117
  article = "<p style='text-align: center'><a href='https://github.com/mv-lab/InstructIR' target='_blank'>High-Quality Image Restoration Following Human Instructions</a></p>"
118
 
119
+ #### Image,Prompts examples
120
  examples = [['images/rain-020.png', "I love this photo, could you remove the raindrops? please keep the content intact"],
121
  ['images/gradio_demo_images/city.jpg', "I took this photo during a foggy day, can you improve it?"],
122
  ['images/gradio_demo_images/frog.png', "can you remove the tiny dots in the image? it is very unpleasant"],
123
  ["images/lol_748.png", "my image is too dark, I cannot see anything, can you fix it?"],
124
  ["images/gopro.png", "I took this photo while I was running, can you stabilize the image? it is too blurry"],
125
+ ["images/a0010.jpg", "please I want this image for my photo album, can you edit it as a photographer"],
126
+ ["images/real_fog.png", "How can I remove the fog and mist from this photo?"]]
127
 
128
  css = """
129
  .image-frame img, .image-container img {
 
139
  gr.Image(type="pil", label="Input"),
140
  gr.Text(label="Prompt")
141
  ],
142
+ outputs=[gr.Image(type="pil", label="Ouput")],
143
  title=title,
144
  description=description,
145
  article=article,
 
148
  )
149
 
150
  if __name__ == "__main__":
151
+ demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
images/real_fog.png ADDED