Spaces:
Sleeping
Sleeping
kadabengaran
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,8 @@
|
|
1 |
-
from fastapi import FastAPI, File, UploadFile, Form, HTTPException
|
2 |
-
from fastapi.responses import
|
3 |
import gradio as gr
|
4 |
from deepface import DeepFace
|
5 |
import os
|
6 |
-
from threading import Thread
|
7 |
from gradio.routes import App as GradioApp
|
8 |
|
9 |
os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"
|
@@ -91,8 +90,8 @@ async def face_verification(
|
|
91 |
|
92 |
# Define Gradio Blocks
|
93 |
with gr.Blocks() as demo:
|
94 |
-
img1 = gr.Image(
|
95 |
-
img2 = gr.Image(
|
96 |
dist = gr.Dropdown(choices=["cosine", "euclidean", "euclidean_l2"], label="Distance Metric", value="cosine")
|
97 |
model = gr.Dropdown(choices=["VGG-Face", "Facenet", "Facenet512", "ArcFace"], label="Model", value="Facenet")
|
98 |
detector = gr.Dropdown(choices=["opencv", "ssd", "mtcnn", "retinaface", "mediapipe"], label="Detector", value="ssd")
|
@@ -109,14 +108,22 @@ async def root():
|
|
109 |
"""
|
110 |
Redirect root to the Gradio app
|
111 |
"""
|
112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
<!DOCTYPE html>
|
114 |
<html>
|
115 |
<head>
|
116 |
<title>Gradio App</title>
|
117 |
</head>
|
118 |
<body style="margin: 0; padding: 0; overflow: hidden;">
|
119 |
-
<iframe src="
|
120 |
</body>
|
121 |
</html>
|
122 |
""")
|
|
|
1 |
+
from fastapi import FastAPI, File, UploadFile, Form, HTTPException
|
2 |
+
from fastapi.responses import HTMLResponse
|
3 |
import gradio as gr
|
4 |
from deepface import DeepFace
|
5 |
import os
|
|
|
6 |
from gradio.routes import App as GradioApp
|
7 |
|
8 |
os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"
|
|
|
90 |
|
91 |
# Define Gradio Blocks
|
92 |
with gr.Blocks() as demo:
|
93 |
+
img1 = gr.Image(label="Image 1",sources=["upload", "webcam", "clipboard"])
|
94 |
+
img2 = gr.Image(label="Image 2",sources=["upload", "webcam", "clipboard"])
|
95 |
dist = gr.Dropdown(choices=["cosine", "euclidean", "euclidean_l2"], label="Distance Metric", value="cosine")
|
96 |
model = gr.Dropdown(choices=["VGG-Face", "Facenet", "Facenet512", "ArcFace"], label="Model", value="Facenet")
|
97 |
detector = gr.Dropdown(choices=["opencv", "ssd", "mtcnn", "retinaface", "mediapipe"], label="Detector", value="ssd")
|
|
|
108 |
"""
|
109 |
Redirect root to the Gradio app
|
110 |
"""
|
111 |
+
# Check if running on Hugging Face Spaces
|
112 |
+
if os.getenv("SPACE_ID"):
|
113 |
+
# Running on Hugging Face Spaces
|
114 |
+
gradio_url = "https://kadabengaran-face-verify.hf.space/gradio/"
|
115 |
+
else:
|
116 |
+
# Running locally
|
117 |
+
gradio_url = "/gradio"
|
118 |
+
|
119 |
+
return HTMLResponse(f"""
|
120 |
<!DOCTYPE html>
|
121 |
<html>
|
122 |
<head>
|
123 |
<title>Gradio App</title>
|
124 |
</head>
|
125 |
<body style="margin: 0; padding: 0; overflow: hidden;">
|
126 |
+
<iframe src="{gradio_url}" style="width: 100%; height: 100vh; border: none;"></iframe>
|
127 |
</body>
|
128 |
</html>
|
129 |
""")
|