Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,11 @@
|
|
| 1 |
-
|
| 2 |
-
from flask_cors import CORS
|
| 3 |
-
from rembg import remove
|
| 4 |
-
from PIL import Image
|
| 5 |
-
import io
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
CORS(app) # Enable CORS if needed
|
| 10 |
|
| 11 |
-
@app.route('/')
|
| 12 |
-
def home():
|
| 13 |
-
return "Welcome to the Image Background Remover!" # Basic home response
|
| 14 |
-
|
| 15 |
-
@app.route('/remove_background', methods=['POST'])
|
| 16 |
-
def remove_background():
|
| 17 |
-
if 'image' not in request.files:
|
| 18 |
-
return jsonify({"error": "No image provided"}), 400
|
| 19 |
-
|
| 20 |
-
input_image = request.files['image'].read() # Read the uploaded image
|
| 21 |
-
output_bytes = remove(input_image) # Process the image with rembg
|
| 22 |
-
|
| 23 |
-
# Convert the output bytes back into a PIL image
|
| 24 |
-
output_image = Image.open(io.BytesIO(output_bytes))
|
| 25 |
-
img_byte_arr = io.BytesIO()
|
| 26 |
-
output_image.save(img_byte_arr, format='PNG')
|
| 27 |
-
img_byte_arr.seek(0)
|
| 28 |
-
|
| 29 |
-
return send_file(img_byte_arr, mimetype='image/png')
|
| 30 |
-
|
| 31 |
-
# Add this block to make sure your app runs when called
|
| 32 |
if __name__ == "__main__":
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
import os
|
| 4 |
+
import subprocess
|
|
|
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
if __name__ == "__main__":
|
| 7 |
+
# Run awake.py in the background
|
| 8 |
+
subprocess.Popen(["python", "wk.py"]) # Start awake.py
|
| 9 |
+
|
| 10 |
+
# Run the Flask app using Gunicorn
|
| 11 |
+
os.system("gunicorn -w 4 -b 0.0.0.0:7860 myapp:myapp") # 4 worker processes
|