File size: 1,404 Bytes
f347761
 
500f010
 
f347761
 
 
500f010
f347761
 
 
 
500f010
 
 
 
f347761
 
 
 
 
 
 
500f010
 
 
 
 
 
 
 
 
 
 
 
 
 
95ea752
500f010
 
 
a40427c
500f010
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import gradio as gr

import numpy as np
from deepface import DeepFace
from pymongo.mongo_client import MongoClient

credentials = "jamshaid:jamshaid19gh"

uri = f"mongodb+srv://{credentials}@cluster0.uimyui3.mongodb.net/?retryWrites=true&w=majority"
client = MongoClient(uri)
db = client["Face_identification"]
identities_collection = db["face_identities"]

def save_identity(image , name):
  try:
    embeddings = DeepFace.represent(image , model_name="Facenet")
    embeddings = embeddings[0]

    identity = {"embeddings":embeddings["embedding"] , "name" : name }

    result = identities_collection.insert_one(identity)

    return str(result)
  except Exception as error:
    return str(error)


# image_input = gr.inputs.Image(shape=(160,160))
label_output = gr.outputs.Textbox()

# Create the Gradio interface
# gr.Interface(fn=predict_image, inputs=image_input, outputs=label_output).launch()


# Create Gradio interfaces for input and output
image_input = gr.inputs.Image(shape=(160, 160))
label_input = gr.inputs.Textbox(label="Enter Label")
output_image = gr.outputs.Image(type="numpy")

# Create the Gradio interface
interface = gr.Interface(
    fn=save_identity,
    inputs=[image_input, label_input],
    outputs=label_output,
    title="Face Identification",
    description="Upload an image, enter a label, and get the output image.",
)

# Launch the Gradio interface
interface.launch()