Upload folder using huggingface_hub
Browse files- README.md +3 -9
- app.py +30 -0
- requirements.txt +4 -0
README.md
CHANGED
@@ -1,12 +1,6 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji: 🐠
|
4 |
-
colorFrom: indigo
|
5 |
-
colorTo: pink
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 4.32.0
|
8 |
app_file: app.py
|
9 |
-
|
|
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: age_and_emotion_image_classification
|
|
|
|
|
|
|
|
|
|
|
3 |
app_file: app.py
|
4 |
+
sdk: gradio
|
5 |
+
sdk_version: 4.25.0
|
6 |
---
|
|
|
|
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# !pip install transformers==4.37.2 gradio==4.25.0
|
2 |
+
import gradio as gr
|
3 |
+
from transformers import pipeline
|
4 |
+
age_classifier = pipeline("image-classification", model="nateraw/vit-age-classifier")
|
5 |
+
emotion_classifier = pipeline("image-classification", model="jhoppanne/Image-Emotion-Classification")
|
6 |
+
def pred_age_emotion(input_image):
|
7 |
+
if isinstance(input_image,np.ndarray):
|
8 |
+
img = Image.fromarray(input_image)
|
9 |
+
#age classifier
|
10 |
+
age_result = age_classifier(img)
|
11 |
+
age_score = age_result[0].get('score')
|
12 |
+
age_label = age_result[0].get('label')
|
13 |
+
txt1 =''
|
14 |
+
txt1 += f'The Model predict that the person in this image is around {age_label} years old.\n'
|
15 |
+
txt1 += f'with confident score : {age_score*100:.2f}%'
|
16 |
+
#emotion classifier
|
17 |
+
emotion_result = emotion_classifier(img)
|
18 |
+
emotion_score = emotion_result[0].get('score')
|
19 |
+
emotion_label = emotion_result[1].get('label')
|
20 |
+
txt2=''
|
21 |
+
txt2+= f'The Model predict that the emotion of person in this image is {emotion_label}.\n'
|
22 |
+
txt2+= f'with confident score : {emotion_score*100:.2f}% '
|
23 |
+
else:
|
24 |
+
txt1,txt2 = "sorry, unable to process the image"
|
25 |
+
return txt1, txt2
|
26 |
+
# return f"Data type of uploaded image: {type(img)}"
|
27 |
+
def pred_emotion(input_image):
|
28 |
+
return
|
29 |
+
iface = gr.Interface(fn=pred_age_emotion, inputs = gr.Image(), outputs = ["text", "text"])
|
30 |
+
iface.launch(share=True)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Python 3.10.14
|
2 |
+
gradio==4.25.0
|
3 |
+
transformers==4.37.2
|
4 |
+
torch
|