selfitcamera
commited on
Commit
•
e68a153
1
Parent(s):
d417cb0
init
Browse files- .DS_Store +0 -0
- Datas/.DS_Store +0 -0
- Datas/UserRecord_9/Ips/127.0.0.1.pkl +3 -0
- Datas/UserRecord_9/Tokens/f3beccd5-e00f-4af3-b442-efe7e8746899.pkl +3 -0
- Datas/task2/.DS_Store +0 -0
- Datas/task2/task2_showcase.zip +3 -0
- Datas/task2/task2_showcase/task2_out1.jpg +3 -0
- Datas/task2/task2_showcase/task2_street.webp +0 -0
- Datas/task3/.DS_Store +0 -0
- Datas/task3/temps.zip +3 -0
- Datas/task7/.DS_Store +0 -0
- Datas/task9/.DS_Store +0 -0
- Datas/task9/showcases/.DS_Store +0 -0
- Datas/task9/showcases/show0.jpg +3 -0
- Datas/task9/showcases/show1.webp +0 -0
- Datas/task9/showcases/show2.webp +0 -0
- Datas/task9/srcs/.DS_Store +0 -0
- Datas/task9/srcs/use1.jpg +3 -0
- Datas/task9/srcs/use2.jpg +3 -0
- Datas/task9/srcs/use3.jpg +3 -0
- Datas/task9/temps/.DS_Store +0 -0
- Datas/task9/temps/caption.jpg +3 -0
- __pycache__/config.cpython-312.pyc +0 -0
- __pycache__/utils.cpython-312.pyc +0 -0
- app.py +13 -4
- config.py +31 -13
- utils.py +18 -9
.DS_Store
CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
|
|
Datas/.DS_Store
CHANGED
Binary files a/Datas/.DS_Store and b/Datas/.DS_Store differ
|
|
Datas/UserRecord_9/Ips/127.0.0.1.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:da8a6fd81a6423329221bade2789a60a1df18a1fd4d58c650bae257cd4104e06
|
3 |
+
size 218
|
Datas/UserRecord_9/Tokens/f3beccd5-e00f-4af3-b442-efe7e8746899.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:35e0a937a52f61a660b50d2df8cd124d048507e6f08011cac3239733bde8ac8b
|
3 |
+
size 561
|
Datas/task2/.DS_Store
CHANGED
Binary files a/Datas/task2/.DS_Store and b/Datas/task2/.DS_Store differ
|
|
Datas/task2/task2_showcase.zip
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a78cd24de21a410869962ce968c79064faf2f669171d737ae6c7c3a827848998
|
3 |
+
size 377845
|
Datas/task2/task2_showcase/task2_out1.jpg
ADDED
Git LFS Details
|
Datas/task2/task2_showcase/task2_street.webp
ADDED
Datas/task3/.DS_Store
CHANGED
Binary files a/Datas/task3/.DS_Store and b/Datas/task3/.DS_Store differ
|
|
Datas/task3/temps.zip
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:406dbf7be2891d2c0d9d591f5b7825f7567fccf71f20d10540cdc68fc664e1a7
|
3 |
+
size 2043353
|
Datas/task7/.DS_Store
CHANGED
Binary files a/Datas/task7/.DS_Store and b/Datas/task7/.DS_Store differ
|
|
Datas/task9/.DS_Store
ADDED
Binary file (8.2 kB). View file
|
|
Datas/task9/showcases/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
Datas/task9/showcases/show0.jpg
ADDED
Git LFS Details
|
Datas/task9/showcases/show1.webp
ADDED
Datas/task9/showcases/show2.webp
ADDED
Datas/task9/srcs/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
Datas/task9/srcs/use1.jpg
ADDED
Git LFS Details
|
Datas/task9/srcs/use2.jpg
ADDED
Git LFS Details
|
Datas/task9/srcs/use3.jpg
ADDED
Git LFS Details
|
Datas/task9/temps/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
Datas/task9/temps/caption.jpg
ADDED
Git LFS Details
|
__pycache__/config.cpython-312.pyc
CHANGED
Binary files a/__pycache__/config.cpython-312.pyc and b/__pycache__/config.cpython-312.pyc differ
|
|
__pycache__/utils.cpython-312.pyc
CHANGED
Binary files a/__pycache__/utils.cpython-312.pyc and b/__pycache__/utils.cpython-312.pyc differ
|
|
app.py
CHANGED
@@ -43,13 +43,20 @@ def onClick(temp_image, user_image, caption_text, token_text,
|
|
43 |
else:
|
44 |
param4_text, param5_text = '', ''
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
# print("======> temp_image ", type(temp_image))
|
47 |
# print("======> user_image ", type(user_image))
|
48 |
# print("======> caption_text ", type(caption_text))
|
49 |
if temp_image is None:
|
50 |
yield None, "please choose a template!!!"
|
51 |
return None, "please choose a template!!!"
|
52 |
-
if user_image is None:
|
53 |
yield None, "please upload a photo!!!"
|
54 |
return None, "please upload a photo!!!"
|
55 |
|
@@ -68,7 +75,7 @@ def onClick(temp_image, user_image, caption_text, token_text,
|
|
68 |
|
69 |
# 上传用户照片
|
70 |
yield None, "start to upload, please wait..."
|
71 |
-
upload_url, uploadm_url = upload_user_img_mask(client_ip, user_image, user_mask)
|
72 |
if len(upload_url)==0:
|
73 |
yield None, "fail to upload"
|
74 |
return None, "fail to upload"
|
@@ -88,7 +95,7 @@ def onClick(temp_image, user_image, caption_text, token_text,
|
|
88 |
# time.sleep(2)
|
89 |
for i in range(max_try):
|
90 |
time.sleep(wait_s)
|
91 |
-
taskStatus = getTaskRes(taskId)
|
92 |
if taskStatus is None: continue
|
93 |
user_recorder.save_record(taskStatus, ip=client_ip, token=token_text)
|
94 |
|
@@ -145,6 +152,8 @@ with gr.Blocks(css=css) as demo:
|
|
145 |
user_image = gr.ImageEditor(value=None, type="numpy",
|
146 |
eraser=False, brush=brush ,layers=False, sources=['upload',],
|
147 |
transforms=[], label=UserLabel)
|
|
|
|
|
148 |
else:
|
149 |
user_image = gr.Image(value=None, type="numpy", label=UserLabel)
|
150 |
param4_text = gr.Textbox(value="0.5", interactive=True, label=Param4Label, visible=Param4Visible)
|
@@ -177,7 +186,7 @@ with gr.Blocks(css=css) as demo:
|
|
177 |
with gr.Row():
|
178 |
his_input3 = gr.HTML()
|
179 |
his_output3 = gr.HTML()
|
180 |
-
|
181 |
# outputs_onload = [his_input1, his_output1, his_input2, his_output2, his_input3, his_output3,
|
182 |
# MK02, run_button]
|
183 |
|
|
|
43 |
else:
|
44 |
param4_text, param5_text = '', ''
|
45 |
|
46 |
+
if taskType in ['8', '9']:
|
47 |
+
if len(caption_text)==0:
|
48 |
+
yield None, "Please enter caption !!! "
|
49 |
+
return None, "Please enter caption !!! "
|
50 |
+
if taskType=='9':
|
51 |
+
temp_image, param4_text = '1536x1024.jpg', 'realistic_image'
|
52 |
+
|
53 |
# print("======> temp_image ", type(temp_image))
|
54 |
# print("======> user_image ", type(user_image))
|
55 |
# print("======> caption_text ", type(caption_text))
|
56 |
if temp_image is None:
|
57 |
yield None, "please choose a template!!!"
|
58 |
return None, "please choose a template!!!"
|
59 |
+
if user_image is None and taskType not in ['8', '9']:
|
60 |
yield None, "please upload a photo!!!"
|
61 |
return None, "please upload a photo!!!"
|
62 |
|
|
|
75 |
|
76 |
# 上传用户照片
|
77 |
yield None, "start to upload, please wait..."
|
78 |
+
upload_url, uploadm_url = upload_user_img_mask(client_ip, user_image, user_mask, taskType)
|
79 |
if len(upload_url)==0:
|
80 |
yield None, "fail to upload"
|
81 |
return None, "fail to upload"
|
|
|
95 |
# time.sleep(2)
|
96 |
for i in range(max_try):
|
97 |
time.sleep(wait_s)
|
98 |
+
taskStatus = getTaskRes(taskId, taskType)
|
99 |
if taskStatus is None: continue
|
100 |
user_recorder.save_record(taskStatus, ip=client_ip, token=token_text)
|
101 |
|
|
|
152 |
user_image = gr.ImageEditor(value=None, type="numpy",
|
153 |
eraser=False, brush=brush ,layers=False, sources=['upload',],
|
154 |
transforms=[], label=UserLabel)
|
155 |
+
elif taskType in ['8', '9']:
|
156 |
+
user_image = gr.Image(value=temp_examples[0][0], type="numpy", label=UserLabel, interactive=False)
|
157 |
else:
|
158 |
user_image = gr.Image(value=None, type="numpy", label=UserLabel)
|
159 |
param4_text = gr.Textbox(value="0.5", interactive=True, label=Param4Label, visible=Param4Visible)
|
|
|
186 |
with gr.Row():
|
187 |
his_input3 = gr.HTML()
|
188 |
his_output3 = gr.HTML()
|
189 |
+
|
190 |
# outputs_onload = [his_input1, his_output1, his_input2, his_output2, his_input3, his_output3,
|
191 |
# MK02, run_button]
|
192 |
|
config.py
CHANGED
@@ -41,7 +41,7 @@ if taskType=="3":
|
|
41 |
Go to <a href='https://heybeauty.ai/extension' target='_blank'><b>HeyBeauty</b></a> for Faster and Free AI App! 🤗 .<br>
|
42 |
|
43 |
1. Please wait for a while after submitting the task, you will get the result within 30 seconds.
|
44 |
-
2. After exhausted all trial attempts, you can <a href='https://heybeauty.ai/
|
45 |
3. Share app with your friends and enjoy! 😊.<br>
|
46 |
"""
|
47 |
# 组件信息
|
@@ -63,7 +63,7 @@ elif taskType=="4":
|
|
63 |
Go to <a href='https://heybeauty.ai/extension' target='_blank'><b>HeyBeauty</b></a> for Faster and Free AI App! 🤗 .<br>
|
64 |
|
65 |
1. Please wait for a while after submitting the task, you will get the result within 30 seconds.
|
66 |
-
2. After exhausted all trial attempts, you can <a href='https://heybeauty.ai/
|
67 |
3. Share app with your friends and enjoy! 😊.<br>
|
68 |
"""
|
69 |
# 组件信息
|
@@ -84,7 +84,7 @@ elif taskType=="6":
|
|
84 |
Go to <a href='https://heybeauty.ai/extension' target='_blank'><b>HeyBeauty</b></a> for Faster and Free AI App! 🤗 .<br>
|
85 |
|
86 |
1. Please wait for a while after submitting the task, you will get the result within 30 seconds.
|
87 |
-
2. After exhausted all trial attempts, you can <a href='https://heybeauty.ai/
|
88 |
3. Share app with your friends and enjoy! 😊.<br>
|
89 |
"""
|
90 |
# 组件信息
|
@@ -106,7 +106,7 @@ elif taskType=="5":
|
|
106 |
Go to <a href='https://heybeauty.ai/extension' target='_blank'><b>HeyBeauty</b></a> for Faster and Free AI App! 🤗 .<br>
|
107 |
|
108 |
1. Please wait for a while after submitting the task, you will get the result within 30 seconds.
|
109 |
-
2. After exhausted all trial attempts, you can <a href='https://heybeauty.ai/
|
110 |
3. Share app with your friends and enjoy! 😊.<br>
|
111 |
"""
|
112 |
# 组件信息
|
@@ -128,7 +128,7 @@ elif taskType=="1":
|
|
128 |
Go to <a href='https://heybeauty.ai/extension' target='_blank'><b>HeyBeauty</b></a> for Faster and Free AI App! 🤗 .<br>
|
129 |
|
130 |
1. Please wait for a while after submitting the task, you will get the result within 30 seconds.
|
131 |
-
2. After exhausted all trial attempts, you can <a href='https://heybeauty.ai/
|
132 |
3. Share app with your friends and enjoy! 😊.<br>
|
133 |
"""
|
134 |
# 组件信息
|
@@ -151,7 +151,7 @@ elif taskType=="2":
|
|
151 |
Go to <a href='https://heybeauty.ai/extension' target='_blank'><b>HeyBeauty</b></a> for Faster and Free AI App! 🤗 .<br>
|
152 |
|
153 |
1. Please wait for a while after submitting the task, you will get the result within 30 seconds.
|
154 |
-
2. After exhausted all trial attempts, you can <a href='https://heybeauty.ai/
|
155 |
3. Share app with your friends and enjoy! 😊.<br>
|
156 |
"""
|
157 |
# 组件信息
|
@@ -174,7 +174,7 @@ elif taskType=="7":
|
|
174 |
Go to <a href='https://heybeauty.ai/extension' target='_blank'><b>HeyBeauty</b></a> for Faster and Free AI App! 🤗 .<br>
|
175 |
|
176 |
1. Please wait for a while after submitting the task, you will get the result within 30 seconds.
|
177 |
-
2. After exhausted all trial attempts, you can <a href='https://heybeauty.ai/
|
178 |
3. Share app with your friends and enjoy! 😊.<br>
|
179 |
"""
|
180 |
# 组件信息
|
@@ -184,10 +184,28 @@ elif taskType=="7":
|
|
184 |
CaptionLabel = "English caption text (required)"
|
185 |
CapVisible = True
|
186 |
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
|
192 |
else:
|
193 |
# 是否显示token输入框
|
@@ -202,13 +220,13 @@ else:
|
|
202 |
|
203 |
<b>Official 🤗 Gradio demo</b> for <a href='https://github.com/selfitcamera/Outfit-Anyone-in-the-Wild' target='_blank'><b>Product poster background generation</b></a>.<br>
|
204 |
1. Please wait for a while after submitting the task, you will get the result within 30 seconds.
|
205 |
-
2. <a href='https://heybeauty.ai/
|
206 |
3. Share app with your friends and enjoy! 😊.<br>
|
207 |
"""
|
208 |
|
209 |
if is_show_token:
|
210 |
# 当试用次数耗尽,显示的信息
|
211 |
-
no_more_attempts = "You've exhausted all trial attempts. [Enter Your API Key](https://heybeauty.ai/
|
212 |
else:
|
213 |
# 当试用次数耗尽,显示的信息
|
214 |
no_more_attempts = "You've exhausted all trial attempts."
|
|
|
41 |
Go to <a href='https://heybeauty.ai/extension' target='_blank'><b>HeyBeauty</b></a> for Faster and Free AI App! 🤗 .<br>
|
42 |
|
43 |
1. Please wait for a while after submitting the task, you will get the result within 30 seconds.
|
44 |
+
2. After exhausted all trial attempts, you can <a href='https://heybeauty.ai/home/apikeys' target='_blank'><b>find your api key here</b></a> .<br>
|
45 |
3. Share app with your friends and enjoy! 😊.<br>
|
46 |
"""
|
47 |
# 组件信息
|
|
|
63 |
Go to <a href='https://heybeauty.ai/extension' target='_blank'><b>HeyBeauty</b></a> for Faster and Free AI App! 🤗 .<br>
|
64 |
|
65 |
1. Please wait for a while after submitting the task, you will get the result within 30 seconds.
|
66 |
+
2. After exhausted all trial attempts, you can <a href='https://heybeauty.ai/home/apikeys' target='_blank'><b>find your api key here</b></a> .<br>
|
67 |
3. Share app with your friends and enjoy! 😊.<br>
|
68 |
"""
|
69 |
# 组件信息
|
|
|
84 |
Go to <a href='https://heybeauty.ai/extension' target='_blank'><b>HeyBeauty</b></a> for Faster and Free AI App! 🤗 .<br>
|
85 |
|
86 |
1. Please wait for a while after submitting the task, you will get the result within 30 seconds.
|
87 |
+
2. After exhausted all trial attempts, you can <a href='https://heybeauty.ai/home/apikeys' target='_blank'><b>find your api key here</b></a> .<br>
|
88 |
3. Share app with your friends and enjoy! 😊.<br>
|
89 |
"""
|
90 |
# 组件信息
|
|
|
106 |
Go to <a href='https://heybeauty.ai/extension' target='_blank'><b>HeyBeauty</b></a> for Faster and Free AI App! 🤗 .<br>
|
107 |
|
108 |
1. Please wait for a while after submitting the task, you will get the result within 30 seconds.
|
109 |
+
2. After exhausted all trial attempts, you can <a href='https://heybeauty.ai/home/apikeys' target='_blank'><b>find your api key here</b></a> .<br>
|
110 |
3. Share app with your friends and enjoy! 😊.<br>
|
111 |
"""
|
112 |
# 组件信息
|
|
|
128 |
Go to <a href='https://heybeauty.ai/extension' target='_blank'><b>HeyBeauty</b></a> for Faster and Free AI App! 🤗 .<br>
|
129 |
|
130 |
1. Please wait for a while after submitting the task, you will get the result within 30 seconds.
|
131 |
+
2. After exhausted all trial attempts, you can <a href='https://heybeauty.ai/home/apikeys' target='_blank'><b>find your api key here</b></a> .<br>
|
132 |
3. Share app with your friends and enjoy! 😊.<br>
|
133 |
"""
|
134 |
# 组件信息
|
|
|
151 |
Go to <a href='https://heybeauty.ai/extension' target='_blank'><b>HeyBeauty</b></a> for Faster and Free AI App! 🤗 .<br>
|
152 |
|
153 |
1. Please wait for a while after submitting the task, you will get the result within 30 seconds.
|
154 |
+
2. After exhausted all trial attempts, you can <a href='https://heybeauty.ai/home/apikeys' target='_blank'><b>find your api key here</b></a> .<br>
|
155 |
3. Share app with your friends and enjoy! 😊.<br>
|
156 |
"""
|
157 |
# 组件信息
|
|
|
174 |
Go to <a href='https://heybeauty.ai/extension' target='_blank'><b>HeyBeauty</b></a> for Faster and Free AI App! 🤗 .<br>
|
175 |
|
176 |
1. Please wait for a while after submitting the task, you will get the result within 30 seconds.
|
177 |
+
2. After exhausted all trial attempts, you can <a href='https://heybeauty.ai/home/apikeys' target='_blank'><b>find your api key here</b></a> .<br>
|
178 |
3. Share app with your friends and enjoy! 😊.<br>
|
179 |
"""
|
180 |
# 组件信息
|
|
|
184 |
CaptionLabel = "English caption text (required)"
|
185 |
CapVisible = True
|
186 |
|
187 |
+
elif taskType=="9":
|
188 |
+
# 是否显示token输入框
|
189 |
+
is_show_token = True
|
190 |
+
TempInter = False
|
191 |
+
# 标题
|
192 |
+
title = r"""
|
193 |
+
<h1 align="center">Red Panda Image Generator by Recraft</h1>
|
194 |
+
"""
|
195 |
+
# 标题下的描述
|
196 |
+
description = r"""
|
197 |
+
Go to <a href='https://heybeauty.ai/red-panda-recraft' target='_blank'><b>Recraft</b></a> for Faster and Free Generation! 🤗 .<br>
|
198 |
+
|
199 |
+
1. Please wait for a while after submitting the task, you will get the result within 30 seconds.
|
200 |
+
2. After exhausted all trial attempts, you can <a href='https://heybeauty.ai/home/apikeys' target='_blank'><b>find your api key here</b></a> .<br>
|
201 |
+
3. Share app with your friends and enjoy! 😊.<br>
|
202 |
+
"""
|
203 |
+
# 组件信息
|
204 |
+
TempLabel = "guide"
|
205 |
+
TempVisible = True
|
206 |
+
UserLabel = "upload and paint photo"
|
207 |
+
CaptionLabel = "caption text (required, any language)"
|
208 |
+
CapVisible = True
|
209 |
|
210 |
else:
|
211 |
# 是否显示token输入框
|
|
|
220 |
|
221 |
<b>Official 🤗 Gradio demo</b> for <a href='https://github.com/selfitcamera/Outfit-Anyone-in-the-Wild' target='_blank'><b>Product poster background generation</b></a>.<br>
|
222 |
1. Please wait for a while after submitting the task, you will get the result within 30 seconds.
|
223 |
+
2. <a href='https://heybeauty.ai/home/apikeys' target='_blank'><b>You can find your api key here</b></a> .<br>
|
224 |
3. Share app with your friends and enjoy! 😊.<br>
|
225 |
"""
|
226 |
|
227 |
if is_show_token:
|
228 |
# 当试用次数耗尽,显示的信息
|
229 |
+
no_more_attempts = "You've exhausted all trial attempts. [Enter Your API Key](https://heybeauty.ai/home/apikeys) to continue..."
|
230 |
else:
|
231 |
# 当试用次数耗尽,显示的信息
|
232 |
no_more_attempts = "You've exhausted all trial attempts."
|
utils.py
CHANGED
@@ -39,15 +39,16 @@ def checkToken(token):
|
|
39 |
'''
|
40 |
输入token,检查token是否合法
|
41 |
'''
|
42 |
-
return False
|
43 |
-
params = {'
|
|
|
44 |
session = requests.session()
|
45 |
-
ret = requests.post(f"{tokenUrl}", data=json.dumps(params))
|
46 |
print(ret)
|
47 |
res = False
|
48 |
if ret.status_code==200:
|
49 |
-
if '
|
50 |
-
res = (ret.json()['
|
51 |
else:
|
52 |
print(ret.json(), ret.status_code, 'call token failed')
|
53 |
return res
|
@@ -86,7 +87,7 @@ class UserRecorder(object):
|
|
86 |
if token_valid:
|
87 |
return True, ""
|
88 |
else:
|
89 |
-
return False, "api key is invalid"
|
90 |
else:
|
91 |
_, total_n, _ = self.get_record(ip=ip, token=token)
|
92 |
if total_n>=LimitTask:
|
@@ -196,6 +197,12 @@ def get_showcase_examples(taskType):
|
|
196 |
examples=[
|
197 |
["task7/temps/task7.webp", "task7/srcs/305.jpg", "task7/showcases/task7out.jpg"],
|
198 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
|
200 |
for i in range(len(examples)):
|
201 |
for j in range(len(examples[i])):
|
@@ -208,7 +215,9 @@ def get_result_example(cloth_id, pose_id):
|
|
208 |
res_path = os.path.join(result_dir, f"{cloth_id}_{pose_id}.jpg")
|
209 |
return res_path
|
210 |
|
211 |
-
def upload_user_img_mask(clientIp, img, mask=None):
|
|
|
|
|
212 |
timeId = int( str(time.time()).replace(".", "") )+random.randint(1000, 9999)
|
213 |
fileName = clientIp.replace(".", "")+str(timeId)+".jpg"
|
214 |
local_path = os.path.join(tmpFolder, fileName)
|
@@ -268,8 +277,8 @@ def publicSelfitTask(image, mask, temp_image, caption_text, param4_text, param5_
|
|
268 |
else:
|
269 |
print(ret.json(), ret.status_code, 'call public failed')
|
270 |
|
271 |
-
def getTaskRes(taskId):
|
272 |
-
params = {'id':taskId}
|
273 |
session = requests.session()
|
274 |
ret = requests.post(f"{apiUrl}/status", data=json.dumps(params))
|
275 |
if ret.status_code==200:
|
|
|
39 |
'''
|
40 |
输入token,检查token是否合法
|
41 |
'''
|
42 |
+
# return False
|
43 |
+
params = {'trans_type':'hf_space', 'cost_credits':1}
|
44 |
+
headers = {"Authorization": f"Bearer {token}"}
|
45 |
session = requests.session()
|
46 |
+
ret = requests.post(f"{tokenUrl}", data=json.dumps(params), headers=headers)
|
47 |
print(ret)
|
48 |
res = False
|
49 |
if ret.status_code==200:
|
50 |
+
if 'left_credits' in ret.json():
|
51 |
+
res = (ret.json()['left_credits'])>0
|
52 |
else:
|
53 |
print(ret.json(), ret.status_code, 'call token failed')
|
54 |
return res
|
|
|
87 |
if token_valid:
|
88 |
return True, ""
|
89 |
else:
|
90 |
+
return False, "faild, api key is invalid"
|
91 |
else:
|
92 |
_, total_n, _ = self.get_record(ip=ip, token=token)
|
93 |
if total_n>=LimitTask:
|
|
|
197 |
examples=[
|
198 |
["task7/temps/task7.webp", "task7/srcs/305.jpg", "task7/showcases/task7out.jpg"],
|
199 |
]
|
200 |
+
elif taskType=="9":
|
201 |
+
examples=[
|
202 |
+
["task9/temps/caption.jpg", "task9/srcs/use1.jpg", "task9/showcases/show0.jpg"],
|
203 |
+
["task9/temps/caption.jpg", "task9/srcs/use2.jpg", "task9/showcases/show1.webp"],
|
204 |
+
["task9/temps/caption.jpg", "task9/srcs/use3.jpg", "task9/showcases/show2.webp"],
|
205 |
+
]
|
206 |
|
207 |
for i in range(len(examples)):
|
208 |
for j in range(len(examples[i])):
|
|
|
215 |
res_path = os.path.join(result_dir, f"{cloth_id}_{pose_id}.jpg")
|
216 |
return res_path
|
217 |
|
218 |
+
def upload_user_img_mask(clientIp, img, mask=None, taskType='1'):
|
219 |
+
if taskType in ['8', '9']:
|
220 |
+
return "img", ''
|
221 |
timeId = int( str(time.time()).replace(".", "") )+random.randint(1000, 9999)
|
222 |
fileName = clientIp.replace(".", "")+str(timeId)+".jpg"
|
223 |
local_path = os.path.join(tmpFolder, fileName)
|
|
|
277 |
else:
|
278 |
print(ret.json(), ret.status_code, 'call public failed')
|
279 |
|
280 |
+
def getTaskRes(taskId, taskType):
|
281 |
+
params = {'id':taskId, 'task_type':taskType}
|
282 |
session = requests.session()
|
283 |
ret = requests.post(f"{apiUrl}/status", data=json.dumps(params))
|
284 |
if ret.status_code==200:
|