jhoppanne commited on
Commit
407cd15
·
verified ·
1 Parent(s): 3e87416

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. .ipynb_checkpoints/app-checkpoint.py +31 -0
  2. app.py +1 -0
.ipynb_checkpoints/app-checkpoint.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # !pip install transformers==4.37.2 gradio==4.25.0
2
+ import gradio as gr
3
+ from transformers import pipeline
4
+ import numpy as np
5
+ age_classifier = pipeline("image-classification", model="nateraw/vit-age-classifier")
6
+ emotion_classifier = pipeline("image-classification", model="jhoppanne/Image-Emotion-Classification")
7
+ def pred_age_emotion(input_image):
8
+ if isinstance(input_image,np.ndarray):
9
+ img = Image.fromarray(input_image)
10
+ #age classifier
11
+ age_result = age_classifier(img)
12
+ age_score = age_result[0].get('score')
13
+ age_label = age_result[0].get('label')
14
+ txt1 =''
15
+ txt1 += f'The Model predict that the person in this image is around {age_label} years old.\n'
16
+ txt1 += f'with confident score : {age_score*100:.2f}%'
17
+ #emotion classifier
18
+ emotion_result = emotion_classifier(img)
19
+ emotion_score = emotion_result[0].get('score')
20
+ emotion_label = emotion_result[1].get('label')
21
+ txt2=''
22
+ txt2+= f'The Model predict that the emotion of person in this image is {emotion_label}.\n'
23
+ txt2+= f'with confident score : {emotion_score*100:.2f}% '
24
+ else:
25
+ txt1,txt2 = "sorry, unable to process the image"
26
+ return txt1, txt2
27
+ # return f"Data type of uploaded image: {type(img)}"
28
+ def pred_emotion(input_image):
29
+ return
30
+ iface = gr.Interface(fn=pred_age_emotion, inputs = gr.Image(), outputs = ["text", "text"])
31
+ iface.launch(share=True)
app.py CHANGED
@@ -1,6 +1,7 @@
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):
 
1
  # !pip install transformers==4.37.2 gradio==4.25.0
2
  import gradio as gr
3
  from transformers import pipeline
4
+ import numpy as np
5
  age_classifier = pipeline("image-classification", model="nateraw/vit-age-classifier")
6
  emotion_classifier = pipeline("image-classification", model="jhoppanne/Image-Emotion-Classification")
7
  def pred_age_emotion(input_image):