Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
|
@@ -198,92 +198,108 @@ def analyze(inFileName):
|
|
| 198 |
st.session_state.summaries[currFileIndex]["df3"] = df3
|
| 199 |
printV(f'Set df3',4)
|
| 200 |
|
| 201 |
-
|
| 202 |
nameList = st.session_state.categories
|
| 203 |
extraNames = []
|
| 204 |
valueList = [0 for i in range(len(nameList))]
|
| 205 |
extraValues = []
|
| 206 |
-
|
| 207 |
for sp in speakerNames:
|
| 208 |
foundSp = False
|
| 209 |
for i, categoryName in enumerate(nameList):
|
| 210 |
if sp in categorySelections[i]:
|
| 211 |
-
#st.info(categoryName)
|
| 212 |
valueList[i] += su.sumTimes(currAnnotation.subset([sp]))
|
| 213 |
foundSp = True
|
| 214 |
break
|
| 215 |
-
if foundSp:
|
| 216 |
-
continue
|
| 217 |
-
else:
|
| 218 |
extraNames.append(sp)
|
| 219 |
extraValues.append(su.sumTimes(currAnnotation.subset([sp])))
|
|
|
|
| 220 |
if extraNames:
|
| 221 |
extraPairsSorted = sorted(zip(extraNames, extraValues), key=lambda pair: pair[0])
|
| 222 |
extraNames, extraValues = list(zip(*extraPairsSorted))
|
|
|
|
|
|
|
| 223 |
else:
|
| 224 |
extraNames, extraValues = [], []
|
|
|
|
| 225 |
df4_dict = {
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
df4 = pd.DataFrame(data=df4_dict)
|
| 230 |
df4.name = "df4"
|
| 231 |
st.session_state.summaries[currFileIndex]["df4"] = df4
|
|
|
|
| 232 |
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
speakerList,timeList = su.sumTimesPerSpeaker(oneVoice)
|
| 236 |
multiSpeakerList, multiTimeList = su.sumMultiTimesPerSpeaker(multiVoice)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
summativeMultiSpeaker = sum(multiTimeList) if multiTimeList else 1
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
df5.name = "df5"
|
| 273 |
st.session_state.summaries[currFileIndex]["df5"] = df5
|
| 274 |
-
printV(f'Set df5',4)
|
| 275 |
-
|
| 276 |
-
speakers_dataFrame,
|
|
|
|
| 277 |
st.session_state.summaries[currFileIndex]["speakers_dataFrame"] = speakers_dataFrame
|
| 278 |
st.session_state.summaries[currFileIndex]["speakers_times"] = speakers_times
|
| 279 |
|
| 280 |
df2_dict = {
|
| 281 |
-
"values":[100*t/currTotalTime for t in df4_dict["values"]],
|
| 282 |
-
"names":df4_dict["names"]
|
| 283 |
}
|
| 284 |
df2 = pd.DataFrame(df2_dict)
|
| 285 |
st.session_state.summaries[currFileIndex]["df2"] = df2
|
| 286 |
-
printV(f'Set df2',4)
|
| 287 |
except Exception as e:
|
| 288 |
import traceback
|
| 289 |
print(f"Error in analyze: {e}")
|
|
|
|
| 198 |
st.session_state.summaries[currFileIndex]["df3"] = df3
|
| 199 |
printV(f'Set df3',4)
|
| 200 |
|
| 201 |
+
# --- Build df4 ---
|
| 202 |
nameList = st.session_state.categories
|
| 203 |
extraNames = []
|
| 204 |
valueList = [0 for i in range(len(nameList))]
|
| 205 |
extraValues = []
|
| 206 |
+
|
| 207 |
for sp in speakerNames:
|
| 208 |
foundSp = False
|
| 209 |
for i, categoryName in enumerate(nameList):
|
| 210 |
if sp in categorySelections[i]:
|
|
|
|
| 211 |
valueList[i] += su.sumTimes(currAnnotation.subset([sp]))
|
| 212 |
foundSp = True
|
| 213 |
break
|
| 214 |
+
if not foundSp:
|
|
|
|
|
|
|
| 215 |
extraNames.append(sp)
|
| 216 |
extraValues.append(su.sumTimes(currAnnotation.subset([sp])))
|
| 217 |
+
|
| 218 |
if extraNames:
|
| 219 |
extraPairsSorted = sorted(zip(extraNames, extraValues), key=lambda pair: pair[0])
|
| 220 |
extraNames, extraValues = list(zip(*extraPairsSorted))
|
| 221 |
+
extraNames = list(extraNames)
|
| 222 |
+
extraValues = list(extraValues)
|
| 223 |
else:
|
| 224 |
extraNames, extraValues = [], []
|
| 225 |
+
|
| 226 |
df4_dict = {
|
| 227 |
+
"values": valueList + extraValues,
|
| 228 |
+
"names": nameList + extraNames,
|
| 229 |
+
}
|
| 230 |
df4 = pd.DataFrame(data=df4_dict)
|
| 231 |
df4.name = "df4"
|
| 232 |
st.session_state.summaries[currFileIndex]["df4"] = df4
|
| 233 |
+
printV(f'Set df4', 4)
|
| 234 |
|
| 235 |
+
# --- Build df5 ---
|
| 236 |
+
speakerList, timeList = su.sumTimesPerSpeaker(oneVoice)
|
|
|
|
| 237 |
multiSpeakerList, multiTimeList = su.sumMultiTimesPerSpeaker(multiVoice)
|
| 238 |
+
|
| 239 |
+
speakerList = list(speakerList) if speakerList else []
|
| 240 |
+
timeList = list(timeList) if timeList else []
|
| 241 |
+
multiSpeakerList = list(multiSpeakerList) if multiSpeakerList else []
|
| 242 |
+
multiTimeList = list(multiTimeList) if multiTimeList else []
|
| 243 |
+
|
| 244 |
summativeMultiSpeaker = sum(multiTimeList) if multiTimeList else 1
|
| 245 |
+
safeOneVoice = sumOneVoice if sumOneVoice > 0 else 1
|
| 246 |
+
|
| 247 |
+
basePercentiles = [
|
| 248 |
+
sumNoVoice / currTotalTime,
|
| 249 |
+
sumOneVoice / currTotalTime,
|
| 250 |
+
sumMultiVoice / currTotalTime,
|
| 251 |
+
]
|
| 252 |
+
|
| 253 |
+
timeStrings = su.timeToString(timeList) if timeList else []
|
| 254 |
+
multiTimeStrings = su.timeToString(multiTimeList) if multiTimeList else []
|
| 255 |
+
if isinstance(timeStrings, str):
|
| 256 |
+
timeStrings = [timeStrings]
|
| 257 |
+
if isinstance(multiTimeStrings, str):
|
| 258 |
+
multiTimeStrings = [multiTimeStrings]
|
| 259 |
+
|
| 260 |
+
n_ov = len(speakerList)
|
| 261 |
+
n_mv = len(multiSpeakerList)
|
| 262 |
+
|
| 263 |
+
df5 = pd.DataFrame({
|
| 264 |
+
"ids": ["NV", "OV", "MV"] + [f"OV_{i}" for i in range(n_ov)] + [f"MV_{i}" for i in range(n_mv)],
|
| 265 |
+
"labels": ["No Voice", "One Voice", "Multi Voice"] + speakerList + multiSpeakerList,
|
| 266 |
+
"parents": ["", "", ""] + ["OV"] * n_ov + ["MV"] * n_mv,
|
| 267 |
+
"parentNames": ["Total", "Total", "Total"] + ["One Voice"] * n_ov + ["Multi Voice"] * n_mv,
|
| 268 |
+
"values": [sumNoVoice, sumOneVoice, sumMultiVoice] + timeList + multiTimeList,
|
| 269 |
+
"valueStrings": [
|
| 270 |
+
su.timeToString(sumNoVoice),
|
| 271 |
+
su.timeToString(sumOneVoice),
|
| 272 |
+
su.timeToString(sumMultiVoice),
|
| 273 |
+
] + timeStrings + multiTimeStrings,
|
| 274 |
+
"percentiles": [
|
| 275 |
+
basePercentiles[0] * 100,
|
| 276 |
+
basePercentiles[1] * 100,
|
| 277 |
+
basePercentiles[2] * 100,
|
| 278 |
+
] + [(t * 100) / safeOneVoice * basePercentiles[1] for t in timeList]
|
| 279 |
+
+ [(t * 100) / summativeMultiSpeaker * basePercentiles[2] for t in multiTimeList],
|
| 280 |
+
"parentPercentiles": [
|
| 281 |
+
basePercentiles[0] * 100,
|
| 282 |
+
basePercentiles[1] * 100,
|
| 283 |
+
basePercentiles[2] * 100,
|
| 284 |
+
] + [(t * 100) / safeOneVoice for t in timeList]
|
| 285 |
+
+ [(t * 100) / summativeMultiSpeaker for t in multiTimeList],
|
| 286 |
+
})
|
| 287 |
df5.name = "df5"
|
| 288 |
st.session_state.summaries[currFileIndex]["df5"] = df5
|
| 289 |
+
printV(f'Set df5', 4)
|
| 290 |
+
|
| 291 |
+
# --- Build speakers_dataFrame, df2 ---
|
| 292 |
+
speakers_dataFrame, speakers_times = su.annotationToDataFrame(currAnnotation)
|
| 293 |
st.session_state.summaries[currFileIndex]["speakers_dataFrame"] = speakers_dataFrame
|
| 294 |
st.session_state.summaries[currFileIndex]["speakers_times"] = speakers_times
|
| 295 |
|
| 296 |
df2_dict = {
|
| 297 |
+
"values": [100 * t / currTotalTime for t in df4_dict["values"]],
|
| 298 |
+
"names": df4_dict["names"],
|
| 299 |
}
|
| 300 |
df2 = pd.DataFrame(df2_dict)
|
| 301 |
st.session_state.summaries[currFileIndex]["df2"] = df2
|
| 302 |
+
printV(f'Set df2', 4)
|
| 303 |
except Exception as e:
|
| 304 |
import traceback
|
| 305 |
print(f"Error in analyze: {e}")
|