Zhu-FaceOnLive commited on
Commit
964e8c0
Β·
verified Β·
1 Parent(s): 87cf104

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -4
app.py CHANGED
@@ -21,12 +21,30 @@ def search_face(file):
21
  try:
22
  image = Image.open(file)
23
  image_base64 = image_to_base64(image)
24
- r = requests.post(url=url, json={"token": os.environ.get("ACCESS_TOKEN"), "type": "novip", "image": image_base64})
25
  except:
26
  raise gr.Error("Please select image file!")
27
 
28
- if r.text == "No matches":
29
- gr.Info("No images found.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  return [], count
31
 
32
  try:
@@ -70,4 +88,4 @@ with gr.Blocks() as demo:
70
  gr.HTML('<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FFaceOnLive%2FFace-Search-Online"><img src="https://api.visitorbadge.io/api/combined?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FFaceOnLive%2FFace-Search-Online&labelColor=%23ff8a65&countColor=%2337d67a&style=flat&labelStyle=upper" /></a>')
71
 
72
 
73
- demo.queue(api_open=False).launch(server_name="0.0.0.0", server_port=7860, show_api=False)
 
21
  try:
22
  image = Image.open(file)
23
  image_base64 = image_to_base64(image)
24
+ r = requests.post(url=url, headers={"X-RapidAPI-Key": os.environ.get("API_KEY")}, json={"image": image_base64})
25
  except:
26
  raise gr.Error("Please select image file!")
27
 
28
+ if r.status_code == 301:
29
+ gr.Info("Too many faces in the photo.")
30
+ elif r.status_code == 302:
31
+ gr.Info("Face is not clear enough.")
32
+ elif r.status_code == 303:
33
+ gr.Info("No matches found.")
34
+ elif r.status_code == 304:
35
+ gr.Info("No face in the photo.")
36
+ elif r.status_code == 305:
37
+ gr.Info("Search blocked for privacy issue.")
38
+ elif r.status_code == 401:
39
+ gr.Info("Invalid image format.")
40
+ elif r.status_code == 402:
41
+ gr.Info("Wrong request.")
42
+ elif r.status_code == 403:
43
+ gr.Info("Requests all used in your token.")
44
+ elif r.status_code == 404:
45
+ gr.Info("Timeout, try again.")
46
+
47
+ if r.status_code > 300:
48
  return [], count
49
 
50
  try:
 
88
  gr.HTML('<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FFaceOnLive%2FFace-Search-Online"><img src="https://api.visitorbadge.io/api/combined?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FFaceOnLive%2FFace-Search-Online&labelColor=%23ff8a65&countColor=%2337d67a&style=flat&labelStyle=upper" /></a>')
89
 
90
 
91
+ demo.queue(api_open=False, default_concurrency_limit=4).launch(server_name="0.0.0.0", server_port=7860, show_api=False)