Upload 3 files
Browse files- README.md +5 -5
- app.py +52 -0
- requirements.txt +5 -0
README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version:
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: apache-2.0
|
|
|
1 |
---
|
2 |
+
title: Financial Analyst AI
|
3 |
+
emoji: 🏢
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 3.0.15
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: apache-2.0
|
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
##Fiscal Sentiment by Sentence
|
22 |
+
fin_model= pipeline("sentiment-analysis", model='FinanceInc/auditor_sentiment_finetuned', tokenizer='FinanceInc/auditor_sentiment_finetuned')
|
23 |
+
def fin_ext(text):
|
24 |
+
results = fin_model(split_in_sentences(text))
|
25 |
+
return make_spans(text,results)
|
26 |
+
|
27 |
+
##Forward Looking Statement
|
28 |
+
def fls(text):
|
29 |
+
fls_model = pipeline("text-classification", model="FinanceInc/finbert_fls", tokenizer="FinanceInc/finbert_fls")
|
30 |
+
results = fls_model(split_in_sentences(text))
|
31 |
+
return make_spans(text,results)
|
32 |
+
|
33 |
+
demo = gr.Blocks()
|
34 |
+
|
35 |
+
with demo:
|
36 |
+
gr.Markdown("## Financial Analyst AI")
|
37 |
+
gr.Markdown("This project applies AI trained by our financial analysts to analyze earning calls and other financial documents.")
|
38 |
+
with gr.Row():
|
39 |
+
with gr.Column():
|
40 |
+
with gr.Row():
|
41 |
+
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.")
|
42 |
+
with gr.Row():
|
43 |
+
b5 = gr.Button("Run Sentiment Analysis and Forward Looking Statement Analysis")
|
44 |
+
with gr.Column():
|
45 |
+
with gr.Row():
|
46 |
+
fin_spans = gr.HighlightedText()
|
47 |
+
with gr.Row():
|
48 |
+
fls_spans = gr.HighlightedText()
|
49 |
+
b5.click(fin_ext, inputs=text, outputs=fin_spans)
|
50 |
+
b5.click(fls, inputs=text, outputs=fls_spans)
|
51 |
+
|
52 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|
3 |
+
spacy
|
4 |
+
https://huggingface.co/spacy/en_core_web_sm/resolve/main/en_core_web_sm-any-py3-none-any.whl
|
5 |
+
gradio==3.0.18
|