Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -221,13 +221,23 @@ async def upscale_image(image_bytes: bytes, filename: str) -> Optional[str]:
|
|
| 221 |
|
| 222 |
@app.route('/upscale', methods=['POST'])
|
| 223 |
async def upscale_endpoint():
|
| 224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
return jsonify({"error": "No file provided"}), 400
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
return jsonify({"error": "No file selected"}), 400
|
| 229 |
-
filename = secure_filename(file.filename)
|
| 230 |
-
image_bytes = file.read()
|
| 231 |
upscaled_url = await upscale_image(image_bytes, filename)
|
| 232 |
if upscaled_url:
|
| 233 |
return jsonify({"upscaled_url": upscaled_url}), 200
|
|
|
|
| 221 |
|
| 222 |
@app.route('/upscale', methods=['POST'])
|
| 223 |
async def upscale_endpoint():
|
| 224 |
+
# Check for file in multipart/form-data
|
| 225 |
+
if 'file' in request.files:
|
| 226 |
+
file = request.files['file']
|
| 227 |
+
if file.filename == '':
|
| 228 |
+
print("File filename is empty")
|
| 229 |
+
return jsonify({"error": "No file selected"}), 400
|
| 230 |
+
filename = secure_filename(file.filename)
|
| 231 |
+
image_bytes = file.read()
|
| 232 |
+
# Fallback for raw binary data
|
| 233 |
+
elif request.content_type and 'application/octet-stream' in request.content_type:
|
| 234 |
+
image_bytes = request.get_data()
|
| 235 |
+
filename = f"uploaded_{generate_uuid()}.bin" # Default filename for raw binary
|
| 236 |
+
else:
|
| 237 |
+
print("No file part in request.files and no raw binary data")
|
| 238 |
return jsonify({"error": "No file provided"}), 400
|
| 239 |
+
|
| 240 |
+
print(f"Received file: {filename}, size: {len(image_bytes)} bytes")
|
|
|
|
|
|
|
|
|
|
| 241 |
upscaled_url = await upscale_image(image_bytes, filename)
|
| 242 |
if upscaled_url:
|
| 243 |
return jsonify({"upscaled_url": upscaled_url}), 200
|