Zhu-FaceOnLive commited on
Commit
e66d4bf
Β·
verified Β·
1 Parent(s): f2da609

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -18,8 +18,11 @@ STATUS_MESSAGES = {
18
  }
19
 
20
  BACKEND = os.getenv("BACKEND")
21
- backend = Client(BACKEND)
22
  JS_FUNC = os.getenv("JS_FUNC")
 
 
 
 
23
 
24
  def base64_to_image(base64_str):
25
  return base64.b64decode(base64_str + '=' * (-len(base64_str) % 4))
@@ -60,7 +63,8 @@ def if_limited(request):
60
  user_attempts[user_id] = today
61
  return False
62
 
63
- def search_face(file, token, request: gr.Request):
 
64
  try:
65
  file_1 = handle_file(file)
66
  except Exception as e:
@@ -71,11 +75,19 @@ def search_face(file, token, request: gr.Request):
71
  gr.Info("⏳ Wait for your next free search, or πŸš€ Go Premium for deep search!", duration=12)
72
  return []
73
 
74
- result_text = backend.predict(
75
- file=file_1,
76
- token=token,
 
 
 
 
 
 
 
 
77
  api_name="/search_face"
78
- )
79
 
80
  result = json.loads(result_text)
81
  outarray = []
 
18
  }
19
 
20
  BACKEND = os.getenv("BACKEND")
 
21
  JS_FUNC = os.getenv("JS_FUNC")
22
+ USER = os.getenv("USER")
23
+ PASS = os.getenv("PASS")
24
+
25
+ backend = Client(BACKEND, auth=[USER, PASS])
26
 
27
  def base64_to_image(base64_str):
28
  return base64.b64decode(base64_str + '=' * (-len(base64_str) % 4))
 
63
  user_attempts[user_id] = today
64
  return False
65
 
66
+ def search_face(file, token_txt, request: gr.Request):
67
+ global backend
68
  try:
69
  file_1 = handle_file(file)
70
  except Exception as e:
 
75
  gr.Info("⏳ Wait for your next free search, or πŸš€ Go Premium for deep search!", duration=12)
76
  return []
77
 
78
+ try:
79
+ result_text = backend.predict(
80
+ file=file1,
81
+ token=token_txt,
82
+ api_name="/search_face"
83
+ )
84
+ except:
85
+ backend = Client(BACKEND, auth=[USER, PASS])
86
+ result_text = backend.predict(
87
+ file=file1,
88
+ token=token_txt,
89
  api_name="/search_face"
90
+ )
91
 
92
  result = json.loads(result_text)
93
  outarray = []