qwerty45-uiop commited on
Commit
f757005
·
verified ·
1 Parent(s): 4f33339

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +31 -25
src/streamlit_app.py CHANGED
@@ -24,31 +24,37 @@ st.set_page_config(
24
  # Enhanced data loading with error handling - FIXED FILE PATH
25
  @st.cache_data
26
  def load_data():
27
- try:
28
- # Try multiple possible file locations
29
- possible_paths = [
30
- "BITS_INTERNS.xlsx", # Current directory
31
- "src/BITS_INTERNS.xlsx", # src subdirectory
32
- "./BITS_INTERNS.xlsx", # Explicit current directory
33
- ]
34
-
35
- df = None
36
- for path in possible_paths:
37
- try:
38
- df = pd.read_excel(path, sheet_name="Form Responses 1")
39
- st.info(f" Successfully loaded data from: {path}")
40
- break
41
- except FileNotFoundError:
42
- continue
43
-
44
- if df is None:
45
- return None, "Excel file 'BITS_INTERNS.xlsx' not found in any expected location. Please ensure the file is in the same directory as this script."
46
-
47
- df.columns = df.columns.str.strip()
48
- return df, None
49
-
50
- except Exception as e:
51
- return None, f"Error loading data: {str(e)}"
 
 
 
 
 
 
52
 
53
  # Enhanced RAM extraction with better parsing
54
  def extract_numeric_ram(ram) -> Optional[int]:
 
24
  # Enhanced data loading with error handling - FIXED FILE PATH
25
  @st.cache_data
26
  def load_data():
27
+ def try_read_excel(path: str) -> Optional[pd.DataFrame]:
28
+ try:
29
+ df = pd.read_excel(path, sheet_name=0)
30
+ df.columns = df.columns.str.strip()
31
+ return df
32
+ except Exception:
33
+ return None
34
+
35
+ possible_files = [
36
+ "BITS_INTERNS.xlsx",
37
+ "src/BITS_INTERNS.xlsx",
38
+ "./BITS_INTERNS.xlsx",
39
+ "Summer of AI - ICFAI (Responses) (3).xlsx",
40
+ "src/Summer of AI - ICFAI (Responses) (3).xlsx",
41
+ "./Summer of AI - ICFAI (Responses) (3).xlsx"
42
+ ]
43
+
44
+ dfs = []
45
+ for file in possible_files:
46
+ df = try_read_excel(file)
47
+ if df is not None:
48
+ st.info(f"✅ Loaded data from: {file}")
49
+ dfs.append(df)
50
+
51
+ if not dfs:
52
+ return None, "❌ No valid Excel files found. Please upload at least one file."
53
+
54
+ # Merge all valid DataFrames
55
+ combined_df = pd.concat(dfs, ignore_index=True)
56
+ return combined_df, None
57
+
58
 
59
  # Enhanced RAM extraction with better parsing
60
  def extract_numeric_ram(ram) -> Optional[int]: