sdripie commited on
Commit
b431f4c
·
1 Parent(s): 59737d6

add history

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -17,18 +17,28 @@ data = {
17
  "city": ["athens", "paris", "st. louis", "athens", "beijing", "london"]
18
  }
19
  table = pd.DataFrame(data)
20
- table = table.astype(str) # Ensure all values are strings
21
 
22
- # Streamlit app layout
23
  st.title("Table Question Answering")
24
  st.write("### Input Table")
25
  st.dataframe(table)
26
 
27
- # User query
28
  query = st.text_input("Ask a question about the table:", "In which year did beijing host the Olympic Games?")
29
 
 
 
 
30
  # Process query and display result
31
  if st.button("Get Answer"):
32
  result = pipe(table=table, query=query)
 
33
  st.write("### Answer")
34
  st.write(result["answer"])
 
 
 
 
 
 
 
 
 
17
  "city": ["athens", "paris", "st. louis", "athens", "beijing", "london"]
18
  }
19
  table = pd.DataFrame(data)
20
+ table = table.astype(str) #ensure all values are strings
21
 
 
22
  st.title("Table Question Answering")
23
  st.write("### Input Table")
24
  st.dataframe(table)
25
 
 
26
  query = st.text_input("Ask a question about the table:", "In which year did beijing host the Olympic Games?")
27
 
28
+ if "history" not in st.session_state:
29
+ st.session_state.history = []
30
+
31
  # Process query and display result
32
  if st.button("Get Answer"):
33
  result = pipe(table=table, query=query)
34
+ st.session_state.history.append({"query": query, "answer": result["answer"]})
35
  st.write("### Answer")
36
  st.write(result["answer"])
37
+
38
+ #show history
39
+ if st.session_state.history:
40
+ st.write("### Previous Questions and Answers")
41
+ for item in st.session_state.history:
42
+ st.write(f"**Q:** {item['query']}")
43
+ st.write(f"**A:** {item['answer']}")
44
+ st.write("---")