Create new file
Browse files
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
7 |
+
nlp = spacy.load('en_core_web_sm')
|
8 |
+
nlp.add_pipe('sentencizer')
|
9 |
+
|
10 |
+
def split_in_sentences(text):
|
11 |
+
doc = nlp(text)
|
12 |
+
return [str(sent).strip() for sent in doc.sents]
|
13 |
+
|
14 |
+
def make_spans(text,results):
|
15 |
+
results_list = []
|
16 |
+
for i in range(len(results)):
|
17 |
+
results_list.append(results[i]['label'])
|
18 |
+
facts_spans = []
|
19 |
+
facts_spans = list(zip(split_in_sentences(text),results_list))
|
20 |
+
return facts_spans
|
21 |
+
|
22 |
+
##Fiscal Sentiment by Sentence
|
23 |
+
fin_model= pipeline("sentiment-analysis", model='FinanceInc/auditor_sentiment_finetuned', tokenizer='FinanceInc/auditor_sentiment_finetuned')
|
24 |
+
def fin_ext(text):
|
25 |
+
results = fin_model(split_in_sentences(text))
|
26 |
+
return make_spans(text,results)
|
27 |
+
|
28 |
+
##Forward Looking Statement
|
29 |
+
def fls(text):
|
30 |
+
fls_model = pipeline("text-classification", model="FinanceInc/finbert_fls", tokenizer="FinanceInc/finbert_fls")
|
31 |
+
results = fls_model(split_in_sentences(text))
|
32 |
+
return make_spans(text,results)
|
33 |
+
|
34 |
+
demo = gr.Blocks()
|
35 |
+
|
36 |
+
with demo:
|
37 |
+
gr.Markdown("## Financial Analyst AI")
|
38 |
+
gr.Markdown("This project applies AI trained by our financial analysts to analyze earning calls and other financial documents.")
|
39 |
+
with gr.Row():
|
40 |
+
with gr.Column():
|
41 |
+
with gr.Row():
|
42 |
+
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.")
|
43 |
+
with gr.Row():
|
44 |
+
b5 = gr.Button("Run Sentiment Analysis and Forward Looking Statement Analysis")
|
45 |
+
with gr.Column():
|
46 |
+
with gr.Row():
|
47 |
+
fin_spans = gr.HighlightedText()
|
48 |
+
with gr.Row():
|
49 |
+
fls_spans = gr.HighlightedText()
|
50 |
+
b5.click(fin_ext, inputs=text, outputs=fin_spans)
|
51 |
+
b5.click(fls, inputs=text, outputs=fls_spans)
|
52 |
+
|
53 |
+
demo.launch()
|