Prajwal-r-k commited on
Commit
106449d
·
verified ·
1 Parent(s): 3b5fac2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -1,6 +1,6 @@
1
- from flask import Flask, render_template, request, jsonify, send_from_directory
2
  import os
3
- import shutil
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, 'enhanced_' + file.filename)
26
 
27
- # Save original upload
28
  file.save(input_path)
29
 
30
- # Dummy enhancement (copy image as demo)
31
- shutil.copy(input_path, output_path)
32
-
33
- return jsonify({
34
- 'status': 'success',
35
- 'output_path': f'/outputs/enhanced_{file.filename}'
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)