vgosavi2 commited on
Commit
47ccdf0
·
verified ·
1 Parent(s): afef622

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +12 -3
src/streamlit_app.py CHANGED
@@ -15,14 +15,23 @@ st.markdown(
15
  - **Purpose:** Explore crime-type distribution and arrest outcomes via pie charts.
16
  """
17
  )
 
 
18
 
19
  @st.cache_data
20
  def load_data():
21
- data_path = "crime_data.csv"
22
- return pd.read_csv(data_path)
 
 
 
 
 
23
 
24
  df = load_data()
25
-
 
 
26
  # 3. Data preview
27
  st.header("Data Preview")
28
  st.write(f"Total records: {df.shape[0]} | Total columns: {df.shape[1]}")
 
15
  - **Purpose:** Explore crime-type distribution and arrest outcomes via pie charts.
16
  """
17
  )
18
+ HERE = Path(__file__).parent # e.g. /app/src
19
+ DATA_PATH = HERE / "crime_data.csv" # /app/src/crime_data.csv
20
 
21
  @st.cache_data
22
  def load_data():
23
+ if not DATA_PATH.exists():
24
+ st.error(
25
+ f"❌ Could not find `crime_data.csv` at:\n\n {DATA_PATH}\n\n"
26
+ "Make sure your CSV is placed in the same folder as this script."
27
+ )
28
+ return pd.DataFrame() # return empty so the app doesn’t crash
29
+ return pd.read_csv(DATA_PATH)
30
 
31
  df = load_data()
32
+ if df.empty:
33
+ st.stop() # no further execution
34
+
35
  # 3. Data preview
36
  st.header("Data Preview")
37
  st.write(f"Total records: {df.shape[0]} | Total columns: {df.shape[1]}")