File size: 2,181 Bytes
48f1ac0
3b35064
050a844
 
48f1ac0
17863dd
48f1ac0
050a844
 
 
 
 
040f789
 
 
 
050a844
 
 
 
 
 
040f789
 
 
 
050a844
 
 
420a54e
51df1fc
48f1ac0
 
050a844
a61dfc3
 
050a844
48f1ac0
050a844
 
 
48f1ac0
050a844
 
 
 
 
1bd69b2
050a844
 
 
 
 
 
 
7370a0f
050a844
1bd69b2
 
050a844
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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 = '''
    <style>
        header {visibility: hidden;}
        div.block-container {padding-top:4rem;}
        section[data-testid="stSidebar"] div:first-child {
        padding-top: 0;
    }
     .font {                                          
    text-align:center;
    font-family:sans-serif;font-size: 1.25rem;}
    </style>
'''
st.markdown(style, unsafe_allow_html=True)

st.markdown('<p style="font-family:sans-serif;font-size: 1.9rem;">Table Question Answering using TAPAS</p>', unsafe_allow_html=True)
st.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)

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('<p class="font">Please upload an excel or csv file </p>', 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("<p style='font-family:sans-serif;font-size: 0.9rem;'> Results </p>",unsafe_allow_html = True)
            st.success(answer)