Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
lixiang46
commited on
Commit
•
4e460bd
1
Parent(s):
470fd84
update
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ import time
|
|
11 |
from requests.adapters import HTTPAdapter
|
12 |
|
13 |
def tryon(person_img, garment_img, seed, randomize_seed):
|
14 |
-
|
15 |
if person_img is None or garment_img is None:
|
16 |
return None, None, "Empty image"
|
17 |
if randomize_seed:
|
@@ -31,41 +31,47 @@ def tryon(person_img, garment_img, seed, randomize_seed):
|
|
31 |
"humanImage": encoded_person_img,
|
32 |
"seed": seed
|
33 |
}
|
34 |
-
response = requests.post(url, headers=headers, data=json.dumps(data), timeout=40)
|
35 |
-
print("post response code", response.status_code)
|
36 |
-
if response.status_code == 200:
|
37 |
-
result = response.json()['result']
|
38 |
-
status = result['status']
|
39 |
-
if status == "success":
|
40 |
-
uuid = result['result']
|
41 |
-
print(uuid)
|
42 |
-
|
43 |
try:
|
44 |
-
|
45 |
-
|
46 |
-
session.mount("http://", HTTPAdapter(max_retries=3))
|
47 |
-
response = session.get(url, headers=headers, timeout=10)
|
48 |
-
print("get response code", response.status_code)
|
49 |
if response.status_code == 200:
|
50 |
result = response.json()['result']
|
51 |
status = result['status']
|
52 |
if status == "success":
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
else:
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
print(f"time used: {end_time-start_time}")
|
69 |
|
70 |
return result_img, seed, info
|
71 |
|
|
|
11 |
from requests.adapters import HTTPAdapter
|
12 |
|
13 |
def tryon(person_img, garment_img, seed, randomize_seed):
|
14 |
+
post_start_time = time.time()
|
15 |
if person_img is None or garment_img is None:
|
16 |
return None, None, "Empty image"
|
17 |
if randomize_seed:
|
|
|
31 |
"humanImage": encoded_person_img,
|
32 |
"seed": seed
|
33 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
try:
|
35 |
+
response = requests.post(url, headers=headers, data=json.dumps(data), timeout=30)
|
36 |
+
print("post response code", response.status_code)
|
|
|
|
|
|
|
37 |
if response.status_code == 200:
|
38 |
result = response.json()['result']
|
39 |
status = result['status']
|
40 |
if status == "success":
|
41 |
+
uuid = result['result']
|
42 |
+
print(uuid)
|
43 |
+
finally:
|
44 |
+
pass
|
45 |
+
post_end_time = time.time()
|
46 |
+
print(f"time used: {post_end_time-post_start_time}")
|
47 |
+
|
48 |
+
get_start_time =time.time()
|
49 |
+
Max_Retry = 3
|
50 |
+
for i in range(Max_Retry):
|
51 |
+
try:
|
52 |
+
url = "http://" + os.environ['tryon_url'] + "Query?" + uuid
|
53 |
+
response = requests.get(url, headers=headers, timeout=10)
|
54 |
+
print("get response code", response.status_code)
|
55 |
+
if response.status_code == 200:
|
56 |
+
result = response.json()['result']
|
57 |
+
status = result['status']
|
58 |
+
if status == "success":
|
59 |
+
result = base64.b64decode(result['result'])
|
60 |
+
result_np = np.frombuffer(result, np.uint8)
|
61 |
+
result_img = cv2.imdecode(result_np, cv2.IMREAD_UNCHANGED)
|
62 |
+
result_img = cv2.cvtColor(result_img, cv2.COLOR_RGB2BGR)
|
63 |
+
info = "Success"
|
64 |
+
break
|
65 |
else:
|
66 |
+
print(response.text)
|
67 |
+
info = "URL error, pleace contact the admin"
|
68 |
+
except requests.exceptions.ReadTimeout:
|
69 |
+
print("timeout")
|
70 |
+
info = "Too many users, please try again later"
|
71 |
+
raise gr.Error("Too many users, please try again later")
|
72 |
+
time.sleep(3)
|
73 |
+
get_end_time = time.time()
|
74 |
+
print(f"time used: {get_end_time-get_start_time}")
|
|
|
75 |
|
76 |
return result_img, seed, info
|
77 |
|