Spaces:
Build error
Build error
Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
22 |
|
23 |
-
if file_name is
|
24 |
-
|
25 |
-
|
26 |
-
except:
|
27 |
-
df = pd.read_excel(file_name)
|
28 |
-
df = df.astype(str)
|
29 |
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
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 |
+
|