KroZenDev commited on
Commit
c1f923f
·
verified ·
1 Parent(s): 0f1ce60
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, send_file, jsonify
2
+ import cv2, io
3
+ import numpy as np
4
+
5
+ app = Flask(__name__)
6
+
7
+ model = cv2.dnn_superres.DnnSuperResImpl_create()
8
+ model.readModel('LapSRN_x8.pb')
9
+ model.setModel('lapsrn', 8)
10
+
11
+ @app.route("/upscale/", methods=["POST"])
12
+ def upscale_image():
13
+ if 'file' not in request.files:
14
+ return jsonify({"error": "No file part"}), 400
15
+
16
+ file = request.files['file']
17
+ if file.filename == '':
18
+ return jsonify({"error": "No selected file"}), 400
19
+
20
+ file_bytes = file.read()
21
+ nparr = np.frombuffer(file_bytes, np.uint8)
22
+ img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
23
+ if img is None:
24
+ return jsonify({"error": "Invalid image"}), 400
25
+
26
+ result = model.upsample(img)
27
+
28
+ _, encoded_img = cv2.imencode('.png', result)
29
+ return send_file(
30
+ io.BytesIO(encoded_img.tobytes()),
31
+ mimetype='image/png',
32
+ as_attachment=False,
33
+ download_name='upscaled.png'
34
+ )
35
+
36
+ if __name__ == "__main__":
37
+ app.run(host="0.0.0.0", port=6275)