Spaces:
Build error
Build error
knkarthick
commited on
Commit
•
bebf963
1
Parent(s):
4cfa601
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.system("pip install gradio==3.0.18")
|
3 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification, AutoModelForTokenClassification
|
4 |
+
import gradio as gr
|
5 |
+
import spacy
|
6 |
+
nlp = spacy.load('en_core_web_sm')
|
7 |
+
nlp.add_pipe('sentencizer')
|
8 |
+
|
9 |
+
def split_in_sentences(text):
|
10 |
+
doc = nlp(text)
|
11 |
+
return [str(sent).strip() for sent in doc.sents]
|
12 |
+
|
13 |
+
def make_spans(text,results):
|
14 |
+
results_list = []
|
15 |
+
for i in range(len(results)):
|
16 |
+
results_list.append(results[i]['label'])
|
17 |
+
facts_spans = []
|
18 |
+
facts_spans = list(zip(split_in_sentences(text),results_list))
|
19 |
+
return facts_spans
|
20 |
+
|
21 |
+
auth_token = os.environ.get("HF_Token")
|
22 |
+
|
23 |
+
##Speech Recognition
|
24 |
+
asr = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
|
25 |
+
def transcribe(audio):
|
26 |
+
text = asr(audio)["text"]
|
27 |
+
return text
|
28 |
+
def speech_to_text(speech):
|
29 |
+
text = asr(speech)["text"]
|
30 |
+
return text
|
31 |
+
|
32 |
+
##Summarization
|
33 |
+
summarizer = pipeline("summarization", model="knkarthick/MEETING_SUMMARY")
|
34 |
+
def summarize_text(text):
|
35 |
+
resp = summarizer(text)
|
36 |
+
stext = resp[0]['summary_text']
|
37 |
+
return stext
|
38 |
+
|
39 |
+
##Fiscal Tone Analysis
|
40 |
+
fin_model= pipeline("sentiment-analysis", model='knkarthick/Sentiment-Analysis', tokenizer='knkarthick/Sentiment-Analysis')
|
41 |
+
def text_to_sentiment(text):
|
42 |
+
sentiment = fin_model(text)[0]["label"]
|
43 |
+
return sentiment
|
44 |
+
|
45 |
+
##Fiscal Sentiment by Sentence
|
46 |
+
def fin_ext(text):
|
47 |
+
results = fin_model(split_in_sentences(text))
|
48 |
+
return make_spans(text,results)
|
49 |
+
|
50 |
+
demo = gr.Blocks()
|
51 |
+
|
52 |
+
with demo:
|
53 |
+
gr.Markdown("## Meeting Transcript AI Use Cases")
|
54 |
+
gr.Markdown("Takes Meeting Data/ Recording/ Record Meetings and give out Summary & Sentiment of the discussion")
|
55 |
+
with gr.Row():
|
56 |
+
with gr.Column():
|
57 |
+
audio_file = gr.inputs.Audio(source="microphone", type="filepath")
|
58 |
+
with gr.Row():
|
59 |
+
b1 = gr.Button("Recognize Speech")
|
60 |
+
with gr.Row():
|
61 |
+
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.")
|
62 |
+
b1.click(speech_to_text, inputs=audio_file, outputs=text)
|
63 |
+
with gr.Row():
|
64 |
+
b2 = gr.Button("Summarize Text")
|
65 |
+
stext = gr.Textbox()
|
66 |
+
b2.click(summarize_text, inputs=text, outputs=stext)
|
67 |
+
with gr.Row():
|
68 |
+
b3 = gr.Button("Overall Meeting Sentiment")
|
69 |
+
label = gr.Label()
|
70 |
+
b3.click(text_to_sentiment, inputs=stext, outputs=label)
|
71 |
+
with gr.Row():
|
72 |
+
b5 = gr.Button("Dialogue Sentiment Analysis")
|
73 |
+
fin_spans = gr.HighlightedText()
|
74 |
+
b5.click(fin_ext, inputs=text, outputs=fin_spans)
|
75 |
+
demo.launch()
|