Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
-
from flask import Flask,
|
2 |
import os
|
3 |
-
import
|
4 |
|
5 |
app = Flask(__name__)
|
6 |
|
@@ -14,7 +14,6 @@ os.makedirs(OUTPUT_FOLDER, exist_ok=True)
|
|
14 |
def index():
|
15 |
return render_template('index.html')
|
16 |
|
17 |
-
|
18 |
@app.route('/process_image', methods=['POST'])
|
19 |
def process_image():
|
20 |
if 'file' not in request.files:
|
@@ -22,24 +21,27 @@ def process_image():
|
|
22 |
|
23 |
file = request.files['file']
|
24 |
input_path = os.path.join(UPLOAD_FOLDER, file.filename)
|
25 |
-
output_path = os.path.join(OUTPUT_FOLDER, '
|
26 |
|
27 |
-
# Save
|
28 |
file.save(input_path)
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
37 |
|
|
|
|
|
|
|
38 |
|
39 |
@app.route('/outputs/<filename>')
|
40 |
def get_output_image(filename):
|
41 |
return send_from_directory(OUTPUT_FOLDER, filename)
|
42 |
|
43 |
-
|
44 |
if __name__ == '__main__':
|
45 |
app.run(host='0.0.0.0', port=7860)
|
|
|
1 |
+
from flask import Flask, request, jsonify, send_from_directory, render_template
|
2 |
import os
|
3 |
+
import subprocess
|
4 |
|
5 |
app = Flask(__name__)
|
6 |
|
|
|
14 |
def index():
|
15 |
return render_template('index.html')
|
16 |
|
|
|
17 |
@app.route('/process_image', methods=['POST'])
|
18 |
def process_image():
|
19 |
if 'file' not in request.files:
|
|
|
21 |
|
22 |
file = request.files['file']
|
23 |
input_path = os.path.join(UPLOAD_FOLDER, file.filename)
|
24 |
+
output_path = os.path.join(OUTPUT_FOLDER, 'output.png')
|
25 |
|
26 |
+
# Save the uploaded image
|
27 |
file.save(input_path)
|
28 |
|
29 |
+
try:
|
30 |
+
# Run NAFNet model using subprocess
|
31 |
+
subprocess.run([
|
32 |
+
'python', 'NAFNet/demo.py',
|
33 |
+
'-opt', 'NAFNet/options/test/REDS/NAFNet-width64.yml',
|
34 |
+
'--input_path', input_path,
|
35 |
+
'--output_path', output_path
|
36 |
+
], check=True)
|
37 |
|
38 |
+
return jsonify({'status': 'success', 'output_path': f'/outputs/output.png'})
|
39 |
+
except subprocess.CalledProcessError as e:
|
40 |
+
return jsonify({'status': 'error', 'message': f'Failed to run model: {str(e)}'})
|
41 |
|
42 |
@app.route('/outputs/<filename>')
|
43 |
def get_output_image(filename):
|
44 |
return send_from_directory(OUTPUT_FOLDER, filename)
|
45 |
|
|
|
46 |
if __name__ == '__main__':
|
47 |
app.run(host='0.0.0.0', port=7860)
|