Spaces:
Running
Running
Justin Grammens
commited on
Commit
•
6a1ec3e
1
Parent(s):
405f8e6
updated
Browse files
app.py
CHANGED
@@ -1,7 +1,111 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
demo.launch(auth=("admin", "pass1234"))
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
from PIL import Image
|
4 |
|
5 |
+
# Function to classify the face shape
|
6 |
+
def classify_face_shape(image):
|
7 |
+
|
8 |
+
# Initialize the pipeline
|
9 |
+
pipe = pipeline("image-classification", model="metadome/face_shape_classification")
|
10 |
+
|
11 |
+
# Run the pipeline on the uploaded image
|
12 |
+
output = pipe(image)
|
13 |
+
# Log the output for debugging
|
14 |
+
print("Pipeline output for shape:", output)
|
15 |
+
# Format the output to be compatible with gr.outputs.Label
|
16 |
+
formatted_output = {item['label']: item['score'] for item in output}
|
17 |
+
|
18 |
+
return formatted_output
|
19 |
+
|
20 |
+
def classify_age(image):
|
21 |
+
pipe = pipeline("image-classification", model="nateraw/vit-age-classifier")
|
22 |
+
# Run the pipeline on the uploaded image
|
23 |
+
output = pipe(image)
|
24 |
+
|
25 |
+
print("Pipeline output for age:", output)
|
26 |
+
# Format the output to be compatible with gr.outputs.Label
|
27 |
+
formatted_output = {item['label']: item['score'] for item in output}
|
28 |
+
|
29 |
+
return formatted_output
|
30 |
+
|
31 |
+
def classify_skin_type(image):
|
32 |
+
pipe = pipeline("image-classification", model="dima806/skin_types_image_detection")
|
33 |
+
|
34 |
+
# Run the pipeline on the uploaded image
|
35 |
+
output = pipe(image)
|
36 |
+
|
37 |
+
print("Pipeline output for skin_type:", output)
|
38 |
+
# Format the output to be compatible with gr.outputs.Label
|
39 |
+
formatted_output = {item['label']: item['score'] for item in output}
|
40 |
+
|
41 |
+
return formatted_output
|
42 |
|
43 |
+
def classify_acne_type(image):
|
44 |
+
pipe = pipeline("image-classification", model="imfarzanansari/skintelligent-acne")
|
45 |
+
|
46 |
+
# Run the pipeline on the uploaded image
|
47 |
+
output = pipe(image)
|
48 |
+
|
49 |
+
print("Pipeline output for acne:", output)
|
50 |
+
# Format the output to be compatible with gr.outputs.Label
|
51 |
+
formatted_output = {item['label']: item['score'] for item in output}
|
52 |
+
|
53 |
+
return formatted_output
|
54 |
+
|
55 |
+
def classify_hair_color(image):
|
56 |
+
|
57 |
+
#pipe = pipeline("image-classification", model="enzostvs/hair-color")
|
58 |
+
pipe = pipeline("image-classification", model="londe33/hair_v02")
|
59 |
+
|
60 |
+
# Run the pipeline on the uploaded image
|
61 |
+
output = pipe(image)
|
62 |
+
|
63 |
+
print("Pipeline output for hir color:", output)
|
64 |
+
# Format the output to be compatible with gr.outputs.Label
|
65 |
+
formatted_output = {item['label']: item['score'] for item in output}
|
66 |
+
|
67 |
+
return formatted_output
|
68 |
+
|
69 |
+
def classify_eye_shape(image):
|
70 |
+
|
71 |
+
pipe = pipeline("image-classification", model="justingrammens/eye-shape")
|
72 |
+
|
73 |
+
# Run the pipeline on the uploaded image
|
74 |
+
output = pipe(image)
|
75 |
+
|
76 |
+
print("Pipeline output for eye shape:", output)
|
77 |
+
# Format the output to be compatible with gr.outputs.Label
|
78 |
+
formatted_output = {item['label']: item['score'] for item in output}
|
79 |
+
|
80 |
+
return formatted_output
|
81 |
+
|
82 |
+
|
83 |
+
def classify_image_with_multiple_models(image):
|
84 |
+
face_shape_result = classify_face_shape(image)
|
85 |
+
age_result = classify_age(image)
|
86 |
+
skin_type_result = classify_skin_type(image)
|
87 |
+
acne_results = classify_acne_type(image)
|
88 |
+
hair_color_results = classify_hair_color(image)
|
89 |
+
eye_shape = classify_eye_shape(image)
|
90 |
+
|
91 |
+
return face_shape_result, age_result, skin_type_result, acne_results, hair_color_results, eye_shape
|
92 |
+
|
93 |
+
|
94 |
+
# Create the Gradio interface
|
95 |
+
demo = gr.Interface(
|
96 |
+
fn=classify_image_with_multiple_models, # The function to run
|
97 |
+
inputs=gr.Image(type="pil"),
|
98 |
+
outputs=[
|
99 |
+
gr.Label(num_top_classes=5, label="Face Shape"),
|
100 |
+
gr.Label(num_top_classes=5, label="Age"),
|
101 |
+
gr.Label(num_top_classes=3, label="Skin Type"),
|
102 |
+
gr.Label(num_top_classes=5, label="Acne Type"),
|
103 |
+
gr.Label(num_top_classes=5, label="Hair Color"),
|
104 |
+
gr.Label(num_top_classes=4, label="Eye Shape")
|
105 |
+
],
|
106 |
+
title="Multiple Model Classification",
|
107 |
+
description="Upload an image to classify the face using mutiple classification models"
|
108 |
+
)
|
109 |
+
|
110 |
demo.launch(auth=("admin", "pass1234"))
|
111 |
+
#demo.launch()
|