Zhu-FaceOnLive commited on
Commit
6101dd8
Β·
verified Β·
1 Parent(s): aa561ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -18
app.py CHANGED
@@ -16,14 +16,22 @@ STATUS_MESSAGES = {
16
  301: "Invalid token! Get Premium Token using link in page"
17
  }
18
 
19
- backend = Client(os.getenv("BACKEND"))
 
 
20
 
21
  def base64_to_image(base64_str):
22
  return base64.b64decode(base64_str + '=' * (-len(base64_str) % 4))
23
 
24
  def search_face(file, token=None):
 
 
 
 
 
 
25
  result_text = backend.predict(
26
- file=handle_file(file),
27
  token=token,
28
  api_name="/search_face"
29
  )
@@ -168,7 +176,7 @@ head = """
168
  </script>
169
  """
170
 
171
- output = gr.Gallery(label="Search may take a few minutes.)", columns=[3], object_fit="contain", height="480px", interactive=False)
172
  col2 = gr.Column(scale=2, visible=False)
173
 
174
  def init_ui():
@@ -196,17 +204,16 @@ def update_button(token):
196
  MARKDOWN0 = """
197
  # Free Face Search Online - ❀️Like above if this space helps
198
  #### [Learn more about our Reverse Face Search](https://faceonlive.com/face-search-online)
199
- #### [Check out our Face Search API integration and Affiliate Program here.](https://portfolio.faceonlive.com/#face_search)
200
  """
201
  MARKDOWN2 = """
202
- ### [Why Get the Premium Token?](https://faceonlive.pocketsflow.com/checkout?productId=676c15b1971244a587ca07cb)
203
- βœ… **Deep Search**
204
- βœ… **Social Media and Deep Web Scan**
205
- βœ… **Exclusive Access to Hidden Profiles**
206
- βœ… **No Subscription Needed**
207
  """
208
- MARKDOWN3 = """
209
- <div align="right"><a href="https://faceonlive.pocketsflow.com/checkout?productId=677fe2b5aeced2814bc47dd1" target='_blank' style='font-size: 16px;'>Opt-Out From Search</div><br/>
 
210
  <div align="right"><a href="https://faceonlive.com/reverse-image-search" target='_blank' style='font-size: 16px;'>Reverse Image Search</div><br/>
211
  <div align="right"><a href="https://faceonlive.com/deepfake-detector" target='_blank' style='font-size: 16px;'>AI Generated Image & Deepfake Detector</div>
212
  """
@@ -223,16 +230,18 @@ with gr.Blocks(css=custom_css, head=head, delete_cache=(3600, 3600)) as demo:
223
  token = gr.Textbox(placeholder="(Optional) Input Premium Token here.", label="Premium Token")
224
  with gr.Column():
225
  md_premium1 = gr.Markdown(MARKDOWN2)
 
226
  with gr.Row():
227
  with gr.Column():
228
- premium_search_button = gr.Button("πŸš€ Unlock Deep Search Now!", elem_classes="button-gradient", link=PREMIUM_CHECKOUT)
 
229
  with gr.Column():
230
- face_search_button = gr.Button("πŸ” Free Face Search")
231
  with gr.Row():
232
  with gr.Column():
233
  gr.Examples(['examples/1.jpg', 'examples/2.jpg'], inputs=image, cache_examples=True, fn=search_face_examples, outputs=[output, col1, col2])
234
  with gr.Column():
235
- gr.HTML(MARKDOWN3)
236
 
237
  with col2.render():
238
  gr.Markdown("> ### **⚠️ Reminder:** Export images before refreshing the page by clicking the 'Export Images' button.")
@@ -243,26 +252,25 @@ with gr.Blocks(css=custom_css, head=head, delete_cache=(3600, 3600)) as demo:
243
  with gr.Column():
244
  export_button = gr.Button("Export Images")
245
  export_file = gr.File(label="Download", elem_id="export_file")
246
-
247
  with gr.Row():
248
  with gr.Column():
249
  premium_link_button = gr.Button("πŸš€ Unlock Deep Search Now!", elem_classes="button-gradient", link=PREMIUM_CHECKOUT)
250
  with gr.Column():
251
  new_search_button = gr.Button("πŸ” New Search")
252
- gr.HTML(MARKDOWN3)
253
 
 
254
  face_search_button.click(search_ui, inputs=[], outputs=[col1, col2], api_name=False)
255
  face_search_button.click(search_face, inputs=[image, token], outputs=[output], api_name=False)
256
  export_button.click(export_images, inputs=[output], outputs=export_file, api_name=False)
257
  new_search_button.click(init_ui, inputs=[], outputs=[col1, col2], api_name=False)
258
- token.change(update_button, inputs=[token], outputs=[premium_search_button, face_search_button])
259
 
260
  with gr.Row():
261
  with gr.Column(scale=1):
262
  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/visitors?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FFaceOnLive%2FFace-Search-Online&labelColor=%23ff8a65&countColor=%2337d67a&style=flat&labelStyle=upper" /></a>')
263
  with gr.Column(scale=5):
264
  html = gr.HTML()
265
-
266
  demo.load(None, inputs=None, outputs=html, js=js)
267
  demo.load(set_url_token, inputs=None, outputs=[token])
268
 
 
16
  301: "Invalid token! Get Premium Token using link in page"
17
  }
18
 
19
+ BACKEND = os.getenv("BACKEND")
20
+ backend = Client(BACKEND)
21
+ JS_FUNC = os.getenv("JS_FUNC")
22
 
23
  def base64_to_image(base64_str):
24
  return base64.b64decode(base64_str + '=' * (-len(base64_str) % 4))
25
 
26
  def search_face(file, token=None):
27
+ try:
28
+ file_1 = handle_file(file)
29
+ except Exception as e:
30
+ gr.Info("Please upload an image file.")
31
+ return []
32
+
33
  result_text = backend.predict(
34
+ file=file_1,
35
  token=token,
36
  api_name="/search_face"
37
  )
 
176
  </script>
177
  """
178
 
179
+ output = gr.Gallery(label="Search may take a few minutes.", columns=[3], object_fit="contain", height="480px", interactive=False)
180
  col2 = gr.Column(scale=2, visible=False)
181
 
182
  def init_ui():
 
204
  MARKDOWN0 = """
205
  # Free Face Search Online - ❀️Like above if this space helps
206
  #### [Learn more about our Reverse Face Search](https://faceonlive.com/face-search-online)
207
+ #### [Face Search API and Affiliate Program (50%).](https://portfolio.faceonlive.com/#face_search)
208
  """
209
  MARKDOWN2 = """
210
+ ### [Why Deep Search with Premium Token?](https://faceonlive.pocketsflow.com/checkout?productId=676c15b1971244a587ca07cb)
211
+ βœ… **Search Social Media, Deep Web & Uncover Hidden Profiles**
212
+ βœ… **Outperforming PimEyes + FaceCheck.ID Combined!**
 
 
213
  """
214
+
215
+ MARKDOWN3_2 = """
216
+ <div align="right"><a href="https://faceonlive.pocketsflow.com/checkout?productId=677fe2b5aeced2814bc47dd1" target='_blank' style='font-size: 16px;'>Opt-Out From Search</a></div><br/>
217
  <div align="right"><a href="https://faceonlive.com/reverse-image-search" target='_blank' style='font-size: 16px;'>Reverse Image Search</div><br/>
218
  <div align="right"><a href="https://faceonlive.com/deepfake-detector" target='_blank' style='font-size: 16px;'>AI Generated Image & Deepfake Detector</div>
219
  """
 
230
  token = gr.Textbox(placeholder="(Optional) Input Premium Token here.", label="Premium Token")
231
  with gr.Column():
232
  md_premium1 = gr.Markdown(MARKDOWN2)
233
+ gr.HTML("<div id='limit'></div>")
234
  with gr.Row():
235
  with gr.Column():
236
+ limit_button = gr.Button("πŸ” Free Face Search")
237
+ face_search_button = gr.Button("Face Search", visible=False, elem_id="submit_btn")
238
  with gr.Column():
239
+ premium_search_button = gr.Button("πŸš€ Unlock Deep Search Now!", elem_classes="button-gradient", link=PREMIUM_CHECKOUT)
240
  with gr.Row():
241
  with gr.Column():
242
  gr.Examples(['examples/1.jpg', 'examples/2.jpg'], inputs=image, cache_examples=True, fn=search_face_examples, outputs=[output, col1, col2])
243
  with gr.Column():
244
+ gr.HTML(MARKDOWN3_2)
245
 
246
  with col2.render():
247
  gr.Markdown("> ### **⚠️ Reminder:** Export images before refreshing the page by clicking the 'Export Images' button.")
 
252
  with gr.Column():
253
  export_button = gr.Button("Export Images")
254
  export_file = gr.File(label="Download", elem_id="export_file")
 
255
  with gr.Row():
256
  with gr.Column():
257
  premium_link_button = gr.Button("πŸš€ Unlock Deep Search Now!", elem_classes="button-gradient", link=PREMIUM_CHECKOUT)
258
  with gr.Column():
259
  new_search_button = gr.Button("πŸ” New Search")
260
+ gr.HTML(MARKDOWN3_2)
261
 
262
+ limit_button.click(None, js=JS_FUNC)
263
  face_search_button.click(search_ui, inputs=[], outputs=[col1, col2], api_name=False)
264
  face_search_button.click(search_face, inputs=[image, token], outputs=[output], api_name=False)
265
  export_button.click(export_images, inputs=[output], outputs=export_file, api_name=False)
266
  new_search_button.click(init_ui, inputs=[], outputs=[col1, col2], api_name=False)
267
+ token.change(update_button, inputs=[token], outputs=[premium_search_button, limit_button])
268
 
269
  with gr.Row():
270
  with gr.Column(scale=1):
271
  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/visitors?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FFaceOnLive%2FFace-Search-Online&labelColor=%23ff8a65&countColor=%2337d67a&style=flat&labelStyle=upper" /></a>')
272
  with gr.Column(scale=5):
273
  html = gr.HTML()
 
274
  demo.load(None, inputs=None, outputs=html, js=js)
275
  demo.load(set_url_token, inputs=None, outputs=[token])
276