Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
from transformers import pipeline | |
# Initialize the table-question-answering pipeline | |
tqa = pipeline(task="table-question-answering", model="google/tapas-large-finetuned-wtq") | |
# Streamlit app | |
st.title("Table Question Answering") | |
# File uploader for table data | |
uploaded_file = st.file_uploader("Upload a CSV file", type="csv") | |
# Text input for question | |
question = st.text_input("Enter your question:") | |
# Process table and question | |
if uploaded_file is not None and question: | |
try: | |
# Read table from CSV | |
table = pd.read_csv(uploaded_file) | |
# Display the table | |
st.write("Uploaded Table:") | |
st.dataframe(table) | |
# Convert DataFrame to the format expected by TAPAS | |
table_data = table.as_type(str) | |
# Get answer | |
answer = tqa(table=table_data, query=question)['cells'][0] | |
# Display the answer | |
st.write("Answer:", answer) | |
except Exception as e: | |
st.error(f"An error occurred: {e}") | |
# Instructions | |
st.markdown(""" | |
*First, upload a CSV file. | |
""") | |