Spaces:
Sleeping
Sleeping
Phuc Vo
commited on
Commit
·
564a1f1
1
Parent(s):
4569902
update
Browse files
app.py
CHANGED
|
@@ -8,20 +8,21 @@ import os
|
|
| 8 |
|
| 9 |
def call_predict_api(person, cloth):
|
| 10 |
# Convert PIL images to base64 string
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
return base64.b64encode(buffer.getvalue()).decode('utf-8')
|
| 15 |
|
| 16 |
-
|
| 17 |
-
cloth =
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
"
|
|
|
|
| 22 |
}
|
| 23 |
headers = {"X-API-Key": os.environ["api_key"]}
|
| 24 |
-
response = requests.post(os.environ["endpoint"],
|
| 25 |
if response.status_code != 200:
|
| 26 |
raise Exception(f"API Error: {response.text}")
|
| 27 |
result = response.json()
|
|
|
|
| 8 |
|
| 9 |
def call_predict_api(person, cloth):
|
| 10 |
# Convert PIL images to base64 string
|
| 11 |
+
src_buffer = BytesIO()
|
| 12 |
+
person.save(src_buffer, format='PNG')
|
| 13 |
+
src_buffer.seek(0)
|
|
|
|
| 14 |
|
| 15 |
+
ref_buffer = BytesIO()
|
| 16 |
+
cloth.save(ref_buffer, format='PNG')
|
| 17 |
+
ref_buffer.seek(0)
|
| 18 |
|
| 19 |
+
# Prepare files for upload
|
| 20 |
+
files = {
|
| 21 |
+
"src_image": ("src_image.png", src_buffer, "image/png"),
|
| 22 |
+
"ref_image": ("ref_image.png", ref_buffer, "image/png")
|
| 23 |
}
|
| 24 |
headers = {"X-API-Key": os.environ["api_key"]}
|
| 25 |
+
response = requests.post(os.environ["endpoint"], files=files, headers=headers)
|
| 26 |
if response.status_code != 200:
|
| 27 |
raise Exception(f"API Error: {response.text}")
|
| 28 |
result = response.json()
|