jethrovic commited on
Commit
20bd02e
·
1 Parent(s): af8cb69

maybe wild

Browse files
Files changed (1) hide show
  1. app.py +17 -14
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import streamlit as st
2
  import pandas as pd
3
  from transformers import pipeline
@@ -16,24 +17,26 @@ question = st.text_input("Enter your question:")
16
 
17
  # Process table and question
18
  if uploaded_file is not None and question:
19
- # Read table from CSV
20
- table = pd.read_csv(uploaded_file)
21
- new_header = table.iloc[0] #grab the first row for the header
22
- table = table[1:] #take the data less the header row
23
- table.columns = new_header
 
 
24
 
25
- # Display the table
26
- st.write("Uploaded Table:")
27
- st.write(table)
28
 
29
- # Get answer
30
- answer = tqa(table=table, query=question)['cells'][0]
31
 
32
- # Display the answer
33
- st.write("Answer:", answer)
 
 
34
 
35
  # Instructions
36
  st.markdown("""
37
- *First, upload a CSV file containing your table data. The CSV should have headers for each column.*
38
- *Then, enter a question related to the table and press Enter to see the answer.*
39
  """)
 
1
+
2
  import streamlit as st
3
  import pandas as pd
4
  from transformers import pipeline
 
17
 
18
  # Process table and question
19
  if uploaded_file is not None and question:
20
+ try:
21
+ # Read table from CSV
22
+ table = pd.read_csv(uploaded_file)
23
+
24
+ # Display the table
25
+ st.write("Uploaded Table:")
26
+ st.dataframe(table)
27
 
28
+ # Convert DataFrame to the format expected by TAPAS
29
+ table_data = table.to_dict(orient='records')
 
30
 
31
+ # Get answer
32
+ answer = tqa(table=table_data, query=question)['cells'][0]
33
 
34
+ # Display the answer
35
+ st.write("Answer:", answer)
36
+ except Exception as e:
37
+ st.error(f"An error occurred: {e}")
38
 
39
  # Instructions
40
  st.markdown("""
41
+ *First, upload a CSV file.
 
42
  """)