Spaces:
Sleeping
Sleeping
maybe wild
Browse files
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 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
st.write(table)
|
28 |
|
29 |
-
|
30 |
-
|
31 |
|
32 |
-
|
33 |
-
|
|
|
|
|
34 |
|
35 |
# Instructions
|
36 |
st.markdown("""
|
37 |
-
*First, upload a CSV file
|
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 |
""")
|