Jamshaid89's picture
Added 2nd interface
b97e62c
raw
history blame
2.06 kB
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
interface1 = gr.Interface(
fn=save_identity,
inputs=[image_input, label_input],
outputs=label_output,
title="Face Identification",
description="Upload an image, enter the person name and store the person in database",
)
# Create Gradio interfaces for image input and output
image_input2 = gr.inputs.Image(shape=(None, None))
output_image = gr.outputs.Image(type="numpy")
# Create the Gradio interface for image input and output
interface2 = gr.Interface(
fn=process_image,
inputs=image_input2,
outputs=output_image,
title="Face Identification",
description="Upload an image and get the identity of person",
)
# Create the Gradio interface with two tabs
interface = gr.Interface(title="Face identification App")
interface.add_view(interface1, "Save", "Add new person")
interface.add_view(interface2, "Predict", "Get identity of person")
# Launch the Gradio interface
interface.launch()