Hawk3388 commited on
Commit
cc8e4e0
·
verified ·
1 Parent(s): 46bdbe7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -3
app.py CHANGED
@@ -727,6 +727,13 @@ async def face_search_gradio(image, max_results=100, top_k=5, vgg16_threshold=0.
727
 
728
  return gallery, f"✅ Found {len(top_matches)} matching faces!"
729
 
 
 
 
 
 
 
 
730
 
731
  def gradio_sync_wrapper(image):
732
  """
@@ -739,6 +746,10 @@ def gradio_sync_wrapper(image):
739
  debug = False
740
  return asyncio.run(face_search_gradio(image, max_results, top_k, vgg16_threshold, debug))
741
 
 
 
 
 
742
  with gr.Blocks() as demo:
743
  gr.Markdown("""
744
  # Face Search Tool Demo
@@ -749,15 +760,24 @@ with gr.Blocks() as demo:
749
  """)
750
  image_input = gr.Image(type="pil", label="Upload an image", show_label=True)
751
  submit_btn = gr.Button("🔍 Start Search", elem_id="search-btn")
752
-
753
- # Add status message component
754
- status_msg = gr.Textbox(label="Status", interactive=False, visible=True, show_label=True)
755
  gallery = gr.Gallery(label="Top 10 Matches", columns=5, height="auto", show_label=True)
756
 
 
 
 
 
757
  submit_btn.click(
 
 
 
 
758
  gradio_sync_wrapper,
759
  inputs=[image_input],
760
  outputs=[gallery, status_msg]
 
 
 
 
761
  )
762
 
763
  demo.launch(share=True, server_name="0.0.0.0")
 
727
 
728
  return gallery, f"✅ Found {len(top_matches)} matching faces!"
729
 
730
+ def update_status_visibility(status_text):
731
+ """Make status field visible only when there's a message"""
732
+ if status_text and status_text.strip():
733
+ return gr.update(value=status_text, visible=True)
734
+ else:
735
+ return gr.update(value="", visible=False)
736
+
737
 
738
  def gradio_sync_wrapper(image):
739
  """
 
746
  debug = False
747
  return asyncio.run(face_search_gradio(image, max_results, top_k, vgg16_threshold, debug))
748
 
749
+ def hide_status():
750
+ """Hide status message at start of search."""
751
+ return gr.update(visible=False, value="")
752
+
753
  with gr.Blocks() as demo:
754
  gr.Markdown("""
755
  # Face Search Tool Demo
 
760
  """)
761
  image_input = gr.Image(type="pil", label="Upload an image", show_label=True)
762
  submit_btn = gr.Button("🔍 Start Search", elem_id="search-btn")
 
 
 
763
  gallery = gr.Gallery(label="Top 10 Matches", columns=5, height="auto", show_label=True)
764
 
765
+ # Status message below gallery (only shows when there's a message)
766
+ status_msg = gr.Textbox(label="Status", interactive=False, visible=False, show_label=False)
767
+
768
+ # Create a chain: first hide status, then run search, then show status if needed
769
  submit_btn.click(
770
+ hide_status,
771
+ inputs=[],
772
+ outputs=[status_msg]
773
+ ).then(
774
  gradio_sync_wrapper,
775
  inputs=[image_input],
776
  outputs=[gallery, status_msg]
777
+ ).then(
778
+ update_status_visibility,
779
+ inputs=[status_msg],
780
+ outputs=[status_msg]
781
  )
782
 
783
  demo.launch(share=True, server_name="0.0.0.0")