Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from pyrolens_deployment.gradio_app.dehazing_gen import CycleGenerator
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
from torchvision import transforms
|
| 7 |
+
|
| 8 |
+
import gradio as gr
|
| 9 |
+
|
| 10 |
+
gan = CycleGenerator(num_residuals=6)
|
| 11 |
+
gan.load_state_dict(torch.load("genC.pth.tar", map_location=torch.device('cpu')))
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def dehaze(img):
|
| 15 |
+
gan_transforms = transforms.Compose([
|
| 16 |
+
transforms.Resize((800, 800)),
|
| 17 |
+
transforms.ToTensor()
|
| 18 |
+
])
|
| 19 |
+
dehazed_output = gan(gan_transforms(img))
|
| 20 |
+
out_arr = dehazed_output.detach().cpu()
|
| 21 |
+
return np.array(out_arr).transpose(1, 2, 0)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
sample_images = [
|
| 25 |
+
("Haze", "gradio_check1.png"),
|
| 26 |
+
("Haze", "gradio_check10.png"),
|
| 27 |
+
("Haze", "gradio_check13.png"),
|
| 28 |
+
]
|
| 29 |
+
|
| 30 |
+
with gr.Blocks() as demo:
|
| 31 |
+
gr.Markdown("# ClarityGAN")
|
| 32 |
+
gr.Markdown("## Image Dehazing using CycleGANs")
|
| 33 |
+
with gr.Row():
|
| 34 |
+
with gr.Column():
|
| 35 |
+
input_image = gr.Image(label="Input Image", type="pil")
|
| 36 |
+
with gr.Row():
|
| 37 |
+
dehaze_button = gr.Button("Dehaze")
|
| 38 |
+
with gr.Column():
|
| 39 |
+
output_image = gr.Image(label="Output Image", type="pil")
|
| 40 |
+
for name, file in sample_images:
|
| 41 |
+
gr.Button(name).click(dehaze, inputs=input_image, outputs=output_image)
|
| 42 |
+
|
| 43 |
+
demo.launch()
|