File size: 1,018 Bytes
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
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:
    # Read table from CSV
    table = pd.read_csv(uploaded_file)

    # Display the table
    st.write("Uploaded Table:")
    st.write(table)

    # Get answer
    answer = tqa(table=table, query=question)['cells'][0]

    # Display the answer
    st.write("Answer:", answer)

# Instructions
st.markdown("""
*First, upload a CSV file containing your table data. The CSV should have headers for each column.*  
*Then, enter a question related to the table and press Enter to see the answer.*  
""")