Spaces:
Sleeping
Sleeping
File size: 1,825 Bytes
59737d6 945314c 59737d6 0a302b8 59737d6 0a302b8 bea7d89 5c8ed53 bea7d89 5c8ed53 |
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 |
import warnings
warnings.filterwarnings("ignore", category=UserWarning, module="torchvision")
warnings.filterwarnings("ignore", category=FutureWarning, module="transformers")
warnings.filterwarnings("ignore")
from transformers import pipeline
import pandas as pd
import streamlit as st
# Initialize the pipeline
pipe = pipeline("table-question-answering", model="google/tapas-large-finetuned-wtq")
st.set_page_config(page_title="Table Question Answering", layout="wide")
st.title("π Table Question Answering")
st.write("""
Welcome to the **Table Question Answering** app!
You can upload your own table and ask questions about it.
The model will analyze the table and provide accurate answers.
""")
# Step 1: Table input
st.header("π Step 1: Upload your table")
# Option to upload a excel file
uploaded_file = st.file_uploader("Upload your Excel file:", type=["xlsx"])
if uploaded_file is not None:
try:
table = pd.read_excel(uploaded_file)
st.success("Table uploaded successfully!")
st.write("### Preview of Uploaded Table:")
st.dataframe(table, use_container_width=True)
except Exception as e:
st.error(f"Error reading the file: {e}")
table = None
else:
st.info("Please upload an Excel file to proceed.")
table = None
st.divider()
st.header("β Step 2: Ask a Question")
query = st.text_input("Ask a question about the table:")
st.divider()
if st.button("π Get Answer"):
if table is not None and query:
table = table.astype(str) # Ensure all values are strings
result = pipe(table=table, query=query)
st.success("Answer:")
st.markdown(f"### {result['answer']}")
else:
st.warning("Please upload a table and enter a question before clicking 'Get Answer'.")
st.divider()
st.markdown("**β€οΈ**") |