Spaces:
Sleeping
Sleeping
Init app.py
Browse filesInitial app.py code
app.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import matplotlib.pyplot as matplotlib
|
| 3 |
+
import numpy as np
|
| 4 |
+
import torchaudio
|
| 5 |
+
import sonogram_utility as su
|
| 6 |
+
import time
|
| 7 |
+
|
| 8 |
+
st.title("Lecturer Support Tool")
|
| 9 |
+
|
| 10 |
+
file_name = st.file_uploader("Upload an audio of classroom activity to analyze")
|
| 11 |
+
|
| 12 |
+
supported_file_types = ['.wav','.mp3','.mp4']
|
| 13 |
+
|
| 14 |
+
if file_name is not None:
|
| 15 |
+
if not file_name.endswith(supported_file_types):
|
| 16 |
+
st.error('File must be of type: {}'.format(supported_file_types))
|
| 17 |
+
file_name = st.empty()
|
| 18 |
+
else:
|
| 19 |
+
st.audio(file_name)
|
| 20 |
+
if st.button("Analyze Audio"):
|
| 21 |
+
if file_name is None:
|
| 22 |
+
st.error('Upload a file first!')
|
| 23 |
+
else:
|
| 24 |
+
# Process
|
| 25 |
+
# Pretend to take time as an example
|
| 26 |
+
with st.spinner(text='NOT ACTUALLY ANALYZING, JUST A FILLER ANIMATION'):
|
| 27 |
+
time.sleep(5)
|
| 28 |
+
st.success('Done')
|
| 29 |
+
|
| 30 |
+
# RTTM load as filler
|
| 31 |
+
speakerList, annotations = su.loadAudioRTTM("24F CHEM1402 Night Class Week 4.rttm")
|
| 32 |
+
|
| 33 |
+
# Display breakdowns
|
| 34 |
+
#--------------------------------------------------------------------------
|
| 35 |
+
|
| 36 |
+
# Prepare data
|
| 37 |
+
sortedSpeakerList = sorted([[row for row in speaker if row[1] > 0.25] for speaker in speakerList if len([row for row in speaker if row[1] > 0.25]) > 0],
|
| 38 |
+
key=lambda e: min(e)[0])
|
| 39 |
+
pred_count = len(sortedSpeakerList)
|
| 40 |
+
lecturer_speaker_list = su.twoClassExtendAnnotation(sortedSpeakerList)
|
| 41 |
+
lecturer_pred_count = len(lecturer_speaker_list)
|
| 42 |
+
|
| 43 |
+
# Lecturer vs. Audience
|
| 44 |
+
#---------------------------------------------------------------------------
|
| 45 |
+
|
| 46 |
+
f, ax1 =plt.subplots()
|
| 47 |
+
|
| 48 |
+
# Setting Y-axis limits
|
| 49 |
+
ax1.set_ylim(0, lecturer_pred_count*5 + 5)
|
| 50 |
+
|
| 51 |
+
# Setting X-axis limits
|
| 52 |
+
#gnt.set_xlim(0, 160)
|
| 53 |
+
|
| 54 |
+
# Setting labels for x-axis and y-axis
|
| 55 |
+
ax1.set_title('Recording Results')
|
| 56 |
+
ax1.set_xlabel('Minutes since start')
|
| 57 |
+
ax1.set_ylabel('Speaker ID')
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
# Setting ticks on y-axis (5,10,15,...)
|
| 61 |
+
step = 5
|
| 62 |
+
ax1.set_yticks(list(range(step,(lecturer_pred_count+1)*step,step)))
|
| 63 |
+
# Labelling tickes of y-axis ('1','2','3',...)
|
| 64 |
+
pred_tick_list = [1,2]
|
| 65 |
+
ax1.set_yticklabels(["Lectuerer","Audience"]))
|
| 66 |
+
x_tick_list = range(0,6000,60)
|
| 67 |
+
ax1.set_xticks(x_tick_list)
|
| 68 |
+
ax1.set_xticklabels([str(int(element/60)) for element in x_tick_list])
|
| 69 |
+
ax1.tick_params(axis='x', labelrotation=90)
|
| 70 |
+
# Setting graph attribute
|
| 71 |
+
ax1.grid(True)
|
| 72 |
+
|
| 73 |
+
pred_colors = su.colors(lecturer_pred_count)
|
| 74 |
+
for j, row in enumerate(lecturer_speaker_list):
|
| 75 |
+
ax1.broken_barh(row, ((j+1)*5-1, 3), facecolors =(pred_colors[j]))
|
| 76 |
+
|
| 77 |
+
f.set_figheight(5)
|
| 78 |
+
f.set_figwidth(15)
|
| 79 |
+
|
| 80 |
+
st.pyplot(f)
|
| 81 |
+
|
| 82 |
+
# Experimental Speaker Breakdown
|
| 83 |
+
#------------------------------------------------------------------------------
|
| 84 |
+
|
| 85 |
+
f, ax1 =plt.subplots()
|
| 86 |
+
|
| 87 |
+
# Setting Y-axis limits
|
| 88 |
+
ax1.set_ylim(0, pred_count*5 + 5)
|
| 89 |
+
|
| 90 |
+
# Setting X-axis limits
|
| 91 |
+
#gnt.set_xlim(0, 160)
|
| 92 |
+
|
| 93 |
+
# Setting labels for x-axis and y-axis
|
| 94 |
+
ax1.set_title('Recording Results')
|
| 95 |
+
ax1.set_xlabel('Minutes since start')
|
| 96 |
+
ax1.set_ylabel('Speaker ID')
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
# Setting ticks on y-axis (5,10,15,...)
|
| 100 |
+
step = 5
|
| 101 |
+
ax1.set_yticks(list(range(step,(pred_count+1)*step,step)))
|
| 102 |
+
# Labelling tickes of y-axis ('1','2','3',...)
|
| 103 |
+
pred_tick_list = range(1,pred_count+1)
|
| 104 |
+
ax1.set_yticklabels([str(element) for element in pred_tick_list])
|
| 105 |
+
x_tick_list = range(0,6000,60)
|
| 106 |
+
ax1.set_xticks(x_tick_list)
|
| 107 |
+
ax1.set_xticklabels([str(int(element/60)) for element in x_tick_list])
|
| 108 |
+
ax1.tick_params(axis='x', labelrotation=90)
|
| 109 |
+
# Setting graph attribute
|
| 110 |
+
ax1.grid(True)
|
| 111 |
+
|
| 112 |
+
pred_colors = su.colors(pred_count)
|
| 113 |
+
for j, row in enumerate(sortedSpeakerList):
|
| 114 |
+
ax1.broken_barh(row, ((j+1)*5-1, 3), facecolors =(pred_colors[j]))
|
| 115 |
+
|
| 116 |
+
f.set_figheight(5)
|
| 117 |
+
f.set_figwidth(15)
|
| 118 |
+
|
| 119 |
+
st.pyplot(f)
|
| 120 |
+
|