Midnightar commited on
Commit
057f178
·
verified ·
1 Parent(s): 5059f37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -18
app.py CHANGED
@@ -7,6 +7,7 @@ from pydantic import BaseModel
7
  import uvicorn
8
  import insightface
9
  import gradio as gr
 
10
 
11
  # ---------- Load Face Detector + Recognition Model ----------
12
  model = insightface.app.FaceAnalysis(name="buffalo_l")
@@ -88,16 +89,9 @@ async def compare_faces(req: CompareRequest):
88
  "match": matched
89
  }
90
 
91
- # ---------- Gradio UI (TEXT INPUT instead of upload) ----------
92
  def gradio_ui(img1_text, img2_text):
93
- """
94
- Accepts:
95
- - base64 string
96
- - or URL
97
- Automatically detects which one.
98
- """
99
-
100
- # --- Determine type of input ---
101
  def load_any(input_str):
102
  if input_str.startswith("http://") or input_str.startswith("https://"):
103
  return url_to_img(input_str)
@@ -121,12 +115,24 @@ def gradio_ui(img1_text, img2_text):
121
 
122
  return f"Similarity: {similarity:.3f} | Match: {matched}"
123
 
124
- gr.Interface(
125
- fn=gradio_ui,
126
- inputs=[
127
- gr.Textbox(label="Image 1 (base64 or URL)"),
128
- gr.Textbox(label="Image 2 (base64 or URL)")
129
- ],
130
- outputs="text",
131
- title="Face Match API (Text Input)"
132
- ).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  import uvicorn
8
  import insightface
9
  import gradio as gr
10
+ import threading
11
 
12
  # ---------- Load Face Detector + Recognition Model ----------
13
  model = insightface.app.FaceAnalysis(name="buffalo_l")
 
89
  "match": matched
90
  }
91
 
92
+ # ---------- Gradio UI ----------
93
  def gradio_ui(img1_text, img2_text):
94
+
 
 
 
 
 
 
 
95
  def load_any(input_str):
96
  if input_str.startswith("http://") or input_str.startswith("https://"):
97
  return url_to_img(input_str)
 
115
 
116
  return f"Similarity: {similarity:.3f} | Match: {matched}"
117
 
118
+
119
+ # ---------- Run Gradio in Background Thread ----------
120
+ def launch_gradio():
121
+ gr.Interface(
122
+ fn=gradio_ui,
123
+ inputs=[
124
+ gr.Textbox(label="Image 1 (base64 or URL)"),
125
+ gr.Textbox(label="Image 2 (base64 or URL)")
126
+ ],
127
+ outputs="text",
128
+ title="Face Match API (Text Input)"
129
+ ).launch(server_name="0.0.0.0", server_port=7860)
130
+
131
+
132
+ # ---------- MAIN ----------
133
+ if __name__ == "__main__":
134
+ # Start Gradio in a separate thread
135
+ threading.Thread(target=launch_gradio, daemon=True).start()
136
+
137
+ # Start FastAPI server
138
+ uvicorn.run(app, host="0.0.0.0", port=8000)