rajistics commited on
Commit
560a994
1 Parent(s): 58b2731

adding sentence level changes

Browse files
Files changed (1) hide show
  1. app.py +32 -8
app.py CHANGED
@@ -1,35 +1,54 @@
1
  from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
2
  import gradio as gr
3
  import os
 
 
 
4
  auth_token = os.environ.get("HF_Token")
5
 
 
6
  asr = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
7
- summarizer = pipeline("summarization", model="knkarthick/MEETING_SUMMARY")
8
- tokenizer = AutoTokenizer.from_pretrained("demo-org/auditor_review_model",use_auth_token=auth_token)
9
- audit_model = AutoModelForSequenceClassification.from_pretrained("demo-org/auditor_review_model",use_auth_token=auth_token)
10
- nlp = pipeline("text-classification", model=audit_model, tokenizer=tokenizer)
11
-
12
  def transcribe(audio):
13
  text = asr(audio)["text"]
14
  return text
15
-
16
  def speech_to_text(speech):
17
  text = asr(speech)["text"]
18
  return text
19
 
 
 
20
  def summarize_text(text):
21
  stext = summarizer(text)
22
  return stext
23
 
 
 
 
 
24
  def text_to_sentiment(text):
25
  sentiment = nlp(text)[0]["label"]
26
  return sentiment
27
-
 
28
  def ner(text):
29
  api = gr.Interface.load("dslim/bert-base-NER", src='models')
30
  spans = api(text)
31
  #replaced_spans = [(key, None) if value=='No Disease' else (key, value) for (key, value) in spans]
32
  return spans
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
  demo = gr.Blocks()
35
 
@@ -44,7 +63,7 @@ with demo:
44
  stext = gr.Textbox()
45
  b2.click(summarize_text, inputs=text, outputs=stext)
46
 
47
- b3 = gr.Button("Classify Sentiment")
48
  label = gr.Label()
49
  b3.click(text_to_sentiment, inputs=stext, outputs=label)
50
 
@@ -52,4 +71,9 @@ with demo:
52
  replaced_spans = gr.HighlightedText()
53
  b4.click(ner, inputs=text, outputs=replaced_spans)
54
 
 
 
 
 
 
55
  demo.launch(share=True)
 
1
  from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
2
  import gradio as gr
3
  import os
4
+ import spacy
5
+ nlp = spacy.load('en_core_web_sm')
6
+
7
  auth_token = os.environ.get("HF_Token")
8
 
9
+ ##Speech Recognition
10
  asr = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
 
 
 
 
 
11
  def transcribe(audio):
12
  text = asr(audio)["text"]
13
  return text
 
14
  def speech_to_text(speech):
15
  text = asr(speech)["text"]
16
  return text
17
 
18
+ ##Summarization
19
+ summarizer = pipeline("summarization", model="knkarthick/MEETING_SUMMARY")
20
  def summarize_text(text):
21
  stext = summarizer(text)
22
  return stext
23
 
24
+ ##Fiscal Sentiment
25
+ tokenizer = AutoTokenizer.from_pretrained("demo-org/auditor_review_model",use_auth_token=auth_token)
26
+ audit_model = AutoModelForSequenceClassification.from_pretrained("demo-org/auditor_review_model",use_auth_token=auth_token)
27
+ nlp = pipeline("text-classification", model=audit_model, tokenizer=tokenizer)
28
  def text_to_sentiment(text):
29
  sentiment = nlp(text)[0]["label"]
30
  return sentiment
31
+
32
+ ##Company Extraction
33
  def ner(text):
34
  api = gr.Interface.load("dslim/bert-base-NER", src='models')
35
  spans = api(text)
36
  #replaced_spans = [(key, None) if value=='No Disease' else (key, value) for (key, value) in spans]
37
  return spans
38
+
39
+ ##Fiscal Sentiment by Sentence
40
+ def fin_ext(text):
41
+ doc = nlp(text)
42
+ doc_sents = [sent for sent in doc.sents]
43
+ sents_list = []
44
+ for sent in doc.sents:
45
+ sents_list.append(sent.text)
46
+ results_list=[]
47
+ for i in range(len(results)):
48
+ results_list.append(results[i]['label'])
49
+ fin_spans = list(zip(sents_list,results_list))
50
+ return fin_spans
51
+
52
 
53
  demo = gr.Blocks()
54
 
 
63
  stext = gr.Textbox()
64
  b2.click(summarize_text, inputs=text, outputs=stext)
65
 
66
+ b3 = gr.Button("Classify Overall Financial Sentiment")
67
  label = gr.Label()
68
  b3.click(text_to_sentiment, inputs=stext, outputs=label)
69
 
 
71
  replaced_spans = gr.HighlightedText()
72
  b4.click(ner, inputs=text, outputs=replaced_spans)
73
 
74
+ b5 = gr.Button("Extract Financial Sentiment")
75
+ replaced_spans = gr.HighlightedText()
76
+ b5.click(fin_ext, inputs=text, outputs=fin_spans)
77
+
78
+
79
  demo.launch(share=True)