Niranjana commited on
Commit
050a844
1 Parent(s): 040f789

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -20
app.py CHANGED
@@ -1,40 +1,65 @@
 
1
  import streamlit as st
 
 
2
  from transformers import pipeline
3
- import pandas as pd
4
  st.set_page_config(layout="wide")
5
 
 
 
 
 
 
6
  style = '''
7
  <style>
8
  header {visibility: hidden;}
9
  div.block-container {padding-top:4rem;}
 
 
 
 
 
 
10
  </style>
11
  '''
12
  st.markdown(style, unsafe_allow_html=True)
13
 
 
 
 
14
  tqa = pipeline(task="table-question-answering",
15
  model="google/tapas-base-finetuned-wtq")
16
 
17
- st.title("Table Question Answering using TAPAS")
18
-
19
- 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)
20
 
21
- file_name = st.file_uploader("Upload dataset",type=['csv','xlsx'])
 
 
 
22
 
23
- if file_name is not None:
24
- try:
25
- df=pd.read_csv(file_name)
26
- except:
27
- df = pd.read_excel(file_name)
28
- df = df.astype(str)
29
 
30
- st.markdown("<p style='font-family:sans-serif;font-size: 0.9rem;'> Data - Top 5 records</p>",unsafe_allow_html = True)
31
- st.table(df.head(5))
 
 
 
 
32
 
33
- question = st.text_input('Type your question')
34
- with st.spinner():
35
- if(st.button('Answer')):
36
- answer = tqa(table=df, query=question,truncation=True)
37
- st.markdown("<p style='font-family:sans-serif;font-size: 0.9rem;'> Results </p>",unsafe_allow_html = True)
38
- st.success(answer)
 
 
39
 
40
-
 
 
 
 
 
 
 
1
+ from st_aggrid import AgGrid
2
  import streamlit as st
3
+ import pandas as pd
4
+ # from PIL import Image
5
  from transformers import pipeline
 
6
  st.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
+
13
  style = '''
14
  <style>
15
  header {visibility: hidden;}
16
  div.block-container {padding-top:4rem;}
17
+ section[data-testid="stSidebar"] div:first-child {
18
+ padding-top: 0;
19
+ }
20
+ .font {
21
+ text-align:center;
22
+ font-family:sans-serif;font-size: 1.25rem;}
23
  </style>
24
  '''
25
  st.markdown(style, unsafe_allow_html=True)
26
 
27
+ st.markdown('<p style="font-family:sans-serif;font-size: 1.9rem;">Table Question Answering using TAPAS</p>', unsafe_allow_html=True)
28
+ 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)
29
+
30
  tqa = pipeline(task="table-question-answering",
31
  model="google/tapas-base-finetuned-wtq")
32
 
 
 
 
33
 
34
+ # st.sidebar.image("ai-logo.png",width=200)
35
+ with open('data.csv', 'rb') as f:
36
+ st.sidebar.download_button('Download sample data', f, file_name='Sample Data.csv')
37
+ file_name = st.sidebar.file_uploader("Upload file:", type=['csv','xlsx'])
38
 
39
+ if file_name is None:
40
+ st.markdown('<p class="font">Please upload an excel or csv file </p>', unsafe_allow_html=True)
41
+ # st.image("loader.png")
 
 
 
42
 
43
+ else:
44
+ try:
45
+ df=pd.read_csv(file_name)
46
+ except:
47
+ df = pd.read_excel(file_name)
48
+ df = df.astype(str)
49
 
50
+
51
+ grid_response = AgGrid(
52
+ df.head(5),
53
+ columns_auto_size_mode='FIT_CONTENTS',
54
+ editable=True,
55
+ height=300,
56
+ width='100%',
57
+ )
58
 
59
+ question = st.text_input('Type your question')
60
+ with st.spinner():
61
+ if(st.button('Answer')):
62
+ answer = tqa(table=df, query=question,truncation=True)
63
+ st.markdown("<p style='font-family:sans-serif;font-size: 0.9rem;'> Results </p>",unsafe_allow_html = True)
64
+ st.success(answer)
65
+