Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
from flask import Flask, request, jsonify
|
2 |
-
from gradio_client import Client,
|
3 |
import os
|
4 |
|
5 |
-
app = Flask(__name__)
|
6 |
|
7 |
# Initialize Gradio Client
|
8 |
-
client = Client("
|
9 |
|
10 |
@app.route('/tryon', methods=['POST'])
|
11 |
def tryon():
|
@@ -14,21 +14,34 @@ def tryon():
|
|
14 |
data = request.get_json()
|
15 |
|
16 |
# Validate required parameters
|
17 |
-
if not data or not all(key in data for key in ['
|
18 |
-
return jsonify({"error": "Missing required parameters:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
# Call Gradio API
|
21 |
result = client.predict(
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
24 |
denoise_steps=data.get('denoise_steps', 30),
|
25 |
-
seed=data.get('seed',
|
26 |
-
|
|
|
27 |
)
|
28 |
|
29 |
# Format response
|
30 |
response = {
|
31 |
-
"
|
|
|
32 |
}
|
33 |
|
34 |
return jsonify(response), 200
|
@@ -37,4 +50,4 @@ def tryon():
|
|
37 |
return jsonify({"error": str(e)}), 500
|
38 |
|
39 |
if __name__ == '__main__':
|
40 |
-
app.run(host='0.0.0.0', port=
|
|
|
1 |
from flask import Flask, request, jsonify
|
2 |
+
from gradio_client import Client, handle_file
|
3 |
import os
|
4 |
|
5 |
+
app = Flask(__name__)
|
6 |
|
7 |
# Initialize Gradio Client
|
8 |
+
client = Client("jallenjia/Change-Clothes-AI")
|
9 |
|
10 |
@app.route('/tryon', methods=['POST'])
|
11 |
def tryon():
|
|
|
14 |
data = request.get_json()
|
15 |
|
16 |
# Validate required parameters
|
17 |
+
if not data or not all(key in data for key in ['background', 'garm_img', 'garment_des']):
|
18 |
+
return jsonify({"error": "Missing required parameters: background, garm_img, garment_des"}), 400
|
19 |
+
|
20 |
+
# Prepare input dictionary
|
21 |
+
input_dict = {
|
22 |
+
"background": handle_file(data['background']) if data.get('background') else None,
|
23 |
+
"layers": data.get('layers', []),
|
24 |
+
"composite": handle_file(data.get('composite')) if data.get('composite') else None,
|
25 |
+
"id": data.get('id')
|
26 |
+
}
|
27 |
|
28 |
# Call Gradio API
|
29 |
result = client.predict(
|
30 |
+
dict=input_dict,
|
31 |
+
garm_img=handle_file(data['garm_img']),
|
32 |
+
garment_des=data['garment_des'],
|
33 |
+
is_checked=data.get('is_checked', True),
|
34 |
+
is_checked_crop=data.get('is_checked_crop', False),
|
35 |
denoise_steps=data.get('denoise_steps', 30),
|
36 |
+
seed=data.get('seed', -1),
|
37 |
+
category=data.get('category', 'upper_body'),
|
38 |
+
api_name="/tryon"
|
39 |
)
|
40 |
|
41 |
# Format response
|
42 |
response = {
|
43 |
+
"output_image": result[0], # Filepath of output image
|
44 |
+
"masked_image": result[1] # Filepath of masked image
|
45 |
}
|
46 |
|
47 |
return jsonify(response), 200
|
|
|
50 |
return jsonify({"error": str(e)}), 500
|
51 |
|
52 |
if __name__ == '__main__':
|
53 |
+
app.run(host='0.0.0.0', port=5000)
|