Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -161,7 +161,7 @@ def get_image_size_kb(image):
|
|
161 |
size_bytes = buffer.tell()
|
162 |
return size_bytes / 1024 # Convert to KB
|
163 |
|
164 |
-
def upload_to_s3(image, user_id, folder=""):
|
165 |
"""
|
166 |
Upload image to S3 bucket and return the S3 path
|
167 |
|
@@ -169,6 +169,7 @@ def upload_to_s3(image, user_id, folder=""):
|
|
169 |
image: PIL Image object
|
170 |
user_id: User ID for folder structure
|
171 |
folder: Subfolder to store the image in (e.g., "raw-uploads" or "processed-512x512")
|
|
|
172 |
"""
|
173 |
if st.session_state.get("demo_mode", False):
|
174 |
return f"demo/{user_id}/demo_image.jpg"
|
@@ -186,8 +187,14 @@ def upload_to_s3(image, user_id, folder=""):
|
|
186 |
|
187 |
# Convert PIL image to bytes
|
188 |
buffer = BytesIO()
|
189 |
-
|
190 |
-
quality
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
image.save(buffer, format="JPEG", quality=quality, optimize=True)
|
192 |
buffer.seek(0)
|
193 |
|
|
|
161 |
size_bytes = buffer.tell()
|
162 |
return size_bytes / 1024 # Convert to KB
|
163 |
|
164 |
+
def upload_to_s3(image, user_id, folder="", force_quality=None):
|
165 |
"""
|
166 |
Upload image to S3 bucket and return the S3 path
|
167 |
|
|
|
169 |
image: PIL Image object
|
170 |
user_id: User ID for folder structure
|
171 |
folder: Subfolder to store the image in (e.g., "raw-uploads" or "processed-512x512")
|
172 |
+
force_quality: Override default quality settings if specified
|
173 |
"""
|
174 |
if st.session_state.get("demo_mode", False):
|
175 |
return f"demo/{user_id}/demo_image.jpg"
|
|
|
187 |
|
188 |
# Convert PIL image to bytes
|
189 |
buffer = BytesIO()
|
190 |
+
|
191 |
+
# Set quality based on folder or forced value
|
192 |
+
if force_quality is not None:
|
193 |
+
quality = force_quality
|
194 |
+
else:
|
195 |
+
# Higher quality for raw uploads, compressed for processed
|
196 |
+
quality = 95 if folder == "raw-uploads" else 85
|
197 |
+
|
198 |
image.save(buffer, format="JPEG", quality=quality, optimize=True)
|
199 |
buffer.seek(0)
|
200 |
|