Spaces:
Sleeping
Sleeping
Commit
·
5f7785f
1
Parent(s):
16ffb5d
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from st_aggrid import AgGrid
|
| 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-large-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 |
+
|
| 49 |
+
grid_response = AgGrid(
|
| 50 |
+
df.head(5),
|
| 51 |
+
columns_auto_size_mode='FIT_CONTENTS',
|
| 52 |
+
editable=True,
|
| 53 |
+
height=300,
|
| 54 |
+
width='100%',
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
question = st.text_input('Type your question')
|
| 58 |
+
df = df.astype(str)
|
| 59 |
+
|
| 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)
|