Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,53 +1,51 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import requests
|
| 3 |
-
import face_recognition
|
| 4 |
import numpy as np
|
| 5 |
from PIL import Image
|
|
|
|
|
|
|
| 6 |
import os
|
| 7 |
-
import
|
| 8 |
|
| 9 |
st.set_page_config(page_title="Face Finder on Internet", layout="centered")
|
| 10 |
st.title("🕵️♂️ Check if Your Face Exists on the Internet")
|
| 11 |
st.markdown("Upload your photo and we'll search for public matches using reverse image search and AI-based face comparison.")
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
return None
|
| 22 |
-
except Exception as e:
|
| 23 |
-
st.error(f"Error processing image: {e}")
|
| 24 |
-
return None
|
| 25 |
|
| 26 |
-
# Function to
|
| 27 |
-
def
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# UI: Upload image
|
| 34 |
uploaded_file = st.file_uploader("Upload your face image (jpg/png)", type=["jpg", "jpeg", "png"])
|
| 35 |
|
| 36 |
if uploaded_file:
|
| 37 |
# Show uploaded image
|
| 38 |
-
image = Image.open(uploaded_file)
|
| 39 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 40 |
|
| 41 |
-
# Extract face
|
| 42 |
-
|
| 43 |
|
| 44 |
-
if
|
| 45 |
-
st.success("Face
|
| 46 |
|
| 47 |
# Convert image to bytes for reverse search
|
| 48 |
-
img_byte_arr =
|
| 49 |
-
image.save(img_byte_arr
|
| 50 |
-
img_bytes = img_byte_arr.
|
| 51 |
|
| 52 |
# Provide links for manual reverse search
|
| 53 |
st.subheader("🔍 Search Your Face on the Web")
|
|
@@ -55,7 +53,7 @@ if uploaded_file:
|
|
| 55 |
|
| 56 |
with col1:
|
| 57 |
st.markdown("[Search on Google](https://images.google.com)")
|
| 58 |
-
st.caption("Upload the same image
|
| 59 |
|
| 60 |
with col2:
|
| 61 |
st.markdown("[Search on Yandex](https://yandex.com/images)")
|
|
@@ -70,4 +68,4 @@ if uploaded_file:
|
|
| 70 |
st.warning("No face detected in the uploaded image. Try another photo.")
|
| 71 |
|
| 72 |
st.markdown("---")
|
| 73 |
-
st.markdown("Created with ❤️ using open-source
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
from PIL import Image
|
| 4 |
+
import insightface
|
| 5 |
+
import cv2
|
| 6 |
import os
|
| 7 |
+
import tempfile
|
| 8 |
|
| 9 |
st.set_page_config(page_title="Face Finder on Internet", layout="centered")
|
| 10 |
st.title("🕵️♂️ Check if Your Face Exists on the Internet")
|
| 11 |
st.markdown("Upload your photo and we'll search for public matches using reverse image search and AI-based face comparison.")
|
| 12 |
|
| 13 |
+
# Load InsightFace model
|
| 14 |
+
@st.cache_resource
|
| 15 |
+
def load_model():
|
| 16 |
+
model = insightface.app.FaceAnalysis(name='buffalo_l')
|
| 17 |
+
model.prepare(ctx_id=0)
|
| 18 |
+
return model
|
| 19 |
+
|
| 20 |
+
model = load_model()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
# Function to extract face embeddings
|
| 23 |
+
def get_face_embedding(image):
|
| 24 |
+
image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
|
| 25 |
+
faces = model.get(image)
|
| 26 |
+
if faces:
|
| 27 |
+
return faces[0].embedding
|
| 28 |
+
else:
|
| 29 |
+
return None
|
| 30 |
|
| 31 |
# UI: Upload image
|
| 32 |
uploaded_file = st.file_uploader("Upload your face image (jpg/png)", type=["jpg", "jpeg", "png"])
|
| 33 |
|
| 34 |
if uploaded_file:
|
| 35 |
# Show uploaded image
|
| 36 |
+
image = Image.open(uploaded_file).convert("RGB")
|
| 37 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 38 |
|
| 39 |
+
# Extract face embedding
|
| 40 |
+
embedding = get_face_embedding(image)
|
| 41 |
|
| 42 |
+
if embedding is not None:
|
| 43 |
+
st.success("Face features extracted successfully ✅")
|
| 44 |
|
| 45 |
# Convert image to bytes for reverse search
|
| 46 |
+
img_byte_arr = tempfile.NamedTemporaryFile(delete=False, suffix=".jpg")
|
| 47 |
+
image.save(img_byte_arr.name)
|
| 48 |
+
img_bytes = open(img_byte_arr.name, 'rb').read()
|
| 49 |
|
| 50 |
# Provide links for manual reverse search
|
| 51 |
st.subheader("🔍 Search Your Face on the Web")
|
|
|
|
| 53 |
|
| 54 |
with col1:
|
| 55 |
st.markdown("[Search on Google](https://images.google.com)")
|
| 56 |
+
st.caption("Upload the same image manually")
|
| 57 |
|
| 58 |
with col2:
|
| 59 |
st.markdown("[Search on Yandex](https://yandex.com/images)")
|
|
|
|
| 68 |
st.warning("No face detected in the uploaded image. Try another photo.")
|
| 69 |
|
| 70 |
st.markdown("---")
|
| 71 |
+
st.markdown("Created with ❤️ using open-source InsightFace and public search tools.")
|