Update app.py
Browse files
app.py
CHANGED
|
@@ -344,38 +344,30 @@ fetch('${apiUrl}', {
|
|
| 344 |
|
| 345 |
@app.route('/api/restore', methods=['POST'])
|
| 346 |
def api_restore():
|
| 347 |
-
|
|
|
|
| 348 |
return jsonify({'error': 'No file uploaded'}), 400
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
except Exception as e:
|
| 371 |
-
return jsonify({'error': str(e)}), 500
|
| 372 |
-
|
| 373 |
-
finally:
|
| 374 |
-
# Clean up temp files
|
| 375 |
-
if 'input_path' in locals() and os.path.exists(input_path):
|
| 376 |
-
os.remove(input_path)
|
| 377 |
-
if 'temp_dir' in locals() and os.path.exists(temp_dir):
|
| 378 |
-
os.rmdir(temp_dir)
|
| 379 |
|
| 380 |
if __name__ == '__main__':
|
| 381 |
app.run(host='0.0.0.0', port=7860, debug=True)
|
|
|
|
| 344 |
|
| 345 |
@app.route('/api/restore', methods=['POST'])
|
| 346 |
def api_restore():
|
| 347 |
+
data = request.get_json()
|
| 348 |
+
if not data or 'file' not in data:
|
| 349 |
return jsonify({'error': 'No file uploaded'}), 400
|
| 350 |
+
|
| 351 |
+
import base64
|
| 352 |
+
from io import BytesIO
|
| 353 |
+
from PIL import Image
|
| 354 |
+
|
| 355 |
+
# Base64データをデコード
|
| 356 |
+
file_data = data['file'].split(",")[1]
|
| 357 |
+
img_bytes = base64.b64decode(file_data)
|
| 358 |
+
temp_dir = tempfile.mkdtemp()
|
| 359 |
+
input_path = os.path.join(temp_dir, "input.jpg")
|
| 360 |
+
with open(input_path, "wb") as f:
|
| 361 |
+
f.write(img_bytes)
|
| 362 |
+
|
| 363 |
+
version = data.get('version', 'v1.4')
|
| 364 |
+
scale = float(data.get('scale', 2))
|
| 365 |
+
weight = float(data.get('weight', 0.5)) if version == 'CodeFormer' else None
|
| 366 |
+
|
| 367 |
+
# 画像処理
|
| 368 |
+
output_path = process_image(input_path, version, scale, weight)
|
| 369 |
+
return send_file(output_path, mimetype="image/jpeg")
|
| 370 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 371 |
|
| 372 |
if __name__ == '__main__':
|
| 373 |
app.run(host='0.0.0.0', port=7860, debug=True)
|