FinRead / app.py
sohomghosh's picture
Update app.py
b6ce5cc
raw
history blame
1.36 kB
import pickle
#import joblib
import gradio as gr
from sentence_transformers import SentenceTransformer
import lightgbm
lr_clf_finbert = pickle.load(open("lr_clf_finread_new.pkl",'rb')) #pickle.load(open("lr_clf_finbert.pickle", 'rb')) #joblib.load('lgb.pkl')
#lr_clf_finread_new.pkl is a Logistic Regression model trained on 13K intances
#lr_clf_finbert.pickle is a Logistic Regression model trained on 8K instances
model = SentenceTransformer('ProsusAI/finbert')
def get_readability(text):
emd = model.encode([text])
ans = 'not readable'
if lr_clf_finbert.predict(emd)==1:
ans = 'readable'
score = str(round(lr_clf_finbert.predict_proba(emd)[0,1],4))
return "Prediction: "+ans +"\nPredicted probability: "+ score
iface = gr.Interface(fn=get_readability, inputs="textbox", title="FinRead",description="Financial Readability Assessment Tool", outputs="textbox", allow_flagging="never", examples=[['Inflation is the rate of increase in prices over a given period of time. Inflation is typically a broad measure, such as the overall increase in prices or the increase in the cost of living in a country.'], ['Legally assured line of credit with a bank'], ['A mutual fund is a type of financial vehicle made up of a pool of money collected from many investors to invest in securities like stocks, bonds, money market instruments']])
iface.launch()