selfitcamera
commited on
Commit
•
f30af9d
1
Parent(s):
3d0272c
init
Browse files- .DS_Store +0 -0
- Datas/UserRecord_6/Ips/127.0.0.1.pkl +2 -2
- Datas/UserRecord_7/Ips/127.0.0.1.pkl +3 -0
- Datas/task7/.DS_Store +0 -0
- Datas/task7/showcases/.DS_Store +0 -0
- Datas/task7/showcases/out1.jpg +3 -0
- Datas/task7/srcs/.DS_Store +0 -0
- Datas/task7/srcs/caption.jpg +3 -0
- Datas/task7/srcs/street.webp +0 -0
- Datas/task7/temps/.DS_Store +0 -0
- Datas/task7/temps/caption.jpg +3 -0
- __pycache__/config.cpython-312.pyc +0 -0
- __pycache__/utils.cpython-312.pyc +0 -0
- app.py +24 -7
- config.py +37 -0
- utils.py +7 -6
.DS_Store
CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
|
|
Datas/UserRecord_6/Ips/127.0.0.1.pkl
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9d5a1a961259242c785bddccab82cd792a956e381fa778c0554b9f61d8812ba9
|
3 |
+
size 1091
|
Datas/UserRecord_7/Ips/127.0.0.1.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5f698d73c5c183e23df6860559e0f717e5ec93a01f6b8273dd50f2049da4c183
|
3 |
+
size 745
|
Datas/task7/.DS_Store
ADDED
Binary file (10.2 kB). View file
|
|
Datas/task7/showcases/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
Datas/task7/showcases/out1.jpg
ADDED
Git LFS Details
|
Datas/task7/srcs/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
Datas/task7/srcs/caption.jpg
ADDED
Git LFS Details
|
Datas/task7/srcs/street.webp
ADDED
Datas/task7/temps/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
Datas/task7/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
@@ -15,7 +15,8 @@ css = """
|
|
15 |
"""
|
16 |
|
17 |
|
18 |
-
def onClick(temp_image, user_image, caption_text, token_text,
|
|
|
19 |
|
20 |
user_mask = None
|
21 |
if taskType=='2':
|
@@ -30,12 +31,24 @@ def onClick(temp_image, user_image, caption_text, token_text, request: gr.Reques
|
|
30 |
yield None, "please draw a area!!!"
|
31 |
return None, "please draw a area!!!"
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
print("======> temp_image ", type(temp_image))
|
34 |
print("======> user_image ", type(user_image))
|
35 |
print("======> caption_text ", type(caption_text))
|
36 |
if temp_image is None:
|
37 |
-
yield None, "please choose a template
|
38 |
-
return None, "please choose a template
|
39 |
if user_image is None:
|
40 |
yield None, "please upload a photo!!!"
|
41 |
return None, "please upload a photo!!!"
|
@@ -61,7 +74,8 @@ def onClick(temp_image, user_image, caption_text, token_text, request: gr.Reques
|
|
61 |
|
62 |
# return
|
63 |
# 发布任务
|
64 |
-
taskId = publicSelfitTask(upload_url, uploadm_url, temp_image,
|
|
|
65 |
if not taskId:
|
66 |
yield None, "fail to public task..."
|
67 |
return None, "fail to public task..."
|
@@ -112,7 +126,7 @@ with gr.Blocks(css=css) as demo:
|
|
112 |
with gr.Column():
|
113 |
with gr.Column():
|
114 |
temp_image = gr.Image(sources='clipboard', type="filepath", label=TempLabel,
|
115 |
-
value=temp_examples[0][0], visible=TempVisible)
|
116 |
temp_example = gr.Examples(inputs=[temp_image], examples_per_page=9,
|
117 |
examples=temp_examples, visible=TempVisible)
|
118 |
with gr.Column():
|
@@ -124,7 +138,10 @@ with gr.Blocks(css=css) as demo:
|
|
124 |
transforms=[], label=UserLabel)
|
125 |
else:
|
126 |
user_image = gr.Image(value=None, type="numpy", label=UserLabel)
|
|
|
|
|
127 |
caption_text = gr.Textbox(value="", interactive=True, label=CaptionLabel, visible=CapVisible)
|
|
|
128 |
with gr.Column():
|
129 |
with gr.Column():
|
130 |
res_image = gr.Image(label="generate image", value=None, type="filepath")
|
@@ -155,8 +172,8 @@ with gr.Blocks(css=css) as demo:
|
|
155 |
outputs_onload = [his_input1, his_output1, his_input2, his_output2, his_input3, his_output3,
|
156 |
MK02, run_button]
|
157 |
|
158 |
-
run_button.click(fn=onClick, inputs=[temp_image, user_image, caption_text,
|
159 |
-
|
160 |
|
161 |
refresh_button.click(fn=onLoad, inputs=[token_text], outputs=outputs_onload)
|
162 |
|
|
|
15 |
"""
|
16 |
|
17 |
|
18 |
+
def onClick(temp_image, user_image, caption_text, token_text,
|
19 |
+
param4_text, param5_text, request: gr.Request):
|
20 |
|
21 |
user_mask = None
|
22 |
if taskType=='2':
|
|
|
31 |
yield None, "please draw a area!!!"
|
32 |
return None, "please draw a area!!!"
|
33 |
|
34 |
+
if taskType=='7':
|
35 |
+
try:
|
36 |
+
param4_text, param5_text = str(float(param4_text)), str(float(param5_text))
|
37 |
+
except ValueError:
|
38 |
+
yield None, "Invalid width/height: Please enter a valid float"
|
39 |
+
return None, "Invalid width/height: Please enter a valid float"
|
40 |
+
if len(caption_text)==0:
|
41 |
+
yield None, "Please enter English caption text !!! "
|
42 |
+
return None, "Please enter English caption 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!!!"
|
|
|
74 |
|
75 |
# return
|
76 |
# 发布任务
|
77 |
+
taskId = publicSelfitTask(upload_url, uploadm_url, temp_image,
|
78 |
+
caption_text, param4_text, param5_text)
|
79 |
if not taskId:
|
80 |
yield None, "fail to public task..."
|
81 |
return None, "fail to public task..."
|
|
|
126 |
with gr.Column():
|
127 |
with gr.Column():
|
128 |
temp_image = gr.Image(sources='clipboard', type="filepath", label=TempLabel,
|
129 |
+
value=temp_examples[0][0], visible=TempVisible, interactive=TempInter)
|
130 |
temp_example = gr.Examples(inputs=[temp_image], examples_per_page=9,
|
131 |
examples=temp_examples, visible=TempVisible)
|
132 |
with gr.Column():
|
|
|
138 |
transforms=[], label=UserLabel)
|
139 |
else:
|
140 |
user_image = gr.Image(value=None, type="numpy", label=UserLabel)
|
141 |
+
param4_text = gr.Textbox(value="0.5", interactive=True, label=Param4Label, visible=Param4Visible)
|
142 |
+
param5_text = gr.Textbox(value="0.5", interactive=True, label=Param5Label, visible=Param5Visible)
|
143 |
caption_text = gr.Textbox(value="", interactive=True, label=CaptionLabel, visible=CapVisible)
|
144 |
+
|
145 |
with gr.Column():
|
146 |
with gr.Column():
|
147 |
res_image = gr.Image(label="generate image", value=None, type="filepath")
|
|
|
172 |
outputs_onload = [his_input1, his_output1, his_input2, his_output2, his_input3, his_output3,
|
173 |
MK02, run_button]
|
174 |
|
175 |
+
run_button.click(fn=onClick, inputs=[temp_image, user_image, caption_text,
|
176 |
+
token_text, param4_text, param5_text], outputs=[res_image, info_text])
|
177 |
|
178 |
refresh_button.click(fn=onLoad, inputs=[token_text], outputs=outputs_onload)
|
179 |
|
config.py
CHANGED
@@ -23,6 +23,11 @@ except Exception as e:
|
|
23 |
|
24 |
|
25 |
CapVisible = True
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
if taskType=="3":
|
28 |
# 是否显示token输入框
|
@@ -47,6 +52,7 @@ if taskType=="3":
|
|
47 |
|
48 |
elif taskType=="4":
|
49 |
# 是否显示token输入框
|
|
|
50 |
is_show_token = True
|
51 |
# 标题
|
52 |
title = r"""
|
@@ -90,6 +96,7 @@ elif taskType=="6":
|
|
90 |
elif taskType=="5":
|
91 |
# 是否显示token输入框
|
92 |
is_show_token = True
|
|
|
93 |
# 标题
|
94 |
title = r"""
|
95 |
<h1 align="center">Selfit AI App: Poster(human) Background Swap</h1>
|
@@ -111,6 +118,7 @@ elif taskType=="5":
|
|
111 |
elif taskType=="1":
|
112 |
# 是否显示token输入框
|
113 |
is_show_token = True
|
|
|
114 |
# 标题
|
115 |
title = r"""
|
116 |
<h1 align="center">Selfit AI App: Object Segment</h1>
|
@@ -133,6 +141,7 @@ elif taskType=="1":
|
|
133 |
elif taskType=="2":
|
134 |
# 是否显示token输入框
|
135 |
is_show_token = True
|
|
|
136 |
# 标题
|
137 |
title = r"""
|
138 |
<h1 align="center">Selfit AI App: Object Remove</h1>
|
@@ -152,6 +161,34 @@ elif taskType=="2":
|
|
152 |
CaptionLabel = "English caption text (optional)"
|
153 |
CapVisible = False
|
154 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
else:
|
156 |
# 是否显示token输入框
|
157 |
is_show_token = False
|
|
|
23 |
|
24 |
|
25 |
CapVisible = True
|
26 |
+
Param4Label = ""
|
27 |
+
Param4Visible = False
|
28 |
+
Param5Label = ""
|
29 |
+
Param5Visible = False
|
30 |
+
TempInter = True
|
31 |
|
32 |
if taskType=="3":
|
33 |
# 是否显示token输入框
|
|
|
52 |
|
53 |
elif taskType=="4":
|
54 |
# 是否显示token输入框
|
55 |
+
TempInter = False
|
56 |
is_show_token = True
|
57 |
# 标题
|
58 |
title = r"""
|
|
|
96 |
elif taskType=="5":
|
97 |
# 是否显示token输入框
|
98 |
is_show_token = True
|
99 |
+
TempInter = False
|
100 |
# 标题
|
101 |
title = r"""
|
102 |
<h1 align="center">Selfit AI App: Poster(human) Background Swap</h1>
|
|
|
118 |
elif taskType=="1":
|
119 |
# 是否显示token输入框
|
120 |
is_show_token = True
|
121 |
+
TempInter = False
|
122 |
# 标题
|
123 |
title = r"""
|
124 |
<h1 align="center">Selfit AI App: Object Segment</h1>
|
|
|
141 |
elif taskType=="2":
|
142 |
# 是否显示token输入框
|
143 |
is_show_token = True
|
144 |
+
TempInter = False
|
145 |
# 标题
|
146 |
title = r"""
|
147 |
<h1 align="center">Selfit AI App: Object Remove</h1>
|
|
|
161 |
CaptionLabel = "English caption text (optional)"
|
162 |
CapVisible = False
|
163 |
|
164 |
+
elif taskType=="7":
|
165 |
+
# 是否显示token输入框
|
166 |
+
is_show_token = True
|
167 |
+
TempInter = False
|
168 |
+
# 标题
|
169 |
+
title = r"""
|
170 |
+
<h1 align="center">Selfit AI App: Image Outpaint</h1>
|
171 |
+
"""
|
172 |
+
# 标题下的描述
|
173 |
+
description = r"""
|
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/keys' target='_blank'><b>find your api key here</b></a> .<br>
|
178 |
+
3. Share app with your friends and enjoy! 😊.<br>
|
179 |
+
"""
|
180 |
+
# 组件信息
|
181 |
+
TempLabel = "guide"
|
182 |
+
TempVisible = True
|
183 |
+
UserLabel = "upload and paint photo"
|
184 |
+
CaptionLabel = "English caption text (required)"
|
185 |
+
CapVisible = True
|
186 |
+
|
187 |
+
Param4Label = "How much to expand width (0 - 2)"
|
188 |
+
Param4Visible = True
|
189 |
+
Param5Label = "How much to expand height (0 - 2)"
|
190 |
+
Param5Visible = True
|
191 |
+
|
192 |
else:
|
193 |
# 是否显示token输入框
|
194 |
is_show_token = False
|
utils.py
CHANGED
@@ -192,6 +192,10 @@ def get_showcase_examples(taskType):
|
|
192 |
examples=[
|
193 |
["task2/temps/caption.jpg", "task2/srcs/street.webp", "task2/showcases/out1.jpg"],
|
194 |
]
|
|
|
|
|
|
|
|
|
195 |
|
196 |
for i in range(len(examples)):
|
197 |
for j in range(len(examples[i])):
|
@@ -249,14 +253,11 @@ def upload_user_img_mask(clientIp, img, mask=None):
|
|
249 |
return res, uploadm_url
|
250 |
|
251 |
|
252 |
-
def publicSelfitTask(image, mask, temp_image, caption_text):
|
253 |
-
|
254 |
-
temp_name = ''
|
255 |
-
else:
|
256 |
-
temp_name = os.path.basename(temp_image).split('.')[0]
|
257 |
params = {'openId':openId, 'apiKey':apiKey, 'image':image, 'mask':mask,
|
258 |
"image_type":"2", "task_type":taskType, 'param1':temp_name,
|
259 |
-
'param2':str(caption_text), 'param3':"1", 'param4':
|
260 |
session = requests.session()
|
261 |
ret = requests.post(f"{apiUrl}/public", data=json.dumps(params))
|
262 |
print(ret)
|
|
|
192 |
examples=[
|
193 |
["task2/temps/caption.jpg", "task2/srcs/street.webp", "task2/showcases/out1.jpg"],
|
194 |
]
|
195 |
+
elif taskType=="7":
|
196 |
+
examples=[
|
197 |
+
["task2/temps/caption.jpg", "task2/srcs/street.webp", "task2/showcases/out1.jpg"],
|
198 |
+
]
|
199 |
|
200 |
for i in range(len(examples)):
|
201 |
for j in range(len(examples[i])):
|
|
|
253 |
return res, uploadm_url
|
254 |
|
255 |
|
256 |
+
def publicSelfitTask(image, mask, temp_image, caption_text, param4_text, param5_text):
|
257 |
+
temp_name = os.path.basename(temp_image).split('.')[0]
|
|
|
|
|
|
|
258 |
params = {'openId':openId, 'apiKey':apiKey, 'image':image, 'mask':mask,
|
259 |
"image_type":"2", "task_type":taskType, 'param1':temp_name,
|
260 |
+
'param2':str(caption_text), 'param3':"1", 'param4':param4_text, 'param5':param5_text}
|
261 |
session = requests.session()
|
262 |
ret = requests.post(f"{apiUrl}/public", data=json.dumps(params))
|
263 |
print(ret)
|