AhmedIbrahim007 commited on
Commit
853f5ba
·
verified ·
1 Parent(s): 425e4fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -97,16 +97,21 @@ async def process_file(file_data: FileProcess):
97
 
98
 
99
  def process_video(video_path):
100
- learn = load_learner('model.pkl')
101
- searches = ['formal','casual','athletic']
102
- searches = sorted(searches) # need to be sorted because that's the order the predictions will be outputed
103
- values = [i for i in range(0,len(searches))]
104
- class_dict = dict(zip(searches,values))
105
-
106
- classication,_,probs = learn.predict(im)
107
- confidences = {label: float(probs[i]) for i, label in enumerate(class_dict)}
108
- return confidences
109
-
 
 
 
 
 
110
 
111
  if __name__ == "__main__":
112
  logger.info("Starting the Face Emotion Recognition API")
 
97
 
98
 
99
  def process_video(video_path):
100
+ # Load the image from the provided path
101
+ img = PILImage.create(video_path)
102
+
103
+ # Make the prediction
104
+ classification, _, probs = learn.predict(img)
105
+
106
+ # Convert the prediction to a confidence dictionary
107
+ confidences = {label: float(probs[i]) for i, label in enumerate(class_dict)}
108
+
109
+ # If classification is not formal, return 'informal'
110
+ if classification != 'formal':
111
+ informal_confidence = sum(confidences[label] for label in class_dict if label != 'formal')
112
+ return {'informal': informal_confidence}
113
+ else:
114
+ return {'formal': confidences['formal']}
115
 
116
  if __name__ == "__main__":
117
  logger.info("Starting the Face Emotion Recognition API")