Updated names on buttons
Browse files
app.py
CHANGED
@@ -6,8 +6,6 @@ import gradio as gr
|
|
6 |
import spacy
|
7 |
nlp = spacy.load('en_core_web_sm')
|
8 |
|
9 |
-
auth_token = os.environ.get("HF_Token")
|
10 |
-
|
11 |
##Speech Recognition
|
12 |
asr = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
|
13 |
def transcribe(audio):
|
@@ -24,10 +22,9 @@ def summarize_text(text):
|
|
24 |
stext = resp[0]['summary_text']
|
25 |
return stext
|
26 |
|
27 |
-
##Fiscal
|
28 |
#fin_model = pipeline("text-classification", model="demo-org/auditor_review_model",
|
29 |
# tokenizer="demo-org/auditor_review_model",use_auth_token=auth_token)
|
30 |
-
#fin_model = pipeline("text-classification")
|
31 |
fin_model= pipeline("sentiment-analysis", model='yiyanghkust/finbert-tone', tokenizer='yiyanghkust/finbert-tone')
|
32 |
def text_to_sentiment(text):
|
33 |
sentiment = fin_model(text)[0]["label"]
|
@@ -35,36 +32,27 @@ def text_to_sentiment(text):
|
|
35 |
|
36 |
##Company Extraction
|
37 |
def fin_ner(text):
|
38 |
-
print ("ner")
|
39 |
-
#ner_pipeline = pipeline("ner", model="dslim/bert-base-NER", tokenizer="dslim/bert-base-NER")
|
40 |
api = gr.Interface.load("dslim/bert-base-NER", src='models')
|
41 |
replaced_spans = api(text)
|
42 |
-
print (replaced_spans)
|
43 |
-
print ("spans2")
|
44 |
-
#replaced_spans = [(key, None) if value=='No Disease' else (key, value) for (key, value) in spans]
|
45 |
return replaced_spans
|
46 |
|
47 |
##Fiscal Sentiment by Sentence
|
48 |
def fin_ext(text):
|
49 |
-
print ("sent")
|
50 |
doc = nlp(text)
|
51 |
doc_sents = [sent for sent in doc.sents]
|
52 |
sents_list = []
|
53 |
for sent in doc.sents:
|
54 |
sents_list.append(sent.text)
|
55 |
results = fin_model(sents_list)
|
56 |
-
print (results)
|
57 |
results_list = []
|
58 |
for i in range(len(results)):
|
59 |
results_list.append(results[i]['label'])
|
60 |
fin_spans = []
|
61 |
fin_spans = list(zip(sents_list,results_list))
|
62 |
-
print (fin_spans)
|
63 |
return fin_spans
|
64 |
|
65 |
##Forward Looking Statement
|
66 |
def fls(text):
|
67 |
-
print ("fls")
|
68 |
doc = nlp(text)
|
69 |
doc_sents = [sent for sent in doc.sents]
|
70 |
sents_list = []
|
@@ -72,13 +60,11 @@ def fls(text):
|
|
72 |
sents_list.append(sent.text)
|
73 |
fls_model = pipeline("text-classification", model="yiyanghkust/finbert-fls", tokenizer="yiyanghkust/finbert-fls")
|
74 |
results = fls_model(sents_list)
|
75 |
-
print (results)
|
76 |
results_list = []
|
77 |
for i in range(len(results)):
|
78 |
results_list.append(results[i]['label'])
|
79 |
fls_spans = []
|
80 |
fls_spans = list(zip(sents_list,results_list))
|
81 |
-
print (fls_spans)
|
82 |
return fls_spans
|
83 |
|
84 |
demo = gr.Blocks()
|
@@ -97,11 +83,11 @@ with demo:
|
|
97 |
stext = gr.Textbox()
|
98 |
b2.click(summarize_text, inputs=text, outputs=stext)
|
99 |
with gr.Row():
|
100 |
-
b3 = gr.Button("Classify
|
101 |
label = gr.Label()
|
102 |
b3.click(text_to_sentiment, inputs=stext, outputs=label)
|
103 |
with gr.Column():
|
104 |
-
b5 = gr.Button("
|
105 |
with gr.Row():
|
106 |
fin_spans = gr.HighlightedText()
|
107 |
b5.click(fin_ext, inputs=text, outputs=fin_spans)
|
@@ -109,7 +95,7 @@ with demo:
|
|
109 |
fls_spans = gr.HighlightedText()
|
110 |
b5.click(fls, inputs=text, outputs=fls_spans)
|
111 |
with gr.Row():
|
112 |
-
b4 = gr.Button("
|
113 |
replaced_spans = gr.HighlightedText()
|
114 |
b4.click(fin_ner, inputs=text, outputs=replaced_spans)
|
115 |
|
|
|
6 |
import spacy
|
7 |
nlp = spacy.load('en_core_web_sm')
|
8 |
|
|
|
|
|
9 |
##Speech Recognition
|
10 |
asr = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
|
11 |
def transcribe(audio):
|
|
|
22 |
stext = resp[0]['summary_text']
|
23 |
return stext
|
24 |
|
25 |
+
##Fiscal Tone Analysis
|
26 |
#fin_model = pipeline("text-classification", model="demo-org/auditor_review_model",
|
27 |
# tokenizer="demo-org/auditor_review_model",use_auth_token=auth_token)
|
|
|
28 |
fin_model= pipeline("sentiment-analysis", model='yiyanghkust/finbert-tone', tokenizer='yiyanghkust/finbert-tone')
|
29 |
def text_to_sentiment(text):
|
30 |
sentiment = fin_model(text)[0]["label"]
|
|
|
32 |
|
33 |
##Company Extraction
|
34 |
def fin_ner(text):
|
|
|
|
|
35 |
api = gr.Interface.load("dslim/bert-base-NER", src='models')
|
36 |
replaced_spans = api(text)
|
|
|
|
|
|
|
37 |
return replaced_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 = fin_model(sents_list)
|
|
|
47 |
results_list = []
|
48 |
for i in range(len(results)):
|
49 |
results_list.append(results[i]['label'])
|
50 |
fin_spans = []
|
51 |
fin_spans = list(zip(sents_list,results_list))
|
|
|
52 |
return fin_spans
|
53 |
|
54 |
##Forward Looking Statement
|
55 |
def fls(text):
|
|
|
56 |
doc = nlp(text)
|
57 |
doc_sents = [sent for sent in doc.sents]
|
58 |
sents_list = []
|
|
|
60 |
sents_list.append(sent.text)
|
61 |
fls_model = pipeline("text-classification", model="yiyanghkust/finbert-fls", tokenizer="yiyanghkust/finbert-fls")
|
62 |
results = fls_model(sents_list)
|
|
|
63 |
results_list = []
|
64 |
for i in range(len(results)):
|
65 |
results_list.append(results[i]['label'])
|
66 |
fls_spans = []
|
67 |
fls_spans = list(zip(sents_list,results_list))
|
|
|
68 |
return fls_spans
|
69 |
|
70 |
demo = gr.Blocks()
|
|
|
83 |
stext = gr.Textbox()
|
84 |
b2.click(summarize_text, inputs=text, outputs=stext)
|
85 |
with gr.Row():
|
86 |
+
b3 = gr.Button("Classify Financial Tone")
|
87 |
label = gr.Label()
|
88 |
b3.click(text_to_sentiment, inputs=stext, outputs=label)
|
89 |
with gr.Column():
|
90 |
+
b5 = gr.Button("Financial Tone and Forward Looking Statement Analysis")
|
91 |
with gr.Row():
|
92 |
fin_spans = gr.HighlightedText()
|
93 |
b5.click(fin_ext, inputs=text, outputs=fin_spans)
|
|
|
95 |
fls_spans = gr.HighlightedText()
|
96 |
b5.click(fls, inputs=text, outputs=fls_spans)
|
97 |
with gr.Row():
|
98 |
+
b4 = gr.Button("Identify Companies & Locations")
|
99 |
replaced_spans = gr.HighlightedText()
|
100 |
b4.click(fin_ner, inputs=text, outputs=replaced_spans)
|
101 |
|