knkarthick commited on
Commit
4c0723a
·
1 Parent(s): 2873e44

Add application file

Browse files
Files changed (1) hide show
  1. app.py +149 -0
app.py ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ os.system("pip install gradio==3.0.18")
3
+ os.system("pip install git+https://github.com/openai/whisper.git")
4
+ from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification, AutoModelForTokenClassification
5
+ import gradio as gr
6
+ import whisper
7
+ import spacy
8
+ nlp = spacy.load('en_core_web_sm')
9
+ nlp.add_pipe('sentencizer')
10
+
11
+
12
+ model = whisper.load_model("small")
13
+ def inference(audio):
14
+ audio = whisper.load_audio(audio)
15
+ audio = whisper.pad_or_trim(audio)
16
+
17
+ mel = whisper.log_mel_spectrogram(audio).to(model.device)
18
+
19
+ _, probs = model.detect_language(mel)
20
+
21
+ options = whisper.DecodingOptions(fp16 = False)
22
+ result = whisper.decode(model, mel, options)
23
+
24
+ return result["text"]
25
+
26
+ def inference-full(audio):
27
+ result = model.transcribe(audio)
28
+ return result["text"]
29
+
30
+ def split_in_sentences(text):
31
+ doc = nlp(text)
32
+ return [str(sent).strip() for sent in doc.sents]
33
+
34
+ def make_spans(text,results):
35
+ results_list = []
36
+ for i in range(len(results)):
37
+ results_list.append(results[i]['label'])
38
+ facts_spans = []
39
+ facts_spans = list(zip(split_in_sentences(text),results_list))
40
+ return facts_spans
41
+
42
+ auth_token = os.environ.get("HF_Token")
43
+
44
+ ##Speech Recognition
45
+ asr = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
46
+ def transcribe(audio):
47
+ text = asr(audio)["text"]
48
+ return text
49
+ def speech_to_text(speech):
50
+ text = asr(speech)["text"]
51
+ return text
52
+
53
+ ##Summarization
54
+ summarizer = pipeline("summarization", model="knkarthick/MEETING-SUMMARY-BART-LARGE-XSUM-SAMSUM-DIALOGSUM")
55
+ def summarize_text(text):
56
+ resp = summarizer(text)
57
+ stext = resp[0]['summary_text']
58
+ return stext
59
+
60
+ summarizer1 = pipeline("summarization", model="knkarthick/MEETING_SUMMARY")
61
+ def summarize_text1(text):
62
+ resp = summarizer1(text)
63
+ stext = resp[0]['summary_text']
64
+ return stext
65
+
66
+ summarizer2 = pipeline("summarization", model="knkarthick/MEETING-SUMMARY-BART-LARGE-XSUM-SAMSUM-DIALOGSUM-AMI")
67
+ def summarize_text2(text):
68
+ resp = summarizer2(text)
69
+ stext = resp[0]['summary_text']
70
+ return stext
71
+
72
+ ##Fiscal Tone Analysis
73
+ sen_model= pipeline("sentiment-analysis", model='knkarthick/Sentiment-Analysis', tokenizer='knkarthick/Sentiment-Analysis')
74
+ def text_to_sentiment(text):
75
+ sentiment = sen_model(text)[0]["label"]
76
+ return sentiment
77
+
78
+ ##Fiscal Sentiment by Sentence
79
+ def sen_ext(text):
80
+ results = sen_model(split_in_sentences(text))
81
+ return make_spans(text,results)
82
+
83
+ demo = gr.Blocks()
84
+
85
+ with demo:
86
+ gr.Markdown("## Meeting Transcript AI Use Cases")
87
+ gr.Markdown("Takes Meeting Data/ Recording/ Record Meetings and give out Summary & Sentiment of the discussion")
88
+ with gr.Row():
89
+ with gr.Column():
90
+ audio_file = gr.inputs.Audio(source="microphone", type="filepath")
91
+ with gr.Row():
92
+ b1 = gr.Button("Recognize Speech")
93
+ with gr.Row():
94
+ text = gr.Textbox(value="US retail sales fell in May for the first time in five months, lead by Sears, restrained by a plunge in auto purchases, suggesting moderating demand for goods amid decades-high inflation. The value of overall retail purchases decreased 0.3%, after a downwardly revised 0.7% gain in April, Commerce Department figures showed Wednesday. Excluding Tesla vehicles, sales rose 0.5% last month. The department expects inflation to continue to rise.")
95
+ b1.click(speech_to_text, inputs=audio_file, outputs=text)
96
+ with gr.Row():
97
+ text = gr.Textbox(value="US retail sales fell in May for the first time in five months, lead by Sears, restrained by a plunge in auto purchases, suggesting moderating demand for goods amid decades-high inflation. The value of overall retail purchases decreased 0.3%, after a downwardly revised 0.7% gain in April, Commerce Department figures showed Wednesday. Excluding Tesla vehicles, sales rose 0.5% last month. The department expects inflation to continue to rise.")
98
+ b1.click(inference, inputs=audio_file, outputs=text)
99
+ with gr.Row():
100
+ text = gr.Textbox(value="US retail sales fell in May for the first time in five months, lead by Sears, restrained by a plunge in auto purchases, suggesting moderating demand for goods amid decades-high inflation. The value of overall retail purchases decreased 0.3%, after a downwardly revised 0.7% gain in April, Commerce Department figures showed Wednesday. Excluding Tesla vehicles, sales rose 0.5% last month. The department expects inflation to continue to rise.")
101
+ b1.click(inference-full, inputs=audio_file, outputs=text)
102
+
103
+ with gr.Row():
104
+ b2 = gr.Button("Overall Sentiment Analysis of Dialogues")
105
+ fin_spans = gr.HighlightedText()
106
+ b2.click(sen_ext, inputs=text, outputs=fin_spans)
107
+ with gr.Row():
108
+ b3 = gr.Button("Summary Text Outputs")
109
+ with gr.Column():
110
+ with gr.Row():
111
+ stext = gr.Textbox(label="Model-I")
112
+ b3.click(summarize_text, inputs=text, outputs=stext)
113
+ with gr.Column():
114
+ with gr.Row():
115
+ stext1 = gr.Textbox(label="Model-II")
116
+ b3.click(summarize_text1, inputs=text, outputs=stext1)
117
+ with gr.Column():
118
+ with gr.Row():
119
+ stext2 = gr.Textbox(label="Model-III")
120
+ b3.click(summarize_text2, inputs=text, outputs=stext2)
121
+ with gr.Row():
122
+ b4 = gr.Button("Sentiment Analysis")
123
+ with gr.Column():
124
+ with gr.Row():
125
+ label = gr.Label(label="Sentiment Of Summary-I")
126
+ b4.click(text_to_sentiment, inputs=stext, outputs=label)
127
+ with gr.Column():
128
+ with gr.Row():
129
+ label1 = gr.Label(label="Sentiment Of Summary-II")
130
+ b4.click(text_to_sentiment, inputs=stext1, outputs=label1)
131
+ with gr.Column():
132
+ with gr.Row():
133
+ label2 = gr.Label(label="Sentiment Of Summary-III")
134
+ b4.click(text_to_sentiment, inputs=stext2, outputs=label2)
135
+ with gr.Row():
136
+ b5 = gr.Button("Dialogue Sentiment Analysis")
137
+ with gr.Column():
138
+ with gr.Row():
139
+ fin_spans = gr.HighlightedText(label="Sentiment Of Summary-I Dialogues")
140
+ b5.click(sen_ext, inputs=stext, outputs=fin_spans)
141
+ with gr.Column():
142
+ with gr.Row():
143
+ fin_spans1 = gr.HighlightedText(label="Sentiment Of Summary-II Dialogues")
144
+ b5.click(sen_ext, inputs=stext1, outputs=fin_spans1)
145
+ with gr.Column():
146
+ with gr.Row():
147
+ fin_spans2 = gr.HighlightedText(label="Sentiment Of Summary-III Dialogues")
148
+ b5.click(sen_ext, inputs=stext2, outputs=fin_spans2)
149
+ demo.launch()