czyoung's picture
Update app.py
8cedd51 verified
raw
history blame
4.28 kB
import streamlit as st
import matplotlib.pyplot as plt
import numpy as np
import torchaudio
import sonogram_utility as su
import time
st.title("Lecturer Support Tool")
uploaded_file = st.file_uploader("Upload an audio of classroom activity to analyze")
supported_file_types = ('.wav','.mp3','.mp4')
if uploaded_file is not None:
if not uploaded_file.name.endswith(supported_file_types):
st.error('File must be of type: {}'.format(supported_file_types))
uploaded_file = st.empty()
else:
st.audio(uploaded_file)
if st.button("Analyze Audio"):
if uploaded_file is None:
st.error('Upload a file first!')
else:
# Process
# Pretend to take time as an example
with st.spinner(text='NOT ACTUALLY ANALYZING, JUST A FILLER ANIMATION'):
time.sleep(5)
st.success('Done')
# RTTM load as filler
speakerList, annotations = su.loadAudioRTTM("24F CHEM1402 Night Class Week 4.rttm")
# Display breakdowns
#--------------------------------------------------------------------------
# Prepare data
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],
key=lambda e: min(e)[0])
pred_count = len(sortedSpeakerList)
lecturer_speaker_list = su.twoClassExtendAnnotation(annotations)
lecturer_pred_count = len(lecturer_speaker_list)
# Lecturer vs. Audience
#---------------------------------------------------------------------------
f, ax1 =plt.subplots()
# Setting Y-axis limits
ax1.set_ylim(0, lecturer_pred_count*5 + 5)
# Setting X-axis limits
#gnt.set_xlim(0, 160)
# Setting labels for x-axis and y-axis
ax1.set_title('Recording Results')
ax1.set_xlabel('Minutes since start')
ax1.set_ylabel('Speaker ID')
# Setting ticks on y-axis (5,10,15,...)
step = 5
ax1.set_yticks(list(range(step,(lecturer_pred_count+1)*step,step)))
# Labelling tickes of y-axis ('1','2','3',...)
pred_tick_list = [1,2]
ax1.set_yticklabels(["Lectuerer","Audience"])
x_tick_list = range(0,6000,60)
ax1.set_xticks(x_tick_list)
ax1.set_xticklabels([str(int(element/60)) for element in x_tick_list])
ax1.tick_params(axis='x', labelrotation=90)
# Setting graph attribute
ax1.grid(True)
pred_colors = su.colors(lecturer_pred_count)
for j, row in enumerate(lecturer_speaker_list):
ax1.broken_barh(row, ((j+1)*5-1, 3), facecolors =(pred_colors[j]))
f.set_figheight(5)
f.set_figwidth(15)
st.pyplot(f)
# Experimental Speaker Breakdown
#------------------------------------------------------------------------------
f, ax1 =plt.subplots()
# Setting Y-axis limits
ax1.set_ylim(0, pred_count*5 + 5)
# Setting X-axis limits
#gnt.set_xlim(0, 160)
# Setting labels for x-axis and y-axis
ax1.set_title('Recording Results')
ax1.set_xlabel('Minutes since start')
ax1.set_ylabel('Speaker ID')
# Setting ticks on y-axis (5,10,15,...)
step = 5
ax1.set_yticks(list(range(step,(pred_count+1)*step,step)))
# Labelling tickes of y-axis ('1','2','3',...)
pred_tick_list = range(1,pred_count+1)
ax1.set_yticklabels([str(element) for element in pred_tick_list])
x_tick_list = range(0,6000,60)
ax1.set_xticks(x_tick_list)
ax1.set_xticklabels([str(int(element/60)) for element in x_tick_list])
ax1.tick_params(axis='x', labelrotation=90)
# Setting graph attribute
ax1.grid(True)
pred_colors = su.colors(pred_count)
for j, row in enumerate(sortedSpeakerList):
ax1.broken_barh(row, ((j+1)*5-1, 3), facecolors =(pred_colors[j]))
f.set_figheight(5)
f.set_figwidth(15)
st.pyplot(f)