Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,10 @@ import matplotlib.pyplot as plt
|
|
8 |
# Disable PyplotGlobalUseWarning
|
9 |
st.set_option('deprecation.showPyplotGlobalUse', False)
|
10 |
|
|
|
|
|
|
|
|
|
11 |
# Create an image classification pipeline with scores
|
12 |
pipe = pipeline("image-classification", model="trpakov/vit-face-expression", top_k=None)
|
13 |
|
@@ -159,45 +163,45 @@ st.write("results info:", results)
|
|
159 |
|
160 |
# Generate DataFrame from results
|
161 |
if st.button("Generate DataFrame"):
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
|
|
8 |
# Disable PyplotGlobalUseWarning
|
9 |
st.set_option('deprecation.showPyplotGlobalUse', False)
|
10 |
|
11 |
+
# Initialize session state for results if not already present
|
12 |
+
if 'results' not in st.session_state:
|
13 |
+
st.session_state['results'] = []
|
14 |
+
|
15 |
# Create an image classification pipeline with scores
|
16 |
pipe = pipeline("image-classification", model="trpakov/vit-face-expression", top_k=None)
|
17 |
|
|
|
163 |
|
164 |
# Generate DataFrame from results
|
165 |
if st.button("Generate DataFrame"):
|
166 |
+
# Access the results from the session state
|
167 |
+
results = st.session_state['results']
|
168 |
+
if results:
|
169 |
+
st.write("results info inner loop:", results)
|
170 |
+
# Initialize an empty dictionary to store the scores
|
171 |
+
emotion_scores = {
|
172 |
+
'Neutral': [],
|
173 |
+
'Happy': [],
|
174 |
+
'Surprise': [],
|
175 |
+
'Disgust': [],
|
176 |
+
'Angry': [],
|
177 |
+
# Add other emotions if necessary
|
178 |
+
'Sad': [], # Add this if you have 'sad' scores in your results
|
179 |
+
'Fear': [] # Add this if you have 'fear' scores in your results
|
180 |
+
}
|
181 |
+
|
182 |
+
# Iterate over the results and populate the dictionary
|
183 |
+
for result_set in results:
|
184 |
+
# Initialize a dictionary for the current set with zeros
|
185 |
+
current_scores = {emotion: 0 for emotion in emotion_scores.keys()}
|
186 |
+
|
187 |
+
for result in result_set:
|
188 |
+
# Capitalize the label and update the score in the current set
|
189 |
+
emotion = result['label'].capitalize()
|
190 |
+
score = round(result['score'], 4) # Round the score to 4 decimal places
|
191 |
+
current_scores[emotion] = score
|
192 |
+
|
193 |
+
# Add the current scores to the emotion_scores dictionary
|
194 |
+
for emotion, score in current_scores.items():
|
195 |
+
emotion_scores[emotion].append(score)
|
196 |
+
|
197 |
+
# Convert the dictionary into a pandas DataFrame
|
198 |
+
df_emotions = pd.DataFrame(emotion_scores)
|
199 |
+
|
200 |
+
# Display the DataFrame
|
201 |
+
st.write(df_emotions)
|
202 |
+
|
203 |
+
# Optional: Save the DataFrame to a CSV file
|
204 |
+
df_emotions.to_csv('emotion_scores.csv', index=False)
|
205 |
+
st.success('DataFrame generated and saved as emotion_scores.csv')
|
206 |
+
else:
|
207 |
+
st.error("No results to generate DataFrame. Please predict emotions first.")
|