abhisheksasidharanr commited on
Commit
d5bb9eb
1 Parent(s): 4f651a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +92 -105
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
- class SentimentType(Enum):
7
- NEUTRAL = 'neutral'
8
- POSITIVE = 'POSITIVE'
9
- NEGATIVE = 'NEGATIVE'
10
-
11
- class Entry:
12
- def __init__(self, text, start, end, confidence, speaker, sentiment):
13
- self.text = text
14
- self.start = start
15
- self.end = end
16
- self.confidence = confidence
17
- self.speaker = speaker
18
- self.sentiment = sentiment
19
-
20
- if 'body' not in st.session_state:
21
- st.session_state.body = []
22
-
23
- st.session_state.summary = ""
24
- st.session_state.senti = ""
25
- def readFiles(file):
26
- audio_process(file)
27
-
28
- def audio_process(file):
29
- aai.settings.api_key = "ea2cabb1f91545f28590043ea73fc63c"
30
- config = aai.TranscriptionConfig(
31
- speech_model=aai.SpeechModel.best,
32
- iab_categories=True,
33
- # auto_chapters=True,
34
- # content_safety=True,
35
- # auto_highlights=True,
36
- sentiment_analysis=True,
37
- entity_detection=True,
38
- speaker_labels=True,
39
- # filter_profanity=True,
40
- language_detection=True,
41
- summarization=True,
42
- # summary_type=aai.SummarizationType.bullets
43
- ).set_redact_pii(
44
- policies=[
45
- aai.PIIRedactionPolicy.medical_condition,
46
- # aai.PIIRedactionPolicy.email_address,
47
- # aai.PIIRedactionPolicy.phone_number,
48
- # aai.PIIRedactionPolicy.banking_information,
49
- # aai.PIIRedactionPolicy.credit_card_number,
50
- # aai.PIIRedactionPolicy.credit_card_cvv,
51
- # aai.PIIRedactionPolicy.date_of_birth,
52
- # aai.PIIRedactionPolicy.person_name
53
- ]
54
- )
55
-
56
- transcriber = aai.Transcriber(config=config)
57
- transcript = transcriber.transcribe(file)
58
-
59
- if transcript.status == aai.TranscriptStatus.error:
60
- print(transcript.error)
61
- else:
62
- for utterance in transcript.utterances:
63
- result = {'speaker': utterance.speaker, 'answer': utterance.text}
64
- st.session_state.body.append(result)
65
- st.session_state.summary = transcript.summary
66
- negative = 0
67
- positive = 0
68
- neutral = 0
69
- for sentiment_result in transcript.sentiment_analysis:
70
- sents = sentiment_result.sentiment
71
-
72
- if sents.value=='NEGATIVE':
73
- negative = negative+1
74
- if sents.value=='NEUTRAL':
75
- neutral = neutral+1
76
- if sents.value=='POSITIVE':
77
- positive = positive+1
78
-
79
- st.session_state.senti = f"Neutral: {neutral}, Positive : {positive}, Negative : {negative}"
80
-
81
-
82
- col1, col2 = st.columns(2)
83
- def main():
84
- with st.sidebar:
85
- st.header("Upload Audio File Here", divider='rainbow')
86
- files = st.file_uploader('', accept_multiple_files=False)
87
- button = st.button("Process")
88
- if button:
89
- if files:
90
- with st.spinner("Processing"):
91
- readFiles(files)
92
- else:
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()