Spaces:
Paused
Paused
giorgio-caparvi
commited on
Commit
·
67b8057
1
Parent(s):
bed9a40
Makeing online working
Browse files- api/app.py +4 -38
api/app.py
CHANGED
@@ -1,45 +1,13 @@
|
|
1 |
from flask import Flask, request, jsonify
|
2 |
from flask_cors import CORS
|
3 |
-
|
4 |
-
#from flask_limiter import Limiter
|
5 |
-
#from flask_limiter.util import get_remote_address
|
6 |
|
7 |
app = Flask(__name__)
|
8 |
-
|
9 |
-
|
10 |
-
CORS(app, resources={r"/generate-design": {"origins": "*"}})
|
11 |
-
|
12 |
-
'''
|
13 |
-
limiter = Limiter(
|
14 |
-
get_remote_address,
|
15 |
-
app=app,
|
16 |
-
default_limits=["10 per minute"] # Limita a 10 richieste al minuto per ogni IP
|
17 |
-
)'''
|
18 |
-
|
19 |
-
@app.route('/generate-design', methods=['POST'])
|
20 |
-
#@limiter.limit("10 per minute")
|
21 |
|
|
|
22 |
def generate_design():
|
23 |
-
|
24 |
-
data = request.json
|
25 |
-
|
26 |
-
# Extract image and json
|
27 |
-
image_data = data.get('image')
|
28 |
-
design_data = data.get('designData')
|
29 |
-
|
30 |
-
## Extract image
|
31 |
-
if image_data:
|
32 |
-
image_bytes = base64.b64decode(image_data.split(',')[1]) # Decodifica la parte base64
|
33 |
-
with open("received_design.png", "wb") as image_file:
|
34 |
-
image_file.write(image_bytes)
|
35 |
-
|
36 |
-
# Update JSON
|
37 |
-
design_data['status'] = 'success'
|
38 |
-
design_data['message'] = 'Design received and processed'
|
39 |
-
|
40 |
-
return jsonify(design_data)
|
41 |
-
'''
|
42 |
-
|
43 |
command = [
|
44 |
'python', 'app/model/src/eval.py',
|
45 |
'--dataset_path', './assets/data/vitonhd',
|
@@ -54,13 +22,11 @@ def generate_design():
|
|
54 |
'--test_order', 'paired'
|
55 |
]
|
56 |
|
57 |
-
# Esegue il comando
|
58 |
try:
|
59 |
subprocess.run(command, check=True)
|
60 |
return jsonify({"status": "success", "message": "Command executed successfully"})
|
61 |
except subprocess.CalledProcessError as e:
|
62 |
return jsonify({"status": "error", "message": str(e)}), 500
|
63 |
-
|
64 |
|
65 |
if __name__ == '__main__':
|
66 |
app.run(host='0.0.0.0', port=7860)
|
|
|
1 |
from flask import Flask, request, jsonify
|
2 |
from flask_cors import CORS
|
3 |
+
import subprocess
|
|
|
|
|
4 |
|
5 |
app = Flask(__name__)
|
6 |
+
CORS(app)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
@app.route('/', methods=['POST'])
|
9 |
def generate_design():
|
10 |
+
# Same command handling as before
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
command = [
|
12 |
'python', 'app/model/src/eval.py',
|
13 |
'--dataset_path', './assets/data/vitonhd',
|
|
|
22 |
'--test_order', 'paired'
|
23 |
]
|
24 |
|
|
|
25 |
try:
|
26 |
subprocess.run(command, check=True)
|
27 |
return jsonify({"status": "success", "message": "Command executed successfully"})
|
28 |
except subprocess.CalledProcessError as e:
|
29 |
return jsonify({"status": "error", "message": str(e)}), 500
|
|
|
30 |
|
31 |
if __name__ == '__main__':
|
32 |
app.run(host='0.0.0.0', port=7860)
|