Update app.py
Browse files
app.py
CHANGED
@@ -1,47 +1,11 @@
|
|
1 |
-
|
2 |
-
from flask_cors import CORS
|
3 |
-
from huggingface_hub import InferenceClient
|
4 |
-
from PIL import Image
|
5 |
-
import io
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
CORS(app)
|
10 |
|
11 |
-
|
12 |
-
|
|
|
13 |
|
14 |
-
#
|
15 |
-
|
16 |
-
|
17 |
-
@app.route('/upscale', methods=['POST'])
|
18 |
-
def upscale_image():
|
19 |
-
try:
|
20 |
-
# Retrieve the image file from the request
|
21 |
-
image_file = request.files.get('image')
|
22 |
-
if not image_file:
|
23 |
-
return jsonify({"error": "No image file provided"}), 400
|
24 |
-
|
25 |
-
# Open the image
|
26 |
-
input_image = Image.open(image_file)
|
27 |
-
|
28 |
-
# Use the Hugging Face Inference Client to upscale the image
|
29 |
-
result = client.image_to_image(
|
30 |
-
image=input_image,
|
31 |
-
prompt="", # Optional: Add a guiding prompt
|
32 |
-
num_inference_steps=50, # Adjust as needed
|
33 |
-
guidance_scale=6.0 # Adjust as needed
|
34 |
-
)
|
35 |
-
|
36 |
-
# Save the upscaled image to a BytesIO object
|
37 |
-
img_io = io.BytesIO()
|
38 |
-
result.save(img_io, 'PNG')
|
39 |
-
img_io.seek(0)
|
40 |
-
|
41 |
-
return send_file(img_io, mimetype='image/png')
|
42 |
-
except Exception as e:
|
43 |
-
return jsonify({"error": str(e)}), 500
|
44 |
-
|
45 |
-
# Run the app
|
46 |
-
if __name__ == '__main__':
|
47 |
-
app.run(host='0.0.0.0', port=5000)
|
|
|
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:5000 myapp:myapp") # 4 worker processes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|