codevlogger2003 commited on
Commit
7fa5c89
1 Parent(s): 1c0ab62

Updated app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -40
app.py CHANGED
@@ -50,57 +50,53 @@ def main(options):
50
 
51
 
52
  if st.checkbox('Take a picture for prediction'):
53
- if 'c02' not in st.session_state:
54
- st.session_state.c02=False
55
- c02_state=st.session_state.c02
56
- c02_state=st.sidebar.checkbox('Detect',value=c02_state)
57
 
58
  with col1:
59
  image, original_image= upload()
60
- if original_image is not None and original_image is not None and c02_state:
61
 
62
- # Check if original_image is not None
63
- pass
64
- st.session_state.c02=c02_state
65
 
66
  with col2:
67
- st.warning('Wait for few seconds!!')
68
- progress_bar = st.progress(0.0)
69
- status_text = st.empty()
70
-
71
- result = DeepFace.analyze(image,detector_backend=options,actions=['age','gender','emotion','race'])
72
-
73
- for i in range(100):
74
- progress_bar.progress((i + 1) / 100)
75
- status_text.text(f"Processing {i+1}%")
76
- time.sleep(0.01)
77
-
78
- progress_bar.empty()
79
- gray_frame = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
80
- faces = cascade.detectMultiScale(gray_frame, 1.1, 3)
81
-
82
-
83
- for x,y,w,h in faces:
84
 
 
 
 
 
85
 
86
- cv2.rectangle(image, (x, y), (x+w, y+h), (4, 29, 255), 2, cv2.LINE_4)
87
- user_selected_items = list(result[0].keys())
88
- if 'age' in user_selected_items:
89
- age_label='Age: '+str(result[0]['age'])
90
- cv2.putText(image, age_label, (x ,y+h+30), cv2.FONT_ITALIC,1 ,(255,255,0), 2)
91
- if 'dominant_gender' in user_selected_items:
92
- gender_label='Gender: '+str(result[0]['dominant_gender'])
93
- cv2.putText(image, gender_label, (x, y+h+70), cv2.FONT_ITALIC,1, (0,255,255), 2)
94
 
95
- if 'dominant_emotion' in user_selected_items:
96
- emotion_label='Emotion: '+str(result[0]['dominant_emotion']).title()
97
- cv2.putText(image, emotion_label, (x, y+h+110), cv2.FONT_ITALIC,1 ,(255,0,255), 2)
98
 
99
- if 'dominant_race' in user_selected_items:
100
- emotion_label='Race: '+str(result[0]['dominant_race']).title()
101
- cv2.putText(image, emotion_label, (x, y+h+150), cv2.FONT_ITALIC,1 ,(51,102,0), 2)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
 
103
- st.image(image, channels='BGR')
104
 
105
 
106
 
 
50
 
51
 
52
  if st.checkbox('Take a picture for prediction'):
 
 
 
 
53
 
54
  with col1:
55
  image, original_image= upload()
56
+
57
 
 
 
 
58
 
59
  with col2:
60
+ if original_image is not None and original_image is not None and st.button('Detect'):
61
+
62
+
63
+ st.warning('Wait for few seconds!!')
64
+ progress_bar = st.progress(0.0)
65
+ status_text = st.empty()
66
+
67
+ result = DeepFace.analyze(image,detector_backend=options,actions=['age','gender','emotion','race'])
 
 
 
 
 
 
 
 
 
68
 
69
+ for i in range(100):
70
+ progress_bar.progress((i + 1) / 100)
71
+ status_text.text(f"Processing {i+1}%")
72
+ time.sleep(0.01)
73
 
74
+ progress_bar.empty()
75
+ gray_frame = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
76
+ faces = cascade.detectMultiScale(gray_frame, 1.1, 3)
 
 
 
 
 
77
 
 
 
 
78
 
79
+ for x,y,w,h in faces:
80
+
81
+
82
+ cv2.rectangle(image, (x, y), (x+w, y+h), (4, 29, 255), 2, cv2.LINE_4)
83
+ user_selected_items = list(result[0].keys())
84
+ if 'age' in user_selected_items:
85
+ age_label='Age: '+str(result[0]['age'])
86
+ cv2.putText(image, age_label, (x ,y+h+30), cv2.FONT_ITALIC,1 ,(255,255,0), 2)
87
+ if 'dominant_gender' in user_selected_items:
88
+ gender_label='Gender: '+str(result[0]['dominant_gender'])
89
+ cv2.putText(image, gender_label, (x, y+h+70), cv2.FONT_ITALIC,1, (0,255,255), 2)
90
+
91
+ if 'dominant_emotion' in user_selected_items:
92
+ emotion_label='Emotion: '+str(result[0]['dominant_emotion']).title()
93
+ cv2.putText(image, emotion_label, (x, y+h+110), cv2.FONT_ITALIC,1 ,(255,0,255), 2)
94
+
95
+ if 'dominant_race' in user_selected_items:
96
+ emotion_label='Race: '+str(result[0]['dominant_race']).title()
97
+ cv2.putText(image, emotion_label, (x, y+h+150), cv2.FONT_ITALIC,1 ,(51,102,0), 2)
98
 
99
+ st.image(image, channels='BGR')
100
 
101
 
102