Update app.py
Browse files
app.py
CHANGED
|
@@ -6,11 +6,11 @@ from PIL import Image
|
|
| 6 |
import numpy as np
|
| 7 |
import os
|
| 8 |
|
| 9 |
-
#
|
| 10 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 11 |
print(f"Using device: {device}")
|
| 12 |
|
| 13 |
-
#
|
| 14 |
class DeblurNet(nn.Module):
|
| 15 |
def __init__(self):
|
| 16 |
super(DeblurNet, self).__init__()
|
|
@@ -53,7 +53,7 @@ class DeblurNet(nn.Module):
|
|
| 53 |
x = self.final_conv(x)
|
| 54 |
return torch.tanh(x)
|
| 55 |
|
| 56 |
-
#
|
| 57 |
model = DeblurNet().to(device)
|
| 58 |
model_path = os.path.join('model', 'best_deblur_model.pth')
|
| 59 |
|
|
@@ -65,7 +65,7 @@ if os.path.exists(model_path):
|
|
| 65 |
else:
|
| 66 |
print(f"Model file not found at {model_path}. Please check the path.")
|
| 67 |
|
| 68 |
-
#
|
| 69 |
transform = transforms.Compose([
|
| 70 |
transforms.Resize((256, 256)),
|
| 71 |
transforms.ToTensor(),
|
|
@@ -111,18 +111,10 @@ def deblur_image(filepath):
|
|
| 111 |
print(f"Error processing image: {e}")
|
| 112 |
return None
|
| 113 |
|
| 114 |
-
#
|
| 115 |
custom_css = """
|
| 116 |
-
/* Hide
|
| 117 |
-
|
| 118 |
-
display: none !important;
|
| 119 |
-
}
|
| 120 |
-
/* Hide share button */
|
| 121 |
-
.share-wrap, .gr-share-btn {
|
| 122 |
-
display: none !important;
|
| 123 |
-
}
|
| 124 |
-
/* Hide fullscreen icon */
|
| 125 |
-
.gr-button[title="Fullscreen"] {
|
| 126 |
display: none !important;
|
| 127 |
}
|
| 128 |
/* Non-draggable images */
|
|
@@ -154,7 +146,7 @@ body, .gradio-container {
|
|
| 154 |
}
|
| 155 |
"""
|
| 156 |
|
| 157 |
-
#
|
| 158 |
demo = gr.Interface(
|
| 159 |
fn=deblur_image,
|
| 160 |
inputs=gr.File(label="Input", type="filepath"),
|
|
@@ -164,6 +156,6 @@ demo = gr.Interface(
|
|
| 164 |
css=custom_css
|
| 165 |
)
|
| 166 |
|
| 167 |
-
#
|
| 168 |
if __name__ == "__main__":
|
| 169 |
demo.launch()
|
|
|
|
| 6 |
import numpy as np
|
| 7 |
import os
|
| 8 |
|
| 9 |
+
# Check if CUDA is available
|
| 10 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 11 |
print(f"Using device: {device}")
|
| 12 |
|
| 13 |
+
# Model definition
|
| 14 |
class DeblurNet(nn.Module):
|
| 15 |
def __init__(self):
|
| 16 |
super(DeblurNet, self).__init__()
|
|
|
|
| 53 |
x = self.final_conv(x)
|
| 54 |
return torch.tanh(x)
|
| 55 |
|
| 56 |
+
# Load model
|
| 57 |
model = DeblurNet().to(device)
|
| 58 |
model_path = os.path.join('model', 'best_deblur_model.pth')
|
| 59 |
|
|
|
|
| 65 |
else:
|
| 66 |
print(f"Model file not found at {model_path}. Please check the path.")
|
| 67 |
|
| 68 |
+
# Image processing functions
|
| 69 |
transform = transforms.Compose([
|
| 70 |
transforms.Resize((256, 256)),
|
| 71 |
transforms.ToTensor(),
|
|
|
|
| 111 |
print(f"Error processing image: {e}")
|
| 112 |
return None
|
| 113 |
|
| 114 |
+
# Custom CSS for styling and hiding fullscreen and share buttons
|
| 115 |
custom_css = """
|
| 116 |
+
/* Hide fullscreen and share buttons in the output box */
|
| 117 |
+
.output_image .fullscreen, .output_image .share {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
display: none !important;
|
| 119 |
}
|
| 120 |
/* Non-draggable images */
|
|
|
|
| 146 |
}
|
| 147 |
"""
|
| 148 |
|
| 149 |
+
# Gradio interface
|
| 150 |
demo = gr.Interface(
|
| 151 |
fn=deblur_image,
|
| 152 |
inputs=gr.File(label="Input", type="filepath"),
|
|
|
|
| 156 |
css=custom_css
|
| 157 |
)
|
| 158 |
|
| 159 |
+
# Launch Gradio app
|
| 160 |
if __name__ == "__main__":
|
| 161 |
demo.launch()
|