sohomghosh commited on
Commit
4d9bf04
β€’
1 Parent(s): 50a57bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -2
app.py CHANGED
@@ -8,13 +8,27 @@ 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)
@@ -28,8 +42,8 @@ def score_fincat(txt):
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()
 
8
  lr_clf = pickle.load(open("lr_clf_FiNCAT.pickle",'rb'))
9
 
10
  def score_fincat(txt):
11
+ '''
12
+ Extracts numerals from financial texts and checks if they are in-claim or out-of claim
13
+
14
+ Parameters:
15
+ txt (str): Financial Text. This is to be given as input. Numerals present in this text will be evaluated.
16
+
17
+ Returns:
18
+ highlight (list): A list each element of which is a tuple. Each tuple has two elements i) word ii) whether the word is in-claim or out-of-claim.
19
+ dff (pandas dataframe): A pandas dataframe having three columns 'numeral', 'prediction' (whether the word is in-claim or out-of-claim) and 'probability' (probabilty of the prediction).
20
+ '''
21
  li = []
22
  highlight = []
23
+ txt = " " + txt + " "
24
+ k = ''
25
  for word in txt.split():
26
  if any(char.isdigit() for char in word):
27
  if word[-1] in ['.', ',', ';', ":", "-", "!", "?", ")", '"', "'"]:
28
+ k = word[-1]
29
  word = word[:-1]
30
+ st = txt.index(" " + word + k + " ")+1
31
+ k = ''
32
  ed = st + len(word)
33
  x = {'paragraph' : txt, 'offset_start':st, 'offset_end':ed}
34
  context_text = extract_context_words(x)
 
42
  headers = ['numeral', 'prediction', 'probability']
43
  dff = pd.DataFrame(li)
44
  dff.columns = headers
 
45
  return highlight, dff
46
 
47
+
48
  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"])
49
  iface.launch()