abhisheksasidharanr
commited on
Commit
•
d5bb9eb
1
Parent(s):
4f651a5
Update app.py
Browse files
app.py
CHANGED
@@ -1,106 +1,93 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import assemblyai as aai
|
3 |
-
|
4 |
-
from enum import Enum
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
#
|
34 |
-
#
|
35 |
-
#
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
#
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
if
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
col1
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
st.error('No files selected')
|
94 |
-
|
95 |
-
with col1:
|
96 |
-
st.subheader('CONVERSATIONS', divider='rainbow')
|
97 |
-
for chat in st.session_state.body:
|
98 |
-
with st.chat_message(chat["speaker"]):
|
99 |
-
st.write(chat["answer"])
|
100 |
-
with col2:
|
101 |
-
st.subheader('SUMMARY', divider='rainbow')
|
102 |
-
st.write(st.session_state.summary)
|
103 |
-
st.subheader('SENTIMENT ANALYSIS', divider='rainbow')
|
104 |
-
st.write(st.session_state.senti)
|
105 |
-
if __name__ == "__main__":
|
106 |
main()
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import assemblyai as aai
|
3 |
+
|
4 |
+
from enum import Enum
|
5 |
+
|
6 |
+
|
7 |
+
if 'body' not in st.session_state:
|
8 |
+
st.session_state.body = []
|
9 |
+
|
10 |
+
st.session_state.summary = ""
|
11 |
+
st.session_state.senti = ""
|
12 |
+
def readFiles(file):
|
13 |
+
audio_process(file)
|
14 |
+
|
15 |
+
def audio_process(file):
|
16 |
+
aai.settings.api_key = st.secrets["ASSEMBLY_KEY"]
|
17 |
+
config = aai.TranscriptionConfig(
|
18 |
+
speech_model=aai.SpeechModel.best,
|
19 |
+
iab_categories=True,
|
20 |
+
# auto_chapters=True,
|
21 |
+
# content_safety=True,
|
22 |
+
# auto_highlights=True,
|
23 |
+
sentiment_analysis=True,
|
24 |
+
entity_detection=True,
|
25 |
+
speaker_labels=True,
|
26 |
+
# filter_profanity=True,
|
27 |
+
language_detection=True,
|
28 |
+
summarization=True,
|
29 |
+
# summary_type=aai.SummarizationType.bullets
|
30 |
+
).set_redact_pii(
|
31 |
+
policies=[
|
32 |
+
aai.PIIRedactionPolicy.medical_condition,
|
33 |
+
# aai.PIIRedactionPolicy.email_address,
|
34 |
+
# aai.PIIRedactionPolicy.phone_number,
|
35 |
+
# aai.PIIRedactionPolicy.banking_information,
|
36 |
+
# aai.PIIRedactionPolicy.credit_card_number,
|
37 |
+
# aai.PIIRedactionPolicy.credit_card_cvv,
|
38 |
+
# aai.PIIRedactionPolicy.date_of_birth,
|
39 |
+
# aai.PIIRedactionPolicy.person_name
|
40 |
+
]
|
41 |
+
)
|
42 |
+
|
43 |
+
transcriber = aai.Transcriber(config=config)
|
44 |
+
transcript = transcriber.transcribe(file)
|
45 |
+
|
46 |
+
if transcript.status == aai.TranscriptStatus.error:
|
47 |
+
print(transcript.error)
|
48 |
+
else:
|
49 |
+
for utterance in transcript.utterances:
|
50 |
+
result = {'speaker': utterance.speaker, 'answer': utterance.text}
|
51 |
+
st.session_state.body.append(result)
|
52 |
+
st.session_state.summary = transcript.summary
|
53 |
+
negative = 0
|
54 |
+
positive = 0
|
55 |
+
neutral = 0
|
56 |
+
for sentiment_result in transcript.sentiment_analysis:
|
57 |
+
sents = sentiment_result.sentiment
|
58 |
+
|
59 |
+
if sents.value=='NEGATIVE':
|
60 |
+
negative = negative+1
|
61 |
+
if sents.value=='NEUTRAL':
|
62 |
+
neutral = neutral+1
|
63 |
+
if sents.value=='POSITIVE':
|
64 |
+
positive = positive+1
|
65 |
+
|
66 |
+
st.session_state.senti = f"Neutral: {neutral}, Positive : {positive}, Negative : {negative}"
|
67 |
+
|
68 |
+
|
69 |
+
col1, col2 = st.columns(2)
|
70 |
+
def main():
|
71 |
+
with st.sidebar:
|
72 |
+
st.header("Upload Audio File Here", divider='rainbow')
|
73 |
+
files = st.file_uploader('', accept_multiple_files=False)
|
74 |
+
button = st.button("Process")
|
75 |
+
if button:
|
76 |
+
if files:
|
77 |
+
with st.spinner("Processing"):
|
78 |
+
readFiles(files)
|
79 |
+
else:
|
80 |
+
st.error('No files selected')
|
81 |
+
|
82 |
+
with col1:
|
83 |
+
st.subheader('CONVERSATIONS', divider='rainbow')
|
84 |
+
for chat in st.session_state.body:
|
85 |
+
with st.chat_message(chat["speaker"]):
|
86 |
+
st.write(chat["answer"])
|
87 |
+
with col2:
|
88 |
+
st.subheader('SUMMARY', divider='rainbow')
|
89 |
+
st.write(st.session_state.summary)
|
90 |
+
st.subheader('SENTIMENT ANALYSIS', divider='rainbow')
|
91 |
+
st.write(st.session_state.senti)
|
92 |
+
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
main()
|