Spaces:
Running
Running
imseldrith
commited on
Commit
·
4f8d63d
1
Parent(s):
74a17bb
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
from flask import Flask, render_template, request, send_file, jsonify
|
2 |
from imaginepy import Imagine, Style, Ratio
|
|
|
3 |
|
4 |
app = Flask(__name__)
|
5 |
|
@@ -67,12 +68,14 @@ def api_generate_image():
|
|
67 |
return jsonify({'error': "An error occurred while upscaling the image."}), 500
|
68 |
|
69 |
try:
|
70 |
-
|
|
|
71 |
img_file.write(img_data)
|
72 |
except Exception as e:
|
73 |
return jsonify({'error': f"An error occurred while writing the image to file: {e}"}), 500
|
74 |
|
75 |
-
return send_file(
|
76 |
|
77 |
if __name__ == "__main__":
|
78 |
-
app.run(host="0.0.0.0",port=7860)
|
|
|
|
1 |
from flask import Flask, render_template, request, send_file, jsonify
|
2 |
from imaginepy import Imagine, Style, Ratio
|
3 |
+
import os
|
4 |
|
5 |
app = Flask(__name__)
|
6 |
|
|
|
68 |
return jsonify({'error': "An error occurred while upscaling the image."}), 500
|
69 |
|
70 |
try:
|
71 |
+
image_path = os.path.join(app.root_path, "generated.jpeg")
|
72 |
+
with open(image_path, mode="wb") as img_file:
|
73 |
img_file.write(img_data)
|
74 |
except Exception as e:
|
75 |
return jsonify({'error': f"An error occurred while writing the image to file: {e}"}), 500
|
76 |
|
77 |
+
return send_file(image_path, mimetype='image/jpeg', as_attachment=True)
|
78 |
|
79 |
if __name__ == "__main__":
|
80 |
+
app.run(host="0.0.0.0", port=7860)
|
81 |
+
|