Spaces:
Running
Running
Commit
·
99397a6
1
Parent(s):
fde74d0
update
Browse files
app.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
-
|
| 2 |
import cv2
|
| 3 |
from mtcnn.mtcnn import MTCNN
|
| 4 |
from utils import *
|
|
|
|
|
|
|
| 5 |
|
| 6 |
|
| 7 |
cloth_examples = get_cloth_examples(hr=0)
|
|
@@ -20,6 +21,28 @@ description = r"""
|
|
| 20 |
"""
|
| 21 |
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
def onClick(cloth_image, pose_image, high_resolution, request: gr.Request):
|
| 24 |
if pose_image is None:
|
| 25 |
yield None, "no pose image found !", ""
|
|
@@ -78,7 +101,9 @@ def onClick(cloth_image, pose_image, high_resolution, request: gr.Request):
|
|
| 78 |
return None, "fail to public you task", ""
|
| 79 |
|
| 80 |
print(client_ip, public_res['mid_result'])
|
| 81 |
-
|
|
|
|
|
|
|
| 82 |
|
| 83 |
max_try = 120*3
|
| 84 |
wait_s = 0.5
|
|
@@ -87,9 +112,13 @@ def onClick(cloth_image, pose_image, high_resolution, request: gr.Request):
|
|
| 87 |
state = getInfRes(public_res['id'])
|
| 88 |
timestamp = int(time.time() * 1000)
|
| 89 |
if state is None:
|
| 90 |
-
|
|
|
|
|
|
|
| 91 |
elif state['status']=='PROCESSING':
|
| 92 |
-
|
|
|
|
|
|
|
| 93 |
elif state['status']=='SUCCEED':
|
| 94 |
yield state['output1'] + f"?t={timestamp}", f"task finished, {state['msg']}", ""
|
| 95 |
return state['output1'] + f"?t={timestamp}", f"task finished, {state['msg']}", ""
|
|
@@ -97,7 +126,9 @@ def onClick(cloth_image, pose_image, high_resolution, request: gr.Request):
|
|
| 97 |
yield None, f"task failed, {state['msg']}", ""
|
| 98 |
return None, f"task failed, {state['msg']}", ""
|
| 99 |
else:
|
| 100 |
-
|
|
|
|
|
|
|
| 101 |
return None, "no machine...", ""
|
| 102 |
except Exception as e:
|
| 103 |
print(e)
|
|
|
|
|
|
|
| 1 |
import cv2
|
| 2 |
from mtcnn.mtcnn import MTCNN
|
| 3 |
from utils import *
|
| 4 |
+
import requests
|
| 5 |
+
from urllib.parse import urlparse
|
| 6 |
|
| 7 |
|
| 8 |
cloth_examples = get_cloth_examples(hr=0)
|
|
|
|
| 21 |
"""
|
| 22 |
|
| 23 |
|
| 24 |
+
def is_http_resource_accessible(url):
|
| 25 |
+
"""
|
| 26 |
+
Check if HTTP resource is accessible
|
| 27 |
+
Returns True if accessible, False otherwise
|
| 28 |
+
"""
|
| 29 |
+
if not url or not isinstance(url, str):
|
| 30 |
+
return False
|
| 31 |
+
|
| 32 |
+
try:
|
| 33 |
+
# Parse URL to check if it's a valid HTTP/HTTPS URL
|
| 34 |
+
parsed = urlparse(url)
|
| 35 |
+
if parsed.scheme not in ['http', 'https']:
|
| 36 |
+
return False
|
| 37 |
+
|
| 38 |
+
# Make a HEAD request to check if resource exists
|
| 39 |
+
response = requests.head(url, timeout=5, allow_redirects=True)
|
| 40 |
+
return response.status_code == 200
|
| 41 |
+
except Exception as e:
|
| 42 |
+
print(f"Error checking resource accessibility: {e}")
|
| 43 |
+
return False
|
| 44 |
+
|
| 45 |
+
|
| 46 |
def onClick(cloth_image, pose_image, high_resolution, request: gr.Request):
|
| 47 |
if pose_image is None:
|
| 48 |
yield None, "no pose image found !", ""
|
|
|
|
| 101 |
return None, "fail to public you task", ""
|
| 102 |
|
| 103 |
print(client_ip, public_res['mid_result'])
|
| 104 |
+
# Check if mid_result resource is accessible
|
| 105 |
+
mid_result = public_res['mid_result'] if is_http_resource_accessible(public_res['mid_result']) else None
|
| 106 |
+
yield mid_result, f"task is processing, task id: {public_res['id']}, {public_res['msg']}", ""
|
| 107 |
|
| 108 |
max_try = 120*3
|
| 109 |
wait_s = 0.5
|
|
|
|
| 112 |
state = getInfRes(public_res['id'])
|
| 113 |
timestamp = int(time.time() * 1000)
|
| 114 |
if state is None:
|
| 115 |
+
mid_result = public_res['mid_result'] if is_http_resource_accessible(public_res['mid_result']) else None
|
| 116 |
+
result_url = mid_result + f"?t={timestamp}" if mid_result else None
|
| 117 |
+
yield result_url, "task query failed,", ""
|
| 118 |
elif state['status']=='PROCESSING':
|
| 119 |
+
mid_result = public_res['mid_result'] if is_http_resource_accessible(public_res['mid_result']) else None
|
| 120 |
+
result_url = mid_result + f"?t={timestamp}" if mid_result else None
|
| 121 |
+
yield result_url, f"task is processing, query {i}", ""
|
| 122 |
elif state['status']=='SUCCEED':
|
| 123 |
yield state['output1'] + f"?t={timestamp}", f"task finished, {state['msg']}", ""
|
| 124 |
return state['output1'] + f"?t={timestamp}", f"task finished, {state['msg']}", ""
|
|
|
|
| 126 |
yield None, f"task failed, {state['msg']}", ""
|
| 127 |
return None, f"task failed, {state['msg']}", ""
|
| 128 |
else:
|
| 129 |
+
mid_result = public_res['mid_result'] if is_http_resource_accessible(public_res['mid_result']) else None
|
| 130 |
+
result_url = mid_result + f"?t={timestamp}" if mid_result else None
|
| 131 |
+
yield result_url, f"task is on processing, query {i}", ""
|
| 132 |
return None, "no machine...", ""
|
| 133 |
except Exception as e:
|
| 134 |
print(e)
|