Update app.py
Browse files
app.py
CHANGED
@@ -1,45 +1,11 @@
|
|
1 |
-
|
2 |
-
from flask_cors import CORS
|
3 |
-
from gradio_client import Client
|
4 |
-
from all_models import models # Import the models list
|
5 |
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
|
10 |
-
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
data = request.get_json()
|
15 |
-
|
16 |
-
# Validate required fields
|
17 |
-
if not data or 'model_str' not in data or 'prompt' not in data or 'seed' not in data:
|
18 |
-
return jsonify({"error": "Missing required fields"}), 400
|
19 |
-
|
20 |
-
model_str = data['model_str']
|
21 |
-
prompt = data['prompt']
|
22 |
-
seed = data['seed']
|
23 |
-
|
24 |
-
# Check if the model_str exists in the models list
|
25 |
-
if model_str not in models:
|
26 |
-
return jsonify({"error": f"Model '{model_str}' is not available."}), 400
|
27 |
-
|
28 |
-
try:
|
29 |
-
# Send a request to the Gradio Client and get the result
|
30 |
-
result = client.predict(
|
31 |
-
model_str=model_str,
|
32 |
-
prompt=prompt,
|
33 |
-
seed=seed,
|
34 |
-
api_name="/predict"
|
35 |
-
)
|
36 |
-
|
37 |
-
# Save the result to a file (assuming it returns a filepath)
|
38 |
-
result_path = result # Result is already the filepath
|
39 |
-
return send_file(result_path, mimetype='image/png')
|
40 |
-
|
41 |
-
except Exception as e:
|
42 |
-
return jsonify({"error": str(e)}), 500
|
43 |
-
|
44 |
-
if __name__ == '__main__':
|
45 |
-
app.run(debug=True)
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|