import streamlit as st from st_aggrid import AgGrid import pandas as pd # from PIL import Image from transformers import pipeline st.set_page_config(layout="wide") # im = Image.open("ai-favicon.png") # st.set_page_config(page_title="Table Summarization", # page_icon=im,layout='wide') style = ''' ''' st.markdown(style, unsafe_allow_html=True) st.markdown('

Table Question Answering using TAPAS

', unsafe_allow_html=True) st.markdown("

Pre-trained TAPAS model runs on max 64 rows and 32 columns data. Make sure the file data doesn't exceed these dimensions.

", unsafe_allow_html=True) tqa = pipeline(task="table-question-answering", model="google/tapas-base-finetuned-wtq") # st.sidebar.image("ai-logo.png",width=200) # with open('data.csv', 'rb') as f: # st.sidebar.download_button('Download sample data', f, file_name='Sample Data.csv') file_name = st.sidebar.file_uploader("Upload file:", type=['csv','xlsx']) if file_name is None: st.markdown('

Please upload an excel or csv file

', unsafe_allow_html=True) # st.image("loader.png") else: try: df=pd.read_csv(file_name) except: df = pd.read_excel(file_name) grid_response = AgGrid( df.head(5), columns_auto_size_mode='FIT_CONTENTS', editable=True, height=300, width='100%', ) question = st.text_input('Type your question') df = df.astype(str) with st.spinner(): if(st.button('Answer')): answer = tqa(table=df, query=question,truncation=True) st.markdown("

Results

",unsafe_allow_html = True) st.success(answer)