Spaces:
Sleeping
Sleeping
File size: 1,103 Bytes
20bd02e ba79e6e 20bd02e 1bfc16c 20bd02e ba79e6e 20bd02e caec00a 1bfc16c ba79e6e 20bd02e ba79e6e 20bd02e ba79e6e 20bd02e ba79e6e |
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 |
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.
""")
|