Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -31,6 +31,7 @@ import os
|
|
31 |
import tempfile
|
32 |
import zipfile
|
33 |
|
|
|
34 |
def zoom_at(img, x, y, zoom):
|
35 |
'''
|
36 |
Zoom into an image at a specific location.
|
@@ -63,6 +64,7 @@ def zoom_at(img, x, y, zoom):
|
|
63 |
img_cropped = img.crop((left, upper, right, lower))
|
64 |
return img_cropped.resize((500, 500), Image.LANCZOS)
|
65 |
|
|
|
66 |
def apply_enhancements(img, x, y, zoom, contrast, brightness, sharpness):
|
67 |
'''
|
68 |
Apply zoom and image enhancements to the input image.
|
@@ -93,8 +95,9 @@ def apply_enhancements(img, x, y, zoom, contrast, brightness, sharpness):
|
|
93 |
enhanced_contrast = ImageEnhance.Contrast(zoomed).enhance(contrast)
|
94 |
enhanced_brightness = ImageEnhance.Brightness(enhanced_contrast).enhance(brightness)
|
95 |
enhanced_sharpness = ImageEnhance.Sharpness(enhanced_brightness).enhance(sharpness)
|
96 |
-
return enhanced_sharpness
|
97 |
|
|
|
98 |
def create_zip(processed_img, description, params):
|
99 |
'''
|
100 |
Create a zip archive containing the processed image and annotations.
|
@@ -168,9 +171,9 @@ if uploaded_files:
|
|
168 |
with image_col:
|
169 |
st.subheader("Processed Image")
|
170 |
if 'processed_img' in st.session_state:
|
171 |
-
st.image(st.session_state.processed_img, caption="Processed Image")
|
172 |
else:
|
173 |
-
st.image(img, caption="Processed Image")
|
174 |
|
175 |
with controls_col:
|
176 |
st.subheader("Image Controls")
|
@@ -186,9 +189,6 @@ if uploaded_files:
|
|
186 |
if st.button("Apply Adjustments"):
|
187 |
processed_img = apply_enhancements(img, x, y, zoom, contrast, brightness, sharpness)
|
188 |
st.session_state.processed_img = processed_img
|
189 |
-
else:
|
190 |
-
processed_img = apply_enhancements(img, x, y, zoom, contrast, brightness, sharpness)
|
191 |
-
st.session_state.processed_img = processed_img
|
192 |
|
193 |
# Display Original Image Below
|
194 |
st.subheader("Original Image")
|
|
|
31 |
import tempfile
|
32 |
import zipfile
|
33 |
|
34 |
+
@st.cache_data
|
35 |
def zoom_at(img, x, y, zoom):
|
36 |
'''
|
37 |
Zoom into an image at a specific location.
|
|
|
64 |
img_cropped = img.crop((left, upper, right, lower))
|
65 |
return img_cropped.resize((500, 500), Image.LANCZOS)
|
66 |
|
67 |
+
@st.cache_data
|
68 |
def apply_enhancements(img, x, y, zoom, contrast, brightness, sharpness):
|
69 |
'''
|
70 |
Apply zoom and image enhancements to the input image.
|
|
|
95 |
enhanced_contrast = ImageEnhance.Contrast(zoomed).enhance(contrast)
|
96 |
enhanced_brightness = ImageEnhance.Brightness(enhanced_contrast).enhance(brightness)
|
97 |
enhanced_sharpness = ImageEnhance.Sharpness(enhanced_brightness).enhance(sharpness)
|
98 |
+
return enhanced_sharpness
|
99 |
|
100 |
+
@st.cache_data
|
101 |
def create_zip(processed_img, description, params):
|
102 |
'''
|
103 |
Create a zip archive containing the processed image and annotations.
|
|
|
171 |
with image_col:
|
172 |
st.subheader("Processed Image")
|
173 |
if 'processed_img' in st.session_state:
|
174 |
+
st.image(st.session_state.processed_img, use_column_width=True, caption="Processed Image")
|
175 |
else:
|
176 |
+
st.image(img, use_column_width=True, caption="Processed Image")
|
177 |
|
178 |
with controls_col:
|
179 |
st.subheader("Image Controls")
|
|
|
189 |
if st.button("Apply Adjustments"):
|
190 |
processed_img = apply_enhancements(img, x, y, zoom, contrast, brightness, sharpness)
|
191 |
st.session_state.processed_img = processed_img
|
|
|
|
|
|
|
192 |
|
193 |
# Display Original Image Below
|
194 |
st.subheader("Original Image")
|