louiecerv commited on
Commit
28fb88e
·
1 Parent(s): ff43fb4

fixed bugs

Browse files
Files changed (3) hide show
  1. .streamlit/config.toml +9 -0
  2. Dockerfile +22 -16
  3. src/app.py +24 -53
.streamlit/config.toml CHANGED
@@ -1,2 +1,11 @@
 
 
 
 
 
 
 
 
 
1
  [browser]
2
  gatherUsageStats = false
 
1
+ [global]
2
+ dataSavePath = "/tmp"
3
+
4
+ [client]
5
+ showErrorDetails = true
6
+
7
+ [logger]
8
+ level = "info"
9
+
10
  [browser]
11
  gatherUsageStats = false
Dockerfile CHANGED
@@ -1,23 +1,29 @@
1
- FROM python:3.10-slim
2
 
3
- # Set working directory
4
- WORKDIR /app
 
 
 
 
 
 
 
5
 
6
- # Copy application files
7
- COPY ./src /app/src
8
- COPY ./requirements.txt /app/requirements.txt
9
 
10
- # Install dependencies
11
- RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
 
12
 
13
- # Create writable Streamlit config directory
14
- RUN mkdir -p /tmp/.streamlit && chmod -R 777 /tmp/.streamlit
15
 
16
- # Set environment variable for Streamlit config
17
- ENV STREAMLIT_CONFIG_DIR=/tmp/.streamlit
 
 
18
 
19
- # Expose port 7860 (required by Hugging Face)
20
- EXPOSE 7860
21
 
22
- # Run Streamlit app
23
- CMD ["streamlit", "run", "src/app.py", "--server.port=7860", "--server.address=0.0.0.0"]
 
1
+ FROM python:3.9-slim-buster
2
 
3
+ # Set environment variables for Streamlit and Matplotlib
4
+ ENV STREAMLIT_SERVER_PORT=8501
5
+ ENV MPLCONFIGDIR=/tmp/matplotlib_cache
6
+
7
+ # Create a non-root user for security (optional but good practice)
8
+ # And set ownership of the app directory if needed
9
+ # RUN useradd -m streamlit_user
10
+ # USER streamlit_user
11
+ # WORKDIR /home/streamlit_user/app
12
 
13
+ WORKDIR /app
 
 
14
 
15
+ # Copy requirements.txt and install dependencies
16
+ COPY requirements.txt .
17
+ RUN pip install -r requirements.txt
18
 
19
+ # Copy your Streamlit app and configuration
20
+ COPY . .
21
 
22
+ # Create the matplotlib cache directory with appropriate permissions
23
+ RUN mkdir -p ${MPLCONFIGDIR} && chmod -R 777 ${MPLCONFIGDIR}
24
+ # Make sure /tmp is also writable by everyone if not already (often is by default)
25
+ RUN chmod -R 777 /tmp
26
 
27
+ EXPOSE 8501
 
28
 
29
+ ENTRYPOINT ["streamlit", "run", "src/app.py", "--server.port=8501", "--server.enableCORS=false", "--server.enableXsrfProtection=false"]
 
src/app.py CHANGED
@@ -1,65 +1,36 @@
1
  import streamlit as st
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")
39
- st.dataframe(df)
40
-
41
- # Display descriptive statistics
42
- st.subheader("Descriptive Statistics")
43
- st.write("**Basic Statistics for Numeric Columns**")
44
- st.dataframe(df.describe())
45
-
46
- st.write("**Column Data Types**")
47
- st.write(df.dtypes)
48
-
49
- st.write("**Missing Values**")
50
- st.write(df.isnull().sum())
51
-
52
- st.write("**Gender Distribution**")
53
- st.write(df['gender'].value_counts())
54
-
55
- st.write("**Correlation between Physics and Math Grades**")
56
- st.write(df[['physics_grade', 'math_grade']].corr())
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.")
 
1
  import streamlit as st
2
  import pandas as pd
 
 
 
3
 
4
  # Set page title
5
  st.title("Student Grades Analysis")
6
 
 
 
 
7
  # File uploader for CSV
8
  uploaded_file = st.file_uploader("Upload your student grades CSV file", type=["csv"])
9
 
10
  if uploaded_file is not None:
11
+ # Read the CSV file
12
+ df = pd.read_csv(uploaded_file)
13
+
14
+ # Display the DataFrame
15
+ st.subheader("Uploaded DataFrame")
16
+ st.dataframe(df)
17
+
18
+ # Display descriptive statistics
19
+ st.subheader("Descriptive Statistics")
20
+ st.write("**Basic Statistics for Numeric Columns**")
21
+ st.dataframe(df.describe())
22
+
23
+ # Additional statistics
24
+ st.write("**Column Data Types**")
25
+ st.write(df.dtypes)
26
+
27
+ st.write("**Missing Values**")
28
+ st.write(df.isnull().sum())
29
+
30
+ st.write("**Gender Distribution**")
31
+ st.write(df['gender'].value_counts())
32
+
33
+ st.write("**Correlation between Physics and Math Grades**")
34
+ st.write(df[['physics_grade', 'math_grade']].corr())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  else:
36
  st.info("Please upload a CSV file to see the data and statistics.")