Update app.py
Browse files
app.py
CHANGED
@@ -30,9 +30,12 @@ loaded_autoencoder = tf.keras.models.load_model(
|
|
30 |
)
|
31 |
|
32 |
def process_image(input_img):
|
33 |
-
#
|
|
|
|
|
|
|
34 |
img = input_img.convert("L") # Convert to grayscale (single channel)
|
35 |
-
img = img.resize((WIDTH, HEIGHT)) # Resize to 512x512
|
36 |
img_array = tf.keras.preprocessing.image.img_to_array(img) / 255.0 # Normalize to [0, 1]
|
37 |
img_array = img_array[None, ..., 0:1] # Add batch dimension, shape: (1, 512, 512, 1)
|
38 |
|
@@ -52,15 +55,18 @@ def process_image(input_img):
|
|
52 |
rgb_array = np.clip(rgb_array, 0, 1) * 255.0 # Scale to [0, 255]
|
53 |
rgb_image = Image.fromarray(rgb_array.astype(np.uint8), mode="RGB") # Create RGB PIL image
|
54 |
|
|
|
|
|
|
|
55 |
return rgb_image
|
56 |
|
57 |
custom_css = """
|
58 |
-
body {background: linear-gradient(135deg, #
|
59 |
.gradio-container {background: transparent !important;}
|
60 |
-
h1, .gr-title {color: #
|
61 |
-
.gr-description {color: #
|
62 |
-
.gr-input, .gr-output {border-radius: 18px !important; box-shadow: 0 4px 24px rgba(0,0,0,0.
|
63 |
-
.gr-button {background: linear-gradient(90deg, #
|
64 |
"""
|
65 |
|
66 |
demo = gr.Interface(
|
@@ -78,8 +84,8 @@ demo = gr.Interface(
|
|
78 |
css=custom_css,
|
79 |
allow_flagging="never",
|
80 |
examples=[
|
81 |
-
["examples/
|
82 |
-
["examples/
|
83 |
]
|
84 |
)
|
85 |
|
|
|
30 |
)
|
31 |
|
32 |
def process_image(input_img):
|
33 |
+
# Store original input dimensions
|
34 |
+
original_width, original_height = input_img.size
|
35 |
+
|
36 |
+
# Convert PIL Image to grayscale and resize to model input size
|
37 |
img = input_img.convert("L") # Convert to grayscale (single channel)
|
38 |
+
img = img.resize((WIDTH, HEIGHT)) # Resize to 512x512 for model
|
39 |
img_array = tf.keras.preprocessing.image.img_to_array(img) / 255.0 # Normalize to [0, 1]
|
40 |
img_array = img_array[None, ..., 0:1] # Add batch dimension, shape: (1, 512, 512, 1)
|
41 |
|
|
|
55 |
rgb_array = np.clip(rgb_array, 0, 1) * 255.0 # Scale to [0, 255]
|
56 |
rgb_image = Image.fromarray(rgb_array.astype(np.uint8), mode="RGB") # Create RGB PIL image
|
57 |
|
58 |
+
# Resize output image to match input image resolution
|
59 |
+
rgb_image = rgb_image.resize((original_width, original_height), Image.Resampling.LANCZOS)
|
60 |
+
|
61 |
return rgb_image
|
62 |
|
63 |
custom_css = """
|
64 |
+
body {background: linear-gradient(135deg, #f0f4f8 0%, #d9e2ec 100%) !important;}
|
65 |
.gradio-container {background: transparent !important;}
|
66 |
+
h1, .gr-title {color: #007bff !important; font-family: 'Segoe UI', sans-serif;}
|
67 |
+
.gr-description {color: #333333 !important; font-size: 1.1em;}
|
68 |
+
.gr-input, .gr-output {border-radius: 18px !important; box-shadow: 0 4px 24px rgba(0,0,0,0.1);}
|
69 |
+
.gr-button {background: linear-gradient(90deg, #007bff 0%, #00c4cc 100%) !important; color: #fff !important; border: none !important; border-radius: 12px !important;}
|
70 |
"""
|
71 |
|
72 |
demo = gr.Interface(
|
|
|
84 |
css=custom_css,
|
85 |
allow_flagging="never",
|
86 |
examples=[
|
87 |
+
["examples/example_input_1.jpg"],
|
88 |
+
["examples/example_input_2.jpg"]
|
89 |
]
|
90 |
)
|
91 |
|