jskinner215/TAPAS_Churn
0
1import streamlit as st2from st_aggrid import AgGrid3import pandas as pd 4# from PIL import Image5from transformers import pipeline6st.set_page_config(layout="wide")7 8# im = Image.open("ai-favicon.png")9# st.set_page_config(page_title="Table Summarization",10# page_icon=im,layout='wide') 11 12 13style = '''14 <style>15 body {background-color: #F5F5F5; color: #000000;}16 header {visibility: hidden;}17 div.block-container {padding-top:4rem;}18 section[data-testid="stSidebar"] div:first-child {19 padding-top: 0;20 }21 .font { 22 text-align:center;23 font-family:sans-serif;font-size: 1.25rem;}24 </style>25'''26st.markdown(style, unsafe_allow_html=True)27 28st.markdown('<p style="font-family:sans-serif;font-size: 1.9rem;">Table Question Answering using TAPAS</p>', unsafe_allow_html=True)29st.markdown("<p style='font-family:sans-serif;font-size: 0.9rem;'>Pre-trained TAPAS model runs on max 64 rows and 32 columns data. Make sure the file data doesn't exceed these dimensions.</p>", unsafe_allow_html=True)30 31tqa = pipeline(task="table-question-answering", 32 model="google/tapas-large-finetuned-wtq")33 34 35# st.sidebar.image("ai-logo.png",width=200)36# with open('data.csv', 'rb') as f:37# st.sidebar.download_button('Download sample data', f, file_name='Sample Data.csv')38file_name = st.sidebar.file_uploader("Upload file:", type=['csv','xlsx'])39 40if file_name is None:41 st.markdown('<p class="font">Please upload an excel or csv file </p>', unsafe_allow_html=True)42 # st.image("loader.png")43 44else:45 try:46 df=pd.read_csv(file_name)47 except:48 df = pd.read_excel(file_name)49 50 grid_response = AgGrid(51 df.head(5),52 columns_auto_size_mode='FIT_CONTENTS',53 editable=True, 54 height=300, 55 width='100%',56 )57 58 question = st.text_input('Type your question')59 df = df.astype(str)60 61 with st.spinner():62 if(st.button('Answer')):63 answer = tqa(table=df, query=question,truncation=True)64 st.markdown("<p style='font-family:sans-serif;font-size: 0.9rem;'> Results </p>",unsafe_allow_html = True)65 st.success(answer)