Spaces:
Build error
Build error
Commit
·
5d9b7cd
1
Parent(s):
26691e0
Add application file
Browse files- .ipynb_checkpoints/app-checkpoint.py +107 -0
- app.py +42 -10
.ipynb_checkpoints/app-checkpoint.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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-BART-LARGE-XSUM-SAMSUM-DIALOGSUM")
|
| 34 |
+
def summarize_text(text):
|
| 35 |
+
resp = summarizer(text)
|
| 36 |
+
stext = resp[0]['summary_text']
|
| 37 |
+
return stext
|
| 38 |
+
|
| 39 |
+
summarizer1 = pipeline("summarization", model="knkarthick/MEETING_SUMMARY")
|
| 40 |
+
def summarize_text1(text):
|
| 41 |
+
resp = summarizer1(text)
|
| 42 |
+
stext = resp[0]['summary_text']
|
| 43 |
+
return stext
|
| 44 |
+
|
| 45 |
+
summarizer2 = pipeline("summarization", model="knkarthick/MEETING-SUMMARY-BART-LARGE-XSUM-SAMSUM-DIALOGSUM-AMI")
|
| 46 |
+
def summarize_text2(text):
|
| 47 |
+
resp = summarizer2(text)
|
| 48 |
+
stext = resp[0]['summary_text']
|
| 49 |
+
return stext
|
| 50 |
+
|
| 51 |
+
##Fiscal Tone Analysis
|
| 52 |
+
fin_model= pipeline("sentiment-analysis", model='knkarthick/Sentiment-Analysis', tokenizer='knkarthick/Sentiment-Analysis')
|
| 53 |
+
def text_to_sentiment(text):
|
| 54 |
+
sentiment = fin_model(text)[0]["label"]
|
| 55 |
+
return sentiment
|
| 56 |
+
|
| 57 |
+
##Fiscal Sentiment by Sentence
|
| 58 |
+
def fin_ext(text):
|
| 59 |
+
results = fin_model(split_in_sentences(text))
|
| 60 |
+
return make_spans(text,results)
|
| 61 |
+
|
| 62 |
+
demo = gr.Blocks()
|
| 63 |
+
|
| 64 |
+
with demo:
|
| 65 |
+
gr.Markdown("## Meeting Transcript AI Use Cases")
|
| 66 |
+
gr.Markdown("Takes Meeting Data/ Recording/ Record Meetings and give out Summary & Sentiment of the discussion")
|
| 67 |
+
with gr.Row():
|
| 68 |
+
with gr.Column():
|
| 69 |
+
audio_file = gr.inputs.Audio(source="microphone", type="filepath")
|
| 70 |
+
with gr.Row():
|
| 71 |
+
b1 = gr.Button("Recognize Speech")
|
| 72 |
+
with gr.Row():
|
| 73 |
+
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.")
|
| 74 |
+
b1.click(speech_to_text, inputs=audio_file, outputs=text)
|
| 75 |
+
with gr.Row():
|
| 76 |
+
b2 = gr.Button("Dialogue Sentiment Analysis")
|
| 77 |
+
fin_spans = gr.HighlightedText()
|
| 78 |
+
b2.click(fin_ext, inputs=text, outputs=fin_spans)
|
| 79 |
+
with gr.Row():
|
| 80 |
+
b3 = gr.Button("Summarize Text [Model-I/ Model-II/ Model-III]")
|
| 81 |
+
with gr.Column():
|
| 82 |
+
with gr.Row():
|
| 83 |
+
stext = gr.Textbox()
|
| 84 |
+
b3.click(summarize_text, inputs=text, outputs=stext)
|
| 85 |
+
with gr.Column():
|
| 86 |
+
with gr.Row():
|
| 87 |
+
stext = gr.Textbox()
|
| 88 |
+
b3.click(summarize_text1, inputs=text, outputs=stext1)
|
| 89 |
+
with gr.Column():
|
| 90 |
+
with gr.Row():
|
| 91 |
+
stext = gr.Textbox()
|
| 92 |
+
b3.click(summarize_text2, inputs=text, outputs=stext2)
|
| 93 |
+
with gr.Row():
|
| 94 |
+
b4 = gr.Button("Sentiment of Summary-I/ Summary-II/ Summary-III")
|
| 95 |
+
with gr.Column():
|
| 96 |
+
with gr.Row():
|
| 97 |
+
stext = gr.Label()
|
| 98 |
+
b4.click(text_to_sentiment, inputs=stext, outputs=label)
|
| 99 |
+
with gr.Column():
|
| 100 |
+
with gr.Row():
|
| 101 |
+
stext = gr.Label()
|
| 102 |
+
b4.click(text_to_sentiment, inputs=stext1, outputs=label)
|
| 103 |
+
with gr.Column():
|
| 104 |
+
with gr.Row():
|
| 105 |
+
stext = gr.Label()
|
| 106 |
+
b4.click(text_to_sentiment, inputs=stext2, outputs=label)
|
| 107 |
+
demo.launch()
|
app.py
CHANGED
|
@@ -29,13 +29,25 @@ def speech_to_text(speech):
|
|
| 29 |
text = asr(speech)["text"]
|
| 30 |
return text
|
| 31 |
|
| 32 |
-
##Summarization
|
| 33 |
-
summarizer = pipeline("summarization", model="knkarthick/
|
| 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):
|
|
@@ -61,15 +73,35 @@ with demo:
|
|
| 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("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
stext = gr.Textbox()
|
| 66 |
-
|
|
|
|
| 67 |
with gr.Row():
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
| 71 |
with gr.Row():
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
demo.launch()
|
|
|
|
| 29 |
text = asr(speech)["text"]
|
| 30 |
return text
|
| 31 |
|
| 32 |
+
##Summarization
|
| 33 |
+
summarizer = pipeline("summarization", model="knkarthick/MEETING-SUMMARY-BART-LARGE-XSUM-SAMSUM-DIALOGSUM")
|
| 34 |
def summarize_text(text):
|
| 35 |
resp = summarizer(text)
|
| 36 |
stext = resp[0]['summary_text']
|
| 37 |
return stext
|
| 38 |
|
| 39 |
+
summarizer1 = pipeline("summarization", model="knkarthick/MEETING_SUMMARY")
|
| 40 |
+
def summarize_text1(text):
|
| 41 |
+
resp = summarizer1(text)
|
| 42 |
+
stext = resp[0]['summary_text']
|
| 43 |
+
return stext
|
| 44 |
+
|
| 45 |
+
summarizer2 = pipeline("summarization", model="knkarthick/MEETING-SUMMARY-BART-LARGE-XSUM-SAMSUM-DIALOGSUM-AMI")
|
| 46 |
+
def summarize_text2(text):
|
| 47 |
+
resp = summarizer2(text)
|
| 48 |
+
stext = resp[0]['summary_text']
|
| 49 |
+
return stext
|
| 50 |
+
|
| 51 |
##Fiscal Tone Analysis
|
| 52 |
fin_model= pipeline("sentiment-analysis", model='knkarthick/Sentiment-Analysis', tokenizer='knkarthick/Sentiment-Analysis')
|
| 53 |
def text_to_sentiment(text):
|
|
|
|
| 73 |
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.")
|
| 74 |
b1.click(speech_to_text, inputs=audio_file, outputs=text)
|
| 75 |
with gr.Row():
|
| 76 |
+
b2 = gr.Button("Dialogue Sentiment Analysis")
|
| 77 |
+
fin_spans = gr.HighlightedText()
|
| 78 |
+
b2.click(fin_ext, inputs=text, outputs=fin_spans)
|
| 79 |
+
with gr.Row():
|
| 80 |
+
b3 = gr.Button("Summarize Text [Model-I/ Model-II/ Model-III]")
|
| 81 |
+
with gr.Column():
|
| 82 |
+
with gr.Row():
|
| 83 |
+
stext = gr.Textbox()
|
| 84 |
+
b3.click(summarize_text, inputs=text, outputs=stext)
|
| 85 |
+
with gr.Column():
|
| 86 |
+
with gr.Row():
|
| 87 |
stext = gr.Textbox()
|
| 88 |
+
b3.click(summarize_text1, inputs=text, outputs=stext1)
|
| 89 |
+
with gr.Column():
|
| 90 |
with gr.Row():
|
| 91 |
+
stext = gr.Textbox()
|
| 92 |
+
b3.click(summarize_text2, inputs=text, outputs=stext2)
|
| 93 |
+
with gr.Row():
|
| 94 |
+
b4 = gr.Button("Sentiment of Summary-I/ Summary-II/ Summary-III")
|
| 95 |
+
with gr.Column():
|
| 96 |
with gr.Row():
|
| 97 |
+
stext = gr.Label()
|
| 98 |
+
b4.click(text_to_sentiment, inputs=stext, outputs=label)
|
| 99 |
+
with gr.Column():
|
| 100 |
+
with gr.Row():
|
| 101 |
+
stext = gr.Label()
|
| 102 |
+
b4.click(text_to_sentiment, inputs=stext1, outputs=label)
|
| 103 |
+
with gr.Column():
|
| 104 |
+
with gr.Row():
|
| 105 |
+
stext = gr.Label()
|
| 106 |
+
b4.click(text_to_sentiment, inputs=stext2, outputs=label)
|
| 107 |
demo.launch()
|