selfitcamera commited on
Commit
57c3043
·
1 Parent(s): 091515e
Files changed (4) hide show
  1. __pycache__/utils.cpython-310.pyc +0 -0
  2. app.py +32 -48
  3. requirements.txt +3 -1
  4. utils.py +9 -27
__pycache__/utils.cpython-310.pyc CHANGED
Binary files a/__pycache__/utils.cpython-310.pyc and b/__pycache__/utils.cpython-310.pyc differ
 
app.py CHANGED
@@ -1,4 +1,6 @@
1
 
 
 
2
  from utils import *
3
 
4
 
@@ -6,21 +8,19 @@ cloth_examples = get_cloth_examples(hr=0)
6
  cloth_hr_examples = get_cloth_examples(hr=1)
7
  pose_examples = get_pose_examples()
8
  tip1, tip2 = get_tips()
 
9
 
10
  # Description
11
  title = r"""
12
- <h1 align="center">Outfit Anyway: Best customer try-on experience ever</h1>
13
  """
14
 
15
  description = r"""
16
- <b>Test results on </b> <a href='https://selfit-deploy-1256039085.cos.accelerate.myqcloud.com/ClothData/Publics/Shows/shows/man_v2/man_v2.html' target='_blank'><b>man01</b></a>.<br>
17
- <b>Test results on </b> <a href='https://selfit-deploy-1256039085.cos.accelerate.myqcloud.com/ClothData/Publics/Shows/shows/woman_v2/woman_v2.html' target='_blank'><b>woman01</b></a>.<br>
18
  """
19
 
20
- mk_guide = ""
21
 
22
-
23
- def onClick(cloth_image, pose_image, high_resolution):
24
  if pose_image is None:
25
  yield None, "no pose image found !", ""
26
  return None, "no pose image found !", ""
@@ -32,11 +32,35 @@ def onClick(cloth_image, pose_image, high_resolution):
32
  cloth_id = int(os.path.basename(cloth_image).split(".")[0])
33
 
34
  try:
35
- client_ip = '8.8.8.8'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  yield None, "begin to upload ", ""
37
 
38
  timeId = int( str(time.time()).replace(".", "") )+random.randint(1000, 9999)
39
- upload_url = upload_pose_img(ApiUrl, OpenId, ApiKey, client_ip, timeId, pose_image)
40
  # exit(0)
41
  yield None, "begin to public task ", ""
42
  # return None, "begin to public task ", ""
@@ -111,49 +135,9 @@ with gr.Blocks() as demo:
111
  res_image = gr.Image(label="result image", value=None, type="filepath")
112
  MK01 = gr.Markdown()
113
 
114
-
115
- # with gr.Tab('history'):
116
-
117
- # with gr.Row(): # 用 Row 包裹按钮
118
- # with gr.Column(scale=0.5): # Button 占用 Row 的一半
119
- # refresh_button = gr.Button("Refresh History", size="small")
120
- # MK02 = gr.Markdown(value="") # 示例 Markdown 内容
121
-
122
- # # with gr.Row():
123
- # # MK02 = gr.Markdown()
124
-
125
- # with gr.Row():
126
- # his_pose_image1 = gr.HTML()
127
- # his_res_image1 = gr.HTML()
128
-
129
- # with gr.Row():
130
- # his_pose_image2 = gr.HTML()
131
- # his_res_image2 = gr.HTML()
132
-
133
- # with gr.Row():
134
- # his_pose_image3 = gr.HTML()
135
- # his_res_image3 = gr.HTML()
136
-
137
- # with gr.Row():
138
- # his_pose_image4 = gr.HTML()
139
- # his_res_image4 = gr.HTML()
140
-
141
- # with gr.Row():
142
- # his_pose_image5 = gr.HTML()
143
- # his_res_image5 = gr.HTML()
144
-
145
  run_button.click(fn=onClick, inputs=[cloth_image, pose_image, high_resolution],
146
  outputs=[res_image, info_text, MK01])
147
 
148
- # refresh_button.click(fn=onLoad, inputs=[], outputs=[his_pose_image1, his_res_image1,
149
- # his_pose_image2, his_res_image2, his_pose_image3, his_res_image3,
150
- # his_pose_image4, his_res_image4, his_pose_image5, his_res_image5,
151
- # MK02])
152
-
153
- # demo.load(onLoad, inputs=[], outputs=[his_pose_image1, his_res_image1,
154
- # his_pose_image2, his_res_image2, his_pose_image3, his_res_image3,
155
- # his_pose_image4, his_res_image4, his_pose_image5, his_res_image5,
156
- # MK02])
157
 
158
  if __name__ == "__main__":
159
 
 
1
 
2
+ import cv2
3
+ from mtcnn.mtcnn import MTCNN
4
  from utils import *
5
 
6
 
 
8
  cloth_hr_examples = get_cloth_examples(hr=1)
9
  pose_examples = get_pose_examples()
10
  tip1, tip2 = get_tips()
11
+ face_detector = MTCNN()
12
 
13
  # Description
14
  title = r"""
15
+ <h1 align="center">Outfit Anyway: Best customer try-on You ever See</h1>
16
  """
17
 
18
  description = r"""
19
+ <b>Join discord to know more about </b> <a href='https://discord.com/invite/QgJWCtSG58' target='_blank'><b> heybeauty prebuy vton solution</b></a>.<br>
 
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 !", ""
26
  return None, "no pose image found !", ""
 
32
  cloth_id = int(os.path.basename(cloth_image).split(".")[0])
33
 
34
  try:
35
+
36
+ client_ip = request.client.host
37
+ x_forwarded_for = dict(request.headers).get('x-forwarded-for')
38
+ if x_forwarded_for:
39
+ client_ip = x_forwarded_for
40
+
41
+ pose_np = cv2.imread(pose_image)
42
+ faces = face_detector.detect_faces(pose_np[:,:,::-1])
43
+ if len(faces)==0:
44
+ print(client_ip, 'faces num is 0! ', flush=True)
45
+ yield None, "Fatal Error !!! No face detected !!! You must upload a human photo!!! Not clothing photo!!!", ""
46
+ return None, "Fatal Error !!! No face detected !!! You must upload a human photo!!! Not clothing photo!!!", ""
47
+ else:
48
+ x, y, w, h = faces[0]["box"]
49
+ H, W = pose_np.shape[:2]
50
+ max_face_ratio = 1/3.3
51
+ if w/W>max_face_ratio or h/H>max_face_ratio:
52
+ yield None, "Fatal Error !!! Headshot is not allowed !!! You must upload a full-body or half-body photo!!!", ""
53
+ return None, "Fatal Error !!! Headshot is not allowed !!! You must upload a full-body or half-body photo!!!", ""
54
+
55
+ if not check_region_warp(client_ip):
56
+ yield None, "Failed !!! Our server is under maintenance, please try again later", ""
57
+ return None, "Failed !!! Our server is under maintenance, please try again later", ""
58
+
59
+ # client_ip = '8.8.8.8'
60
  yield None, "begin to upload ", ""
61
 
62
  timeId = int( str(time.time()).replace(".", "") )+random.randint(1000, 9999)
63
+ upload_url = upload_pose_img(client_ip, timeId, pose_image)
64
  # exit(0)
65
  yield None, "begin to public task ", ""
66
  # return None, "begin to public task ", ""
 
135
  res_image = gr.Image(label="result image", value=None, type="filepath")
136
  MK01 = gr.Markdown()
137
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  run_button.click(fn=onClick, inputs=[cloth_image, pose_image, high_resolution],
139
  outputs=[res_image, info_text, MK01])
140
 
 
 
 
 
 
 
 
 
 
141
 
142
  if __name__ == "__main__":
143
 
requirements.txt CHANGED
@@ -3,4 +3,6 @@ numpy
3
  requests
4
  gradio==4.40.0
5
  gradio-client==1.2.0
6
- func_timeout
 
 
 
3
  requests
4
  gradio==4.40.0
5
  gradio-client==1.2.0
6
+ func_timeout
7
+ mtcnn
8
+ tensorflow
utils.py CHANGED
@@ -11,12 +11,10 @@ import numpy as np
11
  import gradio as gr
12
 
13
 
14
- ApiUrl = "https://selfitcamera.site/public"
15
- OpenId = 'ovB-x639B8QwdfF7kQYS9QKdK6u8'
16
- ApiKey = 'be0b28ba433b6245ce10b7c341f'
17
  OssUrl = "https://selfit-deploy-1256039085.cos.accelerate.myqcloud.com/"
18
- Regions = "IndiaKorea"
19
  TOKEN = os.environ['TOKEN']
 
20
 
21
 
22
  proj_dir = os.path.dirname(os.path.abspath(__file__))
@@ -67,32 +65,15 @@ def get_tips():
67
  path1 = OssUrl+'ClothData/Publics/PoseGuide/tip1.jpg'
68
  path2 = OssUrl+'ClothData/Publics/PoseGuide/tip2.jpg'
69
  return path1, path2
70
-
71
- def getAllInfs(apiUrl, openId, apiKey, clientIp):
72
- params = {'openId':openId, 'apiKey':apiKey, 'ipId':clientIp}
73
- session = requests.session()
74
- ret = requests.get(f"{apiUrl}/api/all_infs", params=params)
75
- res = []
76
- if ret.status_code==200:
77
- if 'data' in ret.json():
78
- records = ret.json()['data']['records']
79
- for record in records:
80
- res.append({'pose':OssUrl+record['body_url']+"?thumbnail/768x768>",
81
- 'res':OssUrl+record['showUrl']+"?thumbnail/768x768>",
82
- 'state':int(record['state'])})
83
- # res.append({'pose':OssUrl+record['body_url'],
84
- # 'res':OssUrl+record['showUrl']})
85
- return res
86
-
87
 
88
- def upload_pose_img(apiUrl, openId, apiKey, clientIp, timeId, img):
89
  fileName = clientIp.replace(".", "")+str(timeId)+".jpg"
90
  local_path = os.path.join(tmpFolder, fileName)
91
  img = cv2.imread(img)
92
  cv2.imwrite(os.path.join(tmpFolder, fileName), img)
93
 
94
  json_data = {
95
- "token": "c0e69e5d129b11efa10c525400b75156", # 使用 apiKey 作为 token
96
  "input1": fileName,
97
  "input2": "",
98
  "protocol": "",
@@ -101,7 +82,7 @@ def upload_pose_img(apiUrl, openId, apiKey, clientIp, timeId, img):
101
 
102
  session = requests.session()
103
  ret = requests.post(
104
- f"https://selfitapi.uk/upload",
105
  headers={'Content-Type': 'application/json'},
106
  json=json_data
107
  )
@@ -128,7 +109,8 @@ def publicClothSwap(image, clothId, is_hr=0):
128
  "param2": "",
129
  "param3": "",
130
  "param4": str(is_hr),
131
- "delete_if_complete": "0"
 
132
  }
133
 
134
  headers = {
@@ -137,7 +119,7 @@ def publicClothSwap(image, clothId, is_hr=0):
137
  }
138
 
139
  ret = requests.post(
140
- 'https://selfitapi.uk/public_advton',
141
  headers=headers,
142
  json=json_data
143
  )
@@ -159,7 +141,7 @@ def getInfRes(taskId):
159
  'id': taskId
160
  }
161
  ret = requests.post(
162
- 'https://selfitapi.uk/status_advton',
163
  headers=headers,
164
  json=json_data
165
  )
 
11
  import gradio as gr
12
 
13
 
 
 
 
14
  OssUrl = "https://selfit-deploy-1256039085.cos.accelerate.myqcloud.com/"
15
+ Regions = "IndiaPakistanBengal"
16
  TOKEN = os.environ['TOKEN']
17
+ UKAPIURL = os.environ['UKAPIURL']
18
 
19
 
20
  proj_dir = os.path.dirname(os.path.abspath(__file__))
 
65
  path1 = OssUrl+'ClothData/Publics/PoseGuide/tip1.jpg'
66
  path2 = OssUrl+'ClothData/Publics/PoseGuide/tip2.jpg'
67
  return path1, path2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
+ def upload_pose_img(clientIp, timeId, img):
70
  fileName = clientIp.replace(".", "")+str(timeId)+".jpg"
71
  local_path = os.path.join(tmpFolder, fileName)
72
  img = cv2.imread(img)
73
  cv2.imwrite(os.path.join(tmpFolder, fileName), img)
74
 
75
  json_data = {
76
+ "token": "c0e69e5d129b11efa10c525400b75156",
77
  "input1": fileName,
78
  "input2": "",
79
  "protocol": "",
 
82
 
83
  session = requests.session()
84
  ret = requests.post(
85
+ f"{UKAPIURL}/upload",
86
  headers={'Content-Type': 'application/json'},
87
  json=json_data
88
  )
 
109
  "param2": "",
110
  "param3": "",
111
  "param4": str(is_hr),
112
+ "delete_if_complete": "1",
113
+ "force_celery":"1"
114
  }
115
 
116
  headers = {
 
119
  }
120
 
121
  ret = requests.post(
122
+ f'{UKAPIURL}/public_advton',
123
  headers=headers,
124
  json=json_data
125
  )
 
141
  'id': taskId
142
  }
143
  ret = requests.post(
144
+ f'{UKAPIURL}/status_advton',
145
  headers=headers,
146
  json=json_data
147
  )