File size: 1,315 Bytes
48f1ac0
 
420a54e
17863dd
48f1ac0
040f789
 
 
 
 
 
 
 
420a54e
51df1fc
48f1ac0
89bf98d
 
7370a0f
48f1ac0
420a54e
48f1ac0
 
420a54e
 
 
 
 
48f1ac0
d333cf0
 
fd3c1f3
420a54e
 
 
 
ba52786
420a54e
7370a0f
fd3c1f3
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
import streamlit as st
from transformers import pipeline
import pandas as pd
st.set_page_config(layout="wide")

style = '''
    <style>
        header {visibility: hidden;}
        div.block-container {padding-top:4rem;}
    </style>
'''
st.markdown(style, unsafe_allow_html=True)

tqa = pipeline(task="table-question-answering", 
                    model="google/tapas-base-finetuned-wtq")

st.title("Table Question Answering using TAPAS")

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)

file_name = st.file_uploader("Upload dataset",type=['csv','xlsx'])

if file_name is not None:
  try:
      df=pd.read_csv(file_name)
  except:
      df = pd.read_excel(file_name)
  df = df.astype(str)

  st.markdown("<p style='font-family:sans-serif;font-size: 0.9rem;'> Data - Top 5 records</p>",unsafe_allow_html = True)
  st.table(df.head(5))

  question = st.text_input('Type your question')
  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)