sdripie commited on
Commit
5c8ed53
Β·
1 Parent(s): bea7d89

edit interface

Browse files
Files changed (1) hide show
  1. app.py +35 -33
app.py CHANGED
@@ -15,39 +15,41 @@ st.set_page_config(page_title="Table Question Answering", layout="wide")
15
  st.title("πŸ“Š Table Question Answering")
16
  st.write("""
17
  Welcome to the **Table Question Answering** app!
18
- You can upload or paste your own table and ask questions about it.
19
  The model will analyze the table and provide accurate answers.
20
  """)
21
 
22
-
23
- # Define the table data
24
- data = {
25
- "year": [1896, 1900, 1904, 2004, 2008, 2012],
26
- "city": ["athens", "paris", "st. louis", "athens", "beijing", "london"]
27
- }
28
- table = pd.DataFrame(data)
29
- table = table.astype(str) #ensure all values are strings
30
-
31
- st.title("Table Question Answering")
32
- st.write("### Input Table")
33
- st.dataframe(table)
34
-
35
- query = st.text_input("Ask a question about the table:", "In which year did beijing host the Olympic Games?")
36
-
37
- if "history" not in st.session_state:
38
- st.session_state.history = []
39
-
40
- #process query and display result
41
- if st.button("Get Answer"):
42
- result = pipe(table=table, query=query)
43
- st.session_state.history.append({"query": query, "answer": result["answer"]})
44
- st.write("### Answer")
45
- st.write(result["answer"])
46
-
47
- #show history
48
- if st.session_state.history:
49
- st.write("### Previous Questions and Answers")
50
- for item in st.session_state.history:
51
- st.write(f"**Q:** {item['query']}")
52
- st.write(f"**A:** {item['answer']}")
53
- st.write("---")
 
 
 
15
  st.title("πŸ“Š Table Question Answering")
16
  st.write("""
17
  Welcome to the **Table Question Answering** app!
18
+ You can upload your own table and ask questions about it.
19
  The model will analyze the table and provide accurate answers.
20
  """)
21
 
22
+ # Step 1: Table input
23
+ st.header("πŸ“‚ Step 1: Upload your table")
24
+ # Option to upload a excel file
25
+ uploaded_file = st.file_uploader("Upload your Excel file:", type=["xlsx"])
26
+ if uploaded_file is not None:
27
+ try:
28
+ table = pd.read_excel(uploaded_file)
29
+ st.success("Table uploaded successfully!")
30
+ st.write("### Preview of Uploaded Table:")
31
+ st.dataframe(table, use_container_width=True)
32
+ except Exception as e:
33
+ st.error(f"Error reading the file: {e}")
34
+ table = None
35
+ else:
36
+ st.info("Please upload an Excel file to proceed.")
37
+ table = None
38
+
39
+ st.divider()
40
+ st.header("❓ Step 2: Ask a Question")
41
+ query = st.text_input("Ask a question about the table:")
42
+
43
+
44
+ st.divider()
45
+ if st.button("πŸ” Get Answer"):
46
+ if table is not None and query:
47
+ table = table.astype(str) # Ensure all values are strings
48
+ result = pipe(table=table, query=query)
49
+ st.success("Answer:")
50
+ st.markdown(f"### {result['answer']}")
51
+ else:
52
+ st.warning("Please upload a table and enter a question before clicking 'Get Answer'.")
53
+
54
+ st.divider()
55
+ st.markdown("**❀️**")