selfitcamera commited on
Commit
4736174
1 Parent(s): d06267f
Files changed (3) hide show
  1. app.py +3 -1
  2. requirements.txt +1 -0
  3. utils.py +20 -0
app.py CHANGED
@@ -56,7 +56,6 @@ def onClick(cloth_id, pose_image, pose_id, size, request: gr.Request):
56
 
57
  faces = face_detector.detect_faces(pose_image[:,:,::-1])
58
  if len(faces)==0:
59
- client_ip = request.client.host
60
  print(client_ip, 'faces num is 0! ', flush=True)
61
  return None, "Fatal Error !!! No face detected !!! You must upload a human photo!!! Not clothing photo!!!", ""
62
  else:
@@ -66,6 +65,9 @@ def onClick(cloth_id, pose_image, pose_id, size, request: gr.Request):
66
  if w/W>max_face_ratio or h/H>max_face_ratio:
67
  return None, "Fatal Error !!! Headshot is not allowed !!! You must upload a full-body or half-body photo!!!", ""
68
 
 
 
 
69
  timeId = int( str(time.time()).replace(".", "") )+random.randint(1000, 9999)
70
  isUpload = upload_pose_img(ApiUrl, OpenId, ApiKey, client_ip, timeId, pose_image)
71
  if isUpload==0:
 
56
 
57
  faces = face_detector.detect_faces(pose_image[:,:,::-1])
58
  if len(faces)==0:
 
59
  print(client_ip, 'faces num is 0! ', flush=True)
60
  return None, "Fatal Error !!! No face detected !!! You must upload a human photo!!! Not clothing photo!!!", ""
61
  else:
 
65
  if w/W>max_face_ratio or h/H>max_face_ratio:
66
  return None, "Fatal Error !!! Headshot is not allowed !!! You must upload a full-body or half-body photo!!!", ""
67
 
68
+ if not check_region_warp(client_ip):
69
+ return None, "Failed !!! Our server is under maintenance, please try again later", ""
70
+
71
  timeId = int( str(time.time()).replace(".", "") )+random.randint(1000, 9999)
72
  isUpload = upload_pose_img(ApiUrl, OpenId, ApiKey, client_ip, timeId, pose_image)
73
  if isUpload==0:
requirements.txt CHANGED
@@ -5,3 +5,4 @@ gradio==3.41.2
5
  gradio-client==0.5.0
6
  mtcnn
7
  tensorflow
 
 
5
  gradio-client==0.5.0
6
  mtcnn
7
  tensorflow
8
+ func_timeout
utils.py CHANGED
@@ -6,6 +6,7 @@ import json
6
  import random
7
  import time
8
  import requests
 
9
  import numpy as np
10
  import gradio as gr
11
 
@@ -14,6 +15,7 @@ ApiUrl = os.environ['ApiUrl']
14
  OpenId = os.environ['OpenId']
15
  ApiKey = os.environ['ApiKey']
16
  OssUrl = os.environ['OssUrl']
 
17
 
18
 
19
  proj_dir = os.path.dirname(os.path.abspath(__file__))
@@ -125,3 +127,21 @@ def getInfRes(apiUrl, openId, apiKey, clientIp, timeId):
125
  else:
126
  return 0
127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  import random
7
  import time
8
  import requests
9
+ import func_timeout
10
  import numpy as np
11
  import gradio as gr
12
 
 
15
  OpenId = os.environ['OpenId']
16
  ApiKey = os.environ['ApiKey']
17
  OssUrl = os.environ['OssUrl']
18
+ Regions = os.environ['Regions']
19
 
20
 
21
  proj_dir = os.path.dirname(os.path.abspath(__file__))
 
127
  else:
128
  return 0
129
 
130
+ @func_timeout.func_set_timeout(10)
131
+ def check_region(ip):
132
+ session = requests.session()
133
+ ret = requests.get(f"https://webapi-pc.meitu.com/common/ip_location?ip={ip}")
134
+ for k in ret.json()['data']:
135
+ nat = ret.json()['data'][k]['nation']
136
+ if nat in Regions:
137
+ print(nat, 'invalid')
138
+ return False
139
+ else:
140
+ print(nat, 'valid')
141
+ return True
142
+ def check_region_warp(ip):
143
+ try:
144
+ return check_region(ip)
145
+ except Exception as e:
146
+ print(e)
147
+ return True