sohomghosh
commited on
Commit
•
42a15d2
1
Parent(s):
da62a59
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import nltk
|
3 |
+
import pandas as pd
|
4 |
+
nltk.download('punkt')
|
5 |
+
from fincat_utils import extract_context_words
|
6 |
+
from fincat_utils import bert_embedding_extract
|
7 |
+
import pickle
|
8 |
+
lr_clf = pickle.load(open("lr_clf_FiNCAT.pickle",'rb'))
|
9 |
+
|
10 |
+
def score_fincat(txt):
|
11 |
+
li = []
|
12 |
+
highlight = []
|
13 |
+
for word in txt.split():
|
14 |
+
if any(char.isdigit() for char in word):
|
15 |
+
if word[-1] in ['.', ',', ';', ":", "-", "!", "?", ")", '"', "'"]:
|
16 |
+
word = word[:-1]
|
17 |
+
st = txt.index(word)
|
18 |
+
ed = st + len(word)
|
19 |
+
x = {'paragraph' : txt, 'offset_start':st, 'offset_end':ed}
|
20 |
+
context_text = extract_context_words(x)
|
21 |
+
features = bert_embedding_extract(context_text, word)
|
22 |
+
prediction = lr_clf.predict(features.reshape(1, 768))
|
23 |
+
prediction_probability = '{:.4f}'.format(round(lr_clf.predict_proba(features.reshape(1, 768))[:,1][0], 4))
|
24 |
+
highlight.append((word, ' In-claim' if prediction==1 else 'Out-of-Claim'))
|
25 |
+
li.append([word,' In-claim' if prediction==1 else 'Out-of-Claim', prediction_probability])
|
26 |
+
else:
|
27 |
+
highlight.append((word, ' '))
|
28 |
+
headers = ['numeral', 'prediction', 'probability']
|
29 |
+
dff = pd.DataFrame(li)
|
30 |
+
dff.columns = headers
|
31 |
+
|
32 |
+
return highlight, dff
|
33 |
+
|
34 |
+
iface = gr.Interface(fn=score_fincat, inputs=gr.inputs.Textbox(lines=5, placeholder="Enter Financial Text here..."), title="FiNCAT-2",description="Financial Numeral Claim Analysis Tool (Enhanced)", outputs=["highlight", "dataframe"], allow_flagging="never", examples=["In the year 2021, the markets were bullish. We expect to boost our sales by 80% this year.", "Last year our profit was $2.2M. This year it will increase to $3M"])
|
35 |
+
iface.launch()
|