Spaces:
Running
Running
import gradio as gr | |
from transformers import pipeline | |
from PIL import Image | |
# Function to classify the face shape | |
def classify_face_shape(image): | |
# Initialize the pipeline | |
pipe = pipeline("image-classification", model="metadome/face_shape_classification") | |
# Run the pipeline on the uploaded image | |
output = pipe(image) | |
# Log the output for debugging | |
print("Pipeline output for shape:", output) | |
# Format the output to be compatible with gr.outputs.Label | |
formatted_output = {item['label']: item['score'] for item in output} | |
return formatted_output | |
def classify_age(image): | |
pipe = pipeline("image-classification", model="nateraw/vit-age-classifier") | |
# Run the pipeline on the uploaded image | |
output = pipe(image) | |
print("Pipeline output for age:", output) | |
# Format the output to be compatible with gr.outputs.Label | |
formatted_output = {item['label']: item['score'] for item in output} | |
return formatted_output | |
def classify_skin_type(image): | |
pipe = pipeline("image-classification", model="dima806/skin_types_image_detection") | |
# Run the pipeline on the uploaded image | |
output = pipe(image) | |
print("Pipeline output for skin_type:", output) | |
# Format the output to be compatible with gr.outputs.Label | |
formatted_output = {item['label']: item['score'] for item in output} | |
return formatted_output | |
def classify_acne_type(image): | |
pipe = pipeline("image-classification", model="imfarzanansari/skintelligent-acne") | |
# Run the pipeline on the uploaded image | |
output = pipe(image) | |
print("Pipeline output for acne:", output) | |
# Format the output to be compatible with gr.outputs.Label | |
formatted_output = {item['label']: item['score'] for item in output} | |
return formatted_output | |
def classify_hair_color(image): | |
#pipe = pipeline("image-classification", model="enzostvs/hair-color") | |
pipe = pipeline("image-classification", model="londe33/hair_v02") | |
# Run the pipeline on the uploaded image | |
output = pipe(image) | |
print("Pipeline output for hir color:", output) | |
# Format the output to be compatible with gr.outputs.Label | |
formatted_output = {item['label']: item['score'] for item in output} | |
return formatted_output | |
def classify_eye_shape(image): | |
pipe = pipeline("image-classification", model="justingrammens/eye-shape") | |
# Run the pipeline on the uploaded image | |
output = pipe(image) | |
print("Pipeline output for eye shape:", output) | |
# Format the output to be compatible with gr.outputs.Label | |
formatted_output = {item['label']: item['score'] for item in output} | |
return formatted_output | |
def classify_eye_color(image): | |
pipe = pipeline("image-classification", model="justingrammens/eye-color") | |
# Run the pipeline on the uploaded image | |
output = pipe(image) | |
print("Pipeline output for eye color:", output) | |
# Format the output to be compatible with gr.outputs.Label | |
formatted_output = {item['label']: item['score'] for item in output} | |
return formatted_output | |
def classify_image_with_multiple_models(image): | |
face_shape_result = classify_face_shape(image) | |
age_result = classify_age(image) | |
skin_type_result = classify_skin_type(image) | |
acne_results = classify_acne_type(image) | |
hair_color_results = classify_hair_color(image) | |
eye_shape = classify_eye_shape(image) | |
eye_color = classify_eye_color(image) | |
return face_shape_result, age_result, skin_type_result, acne_results, hair_color_results, eye_shape, eye_color | |
# Create the Gradio interface | |
demo = gr.Interface( | |
fn=classify_image_with_multiple_models, # The function to run | |
inputs=gr.Image(type="pil"), | |
outputs=[ | |
gr.Label(num_top_classes=5, label="Face Shape"), | |
gr.Label(num_top_classes=5, label="Age"), | |
gr.Label(num_top_classes=3, label="Skin Type"), | |
gr.Label(num_top_classes=5, label="Acne Type"), | |
gr.Label(num_top_classes=5, label="Hair Color"), | |
gr.Label(num_top_classes=4, label="Eye Shape"), | |
gr.Label(num_top_classes=5, label="Eye Color"), | |
], | |
title="Multiple Model Classification", | |
description="Upload an image to classify the face using mutiple classification models" | |
) | |
demo.launch(auth=("admin", "pass1234")) | |
#demo.launch() | |