Geek7 commited on
Commit
f57b188
·
verified ·
1 Parent(s): 15a9f8d

Create myapp.py

Browse files
Files changed (1) hide show
  1. myapp.py +31 -0
myapp.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ from flask_cors import CORS
3
+ from PIL import Image
4
+
5
+ # Initialize the Flask app
6
+ myapp = Flask(__name__)
7
+
8
+ # Enable CORS for the app
9
+ CORS(myapp)
10
+
11
+ @myapp.route('/')
12
+ def index():
13
+ return "Welcome to the AI Model Upscale!"
14
+
15
+ @myapp.route('/resize', methods=['POST'])
16
+ def resize_image():
17
+ data = request.json
18
+ input_path = data.get('input_path')
19
+ output_path = data.get('output_path')
20
+ width = data.get('width')
21
+ height = data.get('height')
22
+
23
+ # Open an image file and resize it
24
+ with Image.open(input_path) as img:
25
+ resized_img = img.resize((width, height), Image.LANCZOS)
26
+ resized_img.save(output_path)
27
+
28
+ return jsonify({'message': 'Image resized successfully', 'output_path': output_path})
29
+
30
+ if __name__ == "__main__":
31
+ myapp.run(host='0.0.0.0', port=5000)