Spaces:
Runtime error
Runtime error
Commit
•
952a6aa
0
Parent(s):
Duplicate from rajistics/Financial_Analyst_AI
Browse filesCo-authored-by: Rajiv Shah <[email protected]>
- .gitattributes +27 -0
- README.md +14 -0
- app.py +97 -0
- requirements.txt +5 -0
.gitattributes
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
19 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
11 |
+
duplicated_from: rajistics/Financial_Analyst_AI
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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")
|
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='yiyanghkust/finbert-tone', tokenizer='yiyanghkust/finbert-tone')
|
41 |
+
def text_to_sentiment(text):
|
42 |
+
sentiment = fin_model(text)[0]["label"]
|
43 |
+
return sentiment
|
44 |
+
|
45 |
+
##Company Extraction
|
46 |
+
def fin_ner(text):
|
47 |
+
api = gr.Interface.load("dslim/bert-base-NER", src='models', use_auth_token=auth_token)
|
48 |
+
replaced_spans = api(text)
|
49 |
+
return replaced_spans
|
50 |
+
|
51 |
+
##Fiscal Sentiment by Sentence
|
52 |
+
def fin_ext(text):
|
53 |
+
results = fin_model(split_in_sentences(text))
|
54 |
+
return make_spans(text,results)
|
55 |
+
|
56 |
+
##Forward Looking Statement
|
57 |
+
def fls(text):
|
58 |
+
# fls_model = pipeline("text-classification", model="yiyanghkust/finbert-fls", tokenizer="yiyanghkust/finbert-fls")
|
59 |
+
fls_model = pipeline("text-classification", model="demo-org/finbert_fls", tokenizer="demo-org/finbert_fls", use_auth_token=auth_token)
|
60 |
+
results = fls_model(split_in_sentences(text))
|
61 |
+
return make_spans(text,results)
|
62 |
+
|
63 |
+
demo = gr.Blocks()
|
64 |
+
|
65 |
+
with demo:
|
66 |
+
gr.Markdown("## Financial Analyst AI")
|
67 |
+
gr.Markdown("This project applies AI trained by our financial analysts to analyze earning calls and other financial documents.")
|
68 |
+
with gr.Row():
|
69 |
+
with gr.Column():
|
70 |
+
audio_file = gr.inputs.Audio(source="microphone", type="filepath")
|
71 |
+
with gr.Row():
|
72 |
+
b1 = gr.Button("Recognize Speech")
|
73 |
+
with gr.Row():
|
74 |
+
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.")
|
75 |
+
b1.click(speech_to_text, inputs=audio_file, outputs=text)
|
76 |
+
with gr.Row():
|
77 |
+
b2 = gr.Button("Summarize Text")
|
78 |
+
stext = gr.Textbox()
|
79 |
+
b2.click(summarize_text, inputs=text, outputs=stext)
|
80 |
+
with gr.Row():
|
81 |
+
b3 = gr.Button("Classify Financial Tone")
|
82 |
+
label = gr.Label()
|
83 |
+
b3.click(text_to_sentiment, inputs=stext, outputs=label)
|
84 |
+
with gr.Column():
|
85 |
+
b5 = gr.Button("Financial Tone and Forward Looking Statement Analysis")
|
86 |
+
with gr.Row():
|
87 |
+
fin_spans = gr.HighlightedText()
|
88 |
+
b5.click(fin_ext, inputs=text, outputs=fin_spans)
|
89 |
+
with gr.Row():
|
90 |
+
fls_spans = gr.HighlightedText()
|
91 |
+
b5.click(fls, inputs=text, outputs=fls_spans)
|
92 |
+
with gr.Row():
|
93 |
+
b4 = gr.Button("Identify Companies & Locations")
|
94 |
+
replaced_spans = gr.HighlightedText()
|
95 |
+
b4.click(fin_ner, inputs=text, outputs=replaced_spans)
|
96 |
+
|
97 |
+
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
|