|
import streamlit as st
|
|
import assemblyai as aai
|
|
|
|
from enum import Enum
|
|
|
|
class SentimentType(Enum):
|
|
NEUTRAL = 'neutral'
|
|
POSITIVE = 'POSITIVE'
|
|
NEGATIVE = 'NEGATIVE'
|
|
|
|
class Entry:
|
|
def __init__(self, text, start, end, confidence, speaker, sentiment):
|
|
self.text = text
|
|
self.start = start
|
|
self.end = end
|
|
self.confidence = confidence
|
|
self.speaker = speaker
|
|
self.sentiment = sentiment
|
|
|
|
if 'body' not in st.session_state:
|
|
st.session_state.body = []
|
|
|
|
st.session_state.summary = ""
|
|
st.session_state.senti = ""
|
|
def readFiles(file):
|
|
audio_process(file)
|
|
|
|
def audio_process(file):
|
|
aai.settings.api_key = "ea2cabb1f91545f28590043ea73fc63c"
|
|
config = aai.TranscriptionConfig(
|
|
speech_model=aai.SpeechModel.best,
|
|
iab_categories=True,
|
|
|
|
|
|
|
|
sentiment_analysis=True,
|
|
entity_detection=True,
|
|
speaker_labels=True,
|
|
|
|
language_detection=True,
|
|
summarization=True,
|
|
|
|
).set_redact_pii(
|
|
policies=[
|
|
aai.PIIRedactionPolicy.medical_condition,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
]
|
|
)
|
|
|
|
transcriber = aai.Transcriber(config=config)
|
|
transcript = transcriber.transcribe(file)
|
|
|
|
if transcript.status == aai.TranscriptStatus.error:
|
|
print(transcript.error)
|
|
else:
|
|
for utterance in transcript.utterances:
|
|
result = {'speaker': utterance.speaker, 'answer': utterance.text}
|
|
st.session_state.body.append(result)
|
|
st.session_state.summary = transcript.summary
|
|
negative = 0
|
|
positive = 0
|
|
neutral = 0
|
|
for sentiment_result in transcript.sentiment_analysis:
|
|
sents = sentiment_result.sentiment
|
|
|
|
if sents.value=='NEGATIVE':
|
|
negative = negative+1
|
|
if sents.value=='NEUTRAL':
|
|
neutral = neutral+1
|
|
if sents.value=='POSITIVE':
|
|
positive = positive+1
|
|
|
|
st.session_state.senti = f"Neutral: {neutral}, Positive : {positive}, Negative : {negative}"
|
|
|
|
|
|
col1, col2 = st.columns(2)
|
|
def main():
|
|
with st.sidebar:
|
|
st.header("Upload Audio File Here", divider='rainbow')
|
|
files = st.file_uploader('', accept_multiple_files=False)
|
|
button = st.button("Process")
|
|
if button:
|
|
if files:
|
|
with st.spinner("Processing"):
|
|
readFiles(files)
|
|
else:
|
|
st.error('No files selected')
|
|
|
|
with col1:
|
|
st.subheader('CONVERSATIONS', divider='rainbow')
|
|
for chat in st.session_state.body:
|
|
with st.chat_message(chat["speaker"]):
|
|
st.write(chat["answer"])
|
|
with col2:
|
|
st.subheader('SUMMARY', divider='rainbow')
|
|
st.write(st.session_state.summary)
|
|
st.subheader('SENTIMENT ANALYSIS', divider='rainbow')
|
|
st.write(st.session_state.senti)
|
|
if __name__ == "__main__":
|
|
main() |