File size: 834 Bytes
f57b188
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from flask import Flask, request, jsonify
from flask_cors import CORS
from PIL import Image

# Initialize the Flask app
myapp = Flask(__name__)

# Enable CORS for the app
CORS(myapp)

@myapp.route('/')
def index():
    return "Welcome to the AI Model Upscale!"

@myapp.route('/resize', methods=['POST'])
def resize_image():
    data = request.json
    input_path = data.get('input_path')
    output_path = data.get('output_path')
    width = data.get('width')
    height = data.get('height')

    # Open an image file and resize it
    with Image.open(input_path) as img:
        resized_img = img.resize((width, height), Image.LANCZOS)
        resized_img.save(output_path)

    return jsonify({'message': 'Image resized successfully', 'output_path': output_path})

if __name__ == "__main__":
    myapp.run(host='0.0.0.0', port=5000)