Spaces:
Sleeping
Sleeping
File size: 2,026 Bytes
7797cc9 0a39414 7797cc9 0a39414 |
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 55 56 57 |
import streamlit as st
import pandas as pd
import openpyxl
from io import BytesIO
from fetaqa import question_answering # Hypothetical module for FeTaQA logic
# Cache the DataFrame for performance
@st.cache(allow_output_mutation=True)
def load_data(uploaded_file):
if uploaded_file.name.endswith('.csv'):
df = pd.read_csv(uploaded_file)
elif uploaded_file.name.endswith(('.xlsx', '.xls')):
df = pd.read_excel(uploaded_file, engine='openpyxl')
else:
st.error("Unsupported file format. Please upload a CSV or XLSX file.")
return None
return df
def main():
st.title("FeTaQA Table Question Answering")
# File uploader
uploaded_file = st.file_uploader("Choose a CSV or Excel file", type=["csv", "xlsx", "xls"])
if uploaded_file is not None:
df = load_data(uploaded_file)
if df is not None:
st.write("Uploaded Table:")
st.dataframe(df)
# Question input
question = st.text_input("Ask a question about the table:")
# Question history
if 'question_history' not in st.session_state:
st.session_state['question_history'] = []
if st.button('Ask'):
if question:
answer = question_answering(df, question)
st.write(f"Answer: {answer}")
st.session_state['question_history'].append((question, answer))
# Displaying history
st.write("Question History:")
for q, a in st.session_state['question_history'][-5:]: # Show last 5 questions
st.write(f"**Q:** {q}")
st.write(f"**A:** {a}")
st.write("---")
# Reset history
if st.button('Clear History'):
st.session_state['question_history'] = []
if __name__ == "__main__":
main() |