Spaces:
Sleeping
Sleeping
update app.py
Browse files- src/app.py +18 -1
src/app.py
CHANGED
@@ -2,22 +2,37 @@ import streamlit as st
|
|
2 |
import pandas as pd
|
3 |
import os
|
4 |
import tempfile
|
|
|
5 |
|
6 |
# Set page title
|
7 |
st.title("Student Grades Analysis")
|
8 |
|
|
|
|
|
|
|
9 |
# File uploader for CSV
|
10 |
uploaded_file = st.file_uploader("Upload your student grades CSV file", type=["csv"])
|
11 |
|
12 |
if uploaded_file is not None:
|
13 |
try:
|
|
|
|
|
14 |
# Create a temporary file to save the uploaded CSV
|
15 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix='.csv') as tmp_file:
|
16 |
tmp_file.write(uploaded_file.getvalue())
|
17 |
tmp_file_path = tmp_file.name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
# Read the CSV from the temporary file
|
20 |
df = pd.read_csv(tmp_file_path)
|
|
|
21 |
|
22 |
# Display the DataFrame
|
23 |
st.subheader("Uploaded DataFrame")
|
@@ -42,7 +57,9 @@ if uploaded_file is not None:
|
|
42 |
|
43 |
# Clean up the temporary file
|
44 |
os.remove(tmp_file_path)
|
|
|
45 |
except Exception as e:
|
46 |
st.error(f"An error occurred while processing the file: {str(e)}")
|
|
|
47 |
else:
|
48 |
st.info("Please upload a CSV file to see the data and statistics.")
|
|
|
2 |
import pandas as pd
|
3 |
import os
|
4 |
import tempfile
|
5 |
+
import traceback
|
6 |
|
7 |
# Set page title
|
8 |
st.title("Student Grades Analysis")
|
9 |
|
10 |
+
# Display Streamlit config directory for debugging
|
11 |
+
st.write(f"Streamlit config directory: {os.getenv('STREAMLIT_CONFIG_DIR', 'Not set')}")
|
12 |
+
|
13 |
# File uploader for CSV
|
14 |
uploaded_file = st.file_uploader("Upload your student grades CSV file", type=["csv"])
|
15 |
|
16 |
if uploaded_file is not None:
|
17 |
try:
|
18 |
+
st.write(f"Uploaded file: {uploaded_file.name}, size: {uploaded_file.size} bytes")
|
19 |
+
|
20 |
# Create a temporary file to save the uploaded CSV
|
21 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix='.csv', dir='/tmp') as tmp_file:
|
22 |
tmp_file.write(uploaded_file.getvalue())
|
23 |
tmp_file_path = tmp_file.name
|
24 |
+
st.write(f"Temporary file created at: {tmp_file_path}")
|
25 |
+
|
26 |
+
# Verify file exists and is readable
|
27 |
+
if os.path.exists(tmp_file_path):
|
28 |
+
st.write("Temporary file exists and is accessible")
|
29 |
+
else:
|
30 |
+
st.error("Temporary file was not created or is not accessible")
|
31 |
+
raise FileNotFoundError(f"Temporary file not found: {tmp_file_path}")
|
32 |
|
33 |
# Read the CSV from the temporary file
|
34 |
df = pd.read_csv(tmp_file_path)
|
35 |
+
st.write("CSV file successfully read into DataFrame")
|
36 |
|
37 |
# Display the DataFrame
|
38 |
st.subheader("Uploaded DataFrame")
|
|
|
57 |
|
58 |
# Clean up the temporary file
|
59 |
os.remove(tmp_file_path)
|
60 |
+
st.write("Temporary file deleted")
|
61 |
except Exception as e:
|
62 |
st.error(f"An error occurred while processing the file: {str(e)}")
|
63 |
+
st.error(f"Full traceback: {traceback.format_exc()}")
|
64 |
else:
|
65 |
st.info("Please upload a CSV file to see the data and statistics.")
|