rajistics commited on
Commit
43c6f10
1 Parent(s): 86aec17

First push

Browse files
Files changed (4) hide show
  1. .gitattributes +0 -4
  2. README.md +5 -4
  3. app.py +96 -0
  4. requirements.txt +5 -0
.gitattributes CHANGED
@@ -9,13 +9,9 @@
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
- *.npy filter=lfs diff=lfs merge=lfs -text
13
- *.npz filter=lfs diff=lfs merge=lfs -text
14
  *.onnx filter=lfs diff=lfs merge=lfs -text
15
  *.ot filter=lfs diff=lfs merge=lfs -text
16
  *.parquet filter=lfs diff=lfs merge=lfs -text
17
- *.pickle filter=lfs diff=lfs merge=lfs -text
18
- *.pkl filter=lfs diff=lfs merge=lfs -text
19
  *.pb filter=lfs diff=lfs merge=lfs -text
20
  *.pt filter=lfs diff=lfs merge=lfs -text
21
  *.pth 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
README.md CHANGED
@@ -1,12 +1,13 @@
1
  ---
2
  title: Financial Analyst AI
3
- emoji: 💻
4
- colorFrom: purple
5
- colorTo: pink
6
  sdk: gradio
7
- sdk_version: 3.1.1
8
  app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
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
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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', api_key=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
+ results = fls_model(split_in_sentences(text))
60
+ return make_spans(text,results)
61
+
62
+ demo = gr.Blocks()
63
+
64
+ with demo:
65
+ gr.Markdown("## Financial Analyst AI")
66
+ gr.Markdown("This project applies AI trained by our financial analysts to analyze earning calls and other financial documents.")
67
+ with gr.Row():
68
+ with gr.Column():
69
+ audio_file = gr.inputs.Audio(source="microphone", type="filepath")
70
+ with gr.Row():
71
+ b1 = gr.Button("Recognize Speech")
72
+ with gr.Row():
73
+ 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.")
74
+ b1.click(speech_to_text, inputs=audio_file, outputs=text)
75
+ with gr.Row():
76
+ b2 = gr.Button("Summarize Text")
77
+ stext = gr.Textbox()
78
+ b2.click(summarize_text, inputs=text, outputs=stext)
79
+ with gr.Row():
80
+ b3 = gr.Button("Classify Financial Tone")
81
+ label = gr.Label()
82
+ b3.click(text_to_sentiment, inputs=stext, outputs=label)
83
+ with gr.Column():
84
+ b5 = gr.Button("Financial Tone and Forward Looking Statement Analysis")
85
+ with gr.Row():
86
+ fin_spans = gr.HighlightedText()
87
+ b5.click(fin_ext, inputs=text, outputs=fin_spans)
88
+ with gr.Row():
89
+ fls_spans = gr.HighlightedText()
90
+ b5.click(fls, inputs=text, outputs=fls_spans)
91
+ with gr.Row():
92
+ b4 = gr.Button("Identify Companies & Locations")
93
+ replaced_spans = gr.HighlightedText()
94
+ b4.click(fin_ner, inputs=text, outputs=replaced_spans)
95
+
96
+ 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