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

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +106 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ assemblyai
2
+ streamlit