Update app.py
Browse files
app.py
CHANGED
|
@@ -73,44 +73,40 @@ def postprocess_image(tensor):
|
|
| 73 |
image = np.transpose(image, (1, 2, 0))
|
| 74 |
return (image * 255).astype(np.uint8)
|
| 75 |
|
| 76 |
-
def deblur_image(
|
| 77 |
-
if
|
| 78 |
return None
|
| 79 |
|
| 80 |
try:
|
| 81 |
-
#
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
# Save original size
|
| 86 |
original_size = input_image.size
|
| 87 |
-
|
| 88 |
# Preprocess
|
| 89 |
input_tensor = transform(input_image).unsqueeze(0).to(device)
|
| 90 |
-
|
| 91 |
# Inference
|
| 92 |
with torch.no_grad():
|
| 93 |
output_tensor = model(input_tensor)
|
| 94 |
-
|
| 95 |
# Postprocess
|
| 96 |
output_image = postprocess_image(output_tensor[0])
|
| 97 |
-
|
| 98 |
# Resize back to original size
|
| 99 |
output_image = Image.fromarray(output_image).resize(original_size)
|
| 100 |
return np.array(output_image)
|
| 101 |
-
|
| 102 |
except Exception as e:
|
| 103 |
print(f"Error processing image: {e}")
|
| 104 |
return None
|
| 105 |
|
| 106 |
-
# ✅ Custom CSS
|
| 107 |
custom_css = """
|
| 108 |
-
/* Hide
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
height: 0px !important;
|
| 112 |
-
width: 0px !important;
|
| 113 |
-
position: absolute !important;
|
| 114 |
}
|
| 115 |
|
| 116 |
/* Non-draggable images */
|
|
@@ -120,7 +116,7 @@ img {
|
|
| 120 |
user-select: none !important;
|
| 121 |
}
|
| 122 |
|
| 123 |
-
/*
|
| 124 |
body, .gradio-container {
|
| 125 |
background-color: #000000 !important;
|
| 126 |
color: white !important;
|
|
@@ -141,15 +137,12 @@ body, .gradio-container {
|
|
| 141 |
color: white !important;
|
| 142 |
border: 1px solid #333333 !important;
|
| 143 |
}
|
| 144 |
-
footer, header, .gradio-footer, .gradio-header {
|
| 145 |
-
display: none !important;
|
| 146 |
-
}
|
| 147 |
"""
|
| 148 |
|
| 149 |
-
# ✅ Gradio interface
|
| 150 |
demo = gr.Interface(
|
| 151 |
fn=deblur_image,
|
| 152 |
-
inputs=gr.
|
| 153 |
outputs=gr.Image(type="numpy", label="Deblurred Result"),
|
| 154 |
title="Image Deblurring",
|
| 155 |
description="Upload a blurry image and get it deblurred using deep learning.",
|
|
|
|
| 73 |
image = np.transpose(image, (1, 2, 0))
|
| 74 |
return (image * 255).astype(np.uint8)
|
| 75 |
|
| 76 |
+
def deblur_image(file):
|
| 77 |
+
if file is None:
|
| 78 |
return None
|
| 79 |
|
| 80 |
try:
|
| 81 |
+
# Load the image from the uploaded file
|
| 82 |
+
input_image = Image.open(file.name).convert("RGB")
|
| 83 |
+
|
|
|
|
| 84 |
# Save original size
|
| 85 |
original_size = input_image.size
|
| 86 |
+
|
| 87 |
# Preprocess
|
| 88 |
input_tensor = transform(input_image).unsqueeze(0).to(device)
|
| 89 |
+
|
| 90 |
# Inference
|
| 91 |
with torch.no_grad():
|
| 92 |
output_tensor = model(input_tensor)
|
| 93 |
+
|
| 94 |
# Postprocess
|
| 95 |
output_image = postprocess_image(output_tensor[0])
|
| 96 |
+
|
| 97 |
# Resize back to original size
|
| 98 |
output_image = Image.fromarray(output_image).resize(original_size)
|
| 99 |
return np.array(output_image)
|
| 100 |
+
|
| 101 |
except Exception as e:
|
| 102 |
print(f"Error processing image: {e}")
|
| 103 |
return None
|
| 104 |
|
| 105 |
+
# ✅ Custom CSS for styling
|
| 106 |
custom_css = """
|
| 107 |
+
/* Hide Gradio's footer and header */
|
| 108 |
+
footer, header, .gradio-footer, .gradio-header {
|
| 109 |
+
display: none !important;
|
|
|
|
|
|
|
|
|
|
| 110 |
}
|
| 111 |
|
| 112 |
/* Non-draggable images */
|
|
|
|
| 116 |
user-select: none !important;
|
| 117 |
}
|
| 118 |
|
| 119 |
+
/* Styling adjustments */
|
| 120 |
body, .gradio-container {
|
| 121 |
background-color: #000000 !important;
|
| 122 |
color: white !important;
|
|
|
|
| 137 |
color: white !important;
|
| 138 |
border: 1px solid #333333 !important;
|
| 139 |
}
|
|
|
|
|
|
|
|
|
|
| 140 |
"""
|
| 141 |
|
| 142 |
+
# ✅ Gradio interface using gr.File (no preview) with custom CSS
|
| 143 |
demo = gr.Interface(
|
| 144 |
fn=deblur_image,
|
| 145 |
+
inputs=gr.File(label="Upload Blurry Image (No Preview)", type="file"),
|
| 146 |
outputs=gr.Image(type="numpy", label="Deblurred Result"),
|
| 147 |
title="Image Deblurring",
|
| 148 |
description="Upload a blurry image and get it deblurred using deep learning.",
|