Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	| 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 | |
| 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() | 
