File size: 4,137 Bytes
9860c63
5956cea
eed3dce
ff39d68
560a994
 
 
a2d7e33
 
560a994
ff39d68
 
 
 
 
 
 
 
560a994
 
d250ad6
e839479
 
d250ad6
 
55a7c39
abeede4
ff39d68
c6df2b8
ff39d68
560a994
 
d26fdac
2044612
3c577a6
6f488a4
560a994
 
 
 
 
 
 
 
b29c07d
7ea20fe
560a994
 
7ea20fe
560a994
 
 
c108596
 
 
 
 
 
 
bbc6b50
 
c108596
 
 
 
 
 
 
f9c9210
35b1732
f9c9210
89d6376
2044612
f9c9210
 
 
 
 
 
ca70944
f9c9210
 
 
 
0b49090
f9c9210
55a7c39
f9c9210
0b49090
 
55a7c39
0b49090
f9c9210
 
c108596
ab0b158
19a1b5d
0b49090
55a7c39
0b49090
 
560a994
358709b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import os
os.system("pip install gradio==3.0.18")
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification, AutoModelForTokenClassification
import gradio as gr
import spacy
nlp = spacy.load('en_core_web_sm')

auth_token = os.environ.get("HF_Token")

##Speech Recognition
asr = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
def transcribe(audio):
    text = asr(audio)["text"]
    return text
def speech_to_text(speech):
    text = asr(speech)["text"]
    return text

##Summarization 
summarizer = pipeline("summarization", model="knkarthick/MEETING_SUMMARY")
def summarize_text(text):
    resp = summarizer(text)
    stext = resp[0]['summary_text']
    return stext

##Fiscal Tone Analysis
fin_model= pipeline("sentiment-analysis", model='yiyanghkust/finbert-tone', tokenizer='yiyanghkust/finbert-tone')
def text_to_sentiment(text):
    sentiment = fin_model(text)[0]["label"]
    return sentiment 

##Company Extraction    
def fin_ner(text):
    api = gr.Interface.load("dslim/bert-base-NER", src='models',use_auth_token=auth_token)
    replaced_spans = api(text)
    return replaced_spans    

##Fiscal Sentiment by Sentence
def fin_ext(text):
    doc = nlp(text)
    doc_sents = [sent for sent in doc.sents]
    sents_list = []
    for sent in doc.sents:
        sents_list.append(sent.text)
    results = fin_model(sents_list)
    results_list = []
    for i in range(len(results)):
        results_list.append(results[i]['label'])
    fin_spans = []
    fin_spans = list(zip(sents_list,results_list))
    return fin_spans    

##Forward Looking Statement
def fls(text):
    doc = nlp(text)
    doc_sents = [sent for sent in doc.sents]
    sents_list = []
    for sent in doc.sents:
        sents_list.append(sent.text)
    fls_model = pipeline("text-classification", model="yiyanghkust/finbert-fls", tokenizer="yiyanghkust/finbert-fls")
    results = fls_model(sents_list)
    results_list = []
    for i in range(len(results)):
        results_list.append(results[i]['label'])
    fls_spans = []
    fls_spans = list(zip(sents_list,results_list))
    return fls_spans  

demo = gr.Blocks()

with demo:
    gr.Markdown("## Financial Analyst AI")
    gr.Markdown("This project applies AI trained by our financial analysts to analyze earning calls and other financial documents.")
    with gr.Row():
        with gr.Column():
            audio_file = gr.inputs.Audio(source="microphone", type="filepath")
            with gr.Row():
                b1 = gr.Button("Recognize Speech") 
            with gr.Row():
                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.")
                b1.click(speech_to_text, inputs=audio_file, outputs=text)
            with gr.Row():
                b2 = gr.Button("Summarize Text")
                stext = gr.Textbox()
                b2.click(summarize_text, inputs=text, outputs=stext)     
            with gr.Row():
                b3 = gr.Button("Classify Financial Tone")
                label = gr.Label()
                b3.click(text_to_sentiment, inputs=stext, outputs=label)  
        with gr.Column():
            b5 = gr.Button("Financial Tone and Forward Looking Statement Analysis")
            with gr.Row():
                fin_spans = gr.HighlightedText()
                b5.click(fin_ext, inputs=text, outputs=fin_spans)
            with gr.Row():
                fls_spans = gr.HighlightedText()
                b5.click(fls, inputs=text, outputs=fls_spans)
            with gr.Row():
                b4 = gr.Button("Identify Companies & Locations")
                replaced_spans = gr.HighlightedText()
                b4.click(fin_ner, inputs=text, outputs=replaced_spans)
    
demo.launch()