Update myapp.py
Browse files
myapp.py
CHANGED
@@ -1,8 +1,6 @@
|
|
1 |
from flask import Flask, jsonify, request, send_file
|
2 |
from flask_cors import CORS
|
3 |
from PIL import Image
|
4 |
-
import numpy as np
|
5 |
-
import cv2
|
6 |
import io
|
7 |
|
8 |
# Initialize the Flask app
|
@@ -11,7 +9,7 @@ CORS(myapp) # Enable CORS if needed
|
|
11 |
|
12 |
@myapp.route('/')
|
13 |
def home():
|
14 |
-
return "Welcome to the Image Upscaler
|
15 |
|
16 |
@myapp.route('/upscale', methods=['POST'])
|
17 |
def upscale_image():
|
@@ -25,18 +23,13 @@ def upscale_image():
|
|
25 |
# Open the image using PIL
|
26 |
img = Image.open(io.BytesIO(input_image))
|
27 |
|
28 |
-
# Resize the image to upscale
|
29 |
upscaled_img = img.resize((img.width * width, img.height * height), Image.LANCZOS)
|
30 |
-
|
31 |
-
#
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
filtered_img = cv2.medianBlur(np_img, 5) # The second parameter is the kernel size
|
36 |
-
|
37 |
-
# Convert the result back to PIL Image for sending
|
38 |
-
_, buffer = cv2.imencode('.png', filtered_img)
|
39 |
-
img_byte_arr = io.BytesIO(buffer)
|
40 |
|
41 |
return send_file(img_byte_arr, mimetype='image/png')
|
42 |
|
|
|
1 |
from flask import Flask, jsonify, request, send_file
|
2 |
from flask_cors import CORS
|
3 |
from PIL import Image
|
|
|
|
|
4 |
import io
|
5 |
|
6 |
# Initialize the Flask app
|
|
|
9 |
|
10 |
@myapp.route('/')
|
11 |
def home():
|
12 |
+
return "Welcome to the Image Upscaler!" # Basic home response
|
13 |
|
14 |
@myapp.route('/upscale', methods=['POST'])
|
15 |
def upscale_image():
|
|
|
23 |
# Open the image using PIL
|
24 |
img = Image.open(io.BytesIO(input_image))
|
25 |
|
26 |
+
# Resize the image to upscale (you can adjust the method as needed)
|
27 |
upscaled_img = img.resize((img.width * width, img.height * height), Image.LANCZOS)
|
28 |
+
|
29 |
+
# Save to bytes
|
30 |
+
img_byte_arr = io.BytesIO()
|
31 |
+
upscaled_img.save(img_byte_arr, format='PNG')
|
32 |
+
img_byte_arr.seek(0)
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
return send_file(img_byte_arr, mimetype='image/png')
|
35 |
|