Update src/streamlit_app.py
Browse files- src/streamlit_app.py +44 -9
src/streamlit_app.py
CHANGED
@@ -22,28 +22,63 @@ st.set_page_config(
|
|
22 |
)
|
23 |
|
24 |
# Enhanced data loading with error handling
|
|
|
|
|
|
|
|
|
|
|
25 |
@st.cache_data
|
26 |
-
|
|
|
27 |
try:
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
31 |
|
32 |
df1.columns = df1.columns.str.strip()
|
33 |
df2.columns = df2.columns.str.strip()
|
34 |
-
|
35 |
-
#
|
36 |
common_cols = list(set(df1.columns) & set(df2.columns))
|
37 |
df1 = df1[common_cols]
|
38 |
df2 = df2[common_cols]
|
39 |
|
40 |
combined_df = pd.concat([df1, df2], ignore_index=True)
|
41 |
return combined_df, None
|
42 |
-
except FileNotFoundError as e:
|
43 |
-
return None, f"File not found: {e}"
|
44 |
except Exception as e:
|
45 |
-
return None,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
|
|
47 |
|
48 |
# Enhanced RAM extraction with better parsing
|
49 |
def extract_numeric_ram(ram) -> Optional[int]:
|
|
|
22 |
)
|
23 |
|
24 |
# Enhanced data loading with error handling
|
25 |
+
# Upload section in sidebar
|
26 |
+
st.sidebar.header("📤 Upload Excel Files")
|
27 |
+
uploaded_file1 = st.sidebar.file_uploader("Upload File 1 (e.g. BITS_INTERNS)", type=["xlsx"])
|
28 |
+
uploaded_file2 = st.sidebar.file_uploader("Upload File 2 (e.g. ICFAI Responses)", type=["xlsx"])
|
29 |
+
|
30 |
@st.cache_data
|
31 |
+
|
32 |
+
def load_uploaded_data(upload1, upload2):
|
33 |
try:
|
34 |
+
if not upload1 or not upload2:
|
35 |
+
return None, "Please upload both Excel files."
|
36 |
+
|
37 |
+
df1 = pd.read_excel(upload1)
|
38 |
+
df2 = pd.read_excel(upload2)
|
39 |
|
40 |
df1.columns = df1.columns.str.strip()
|
41 |
df2.columns = df2.columns.str.strip()
|
42 |
+
|
43 |
+
# Use only common columns
|
44 |
common_cols = list(set(df1.columns) & set(df2.columns))
|
45 |
df1 = df1[common_cols]
|
46 |
df2 = df2[common_cols]
|
47 |
|
48 |
combined_df = pd.concat([df1, df2], ignore_index=True)
|
49 |
return combined_df, None
|
|
|
|
|
50 |
except Exception as e:
|
51 |
+
return None, str(e)
|
52 |
+
|
53 |
+
def extract_numeric_ram(ram) -> Optional[int]:
|
54 |
+
if pd.isna(ram):
|
55 |
+
return None
|
56 |
+
ram_str = str(ram).lower().replace(" ", "")
|
57 |
+
gb_match = re.search(r"(\d+(?:\.\d+)?)(?:gb|g)", ram_str)
|
58 |
+
if gb_match:
|
59 |
+
return int(float(gb_match.group(1)))
|
60 |
+
mb_match = re.search(r"(\d+)(?:mb|m)", ram_str)
|
61 |
+
if mb_match:
|
62 |
+
return max(1, int(int(mb_match.group(1)) / 1024))
|
63 |
+
plain_match = re.search(r"(\d+)", ram_str)
|
64 |
+
if plain_match:
|
65 |
+
return int(plain_match.group(1))
|
66 |
+
return None
|
67 |
+
|
68 |
+
st.title("🧠 LLM Compatibility Advisor")
|
69 |
+
st.markdown("Get personalized recommendations from **150+ popular open source AI models** with download sizes!")
|
70 |
+
|
71 |
+
df, error = load_uploaded_data(uploaded_file1, uploaded_file2)
|
72 |
+
|
73 |
+
if error:
|
74 |
+
st.error(error)
|
75 |
+
st.stop()
|
76 |
+
|
77 |
+
if df is None or df.empty:
|
78 |
+
st.warning("No data loaded. Please upload both files.")
|
79 |
+
st.stop()
|
80 |
|
81 |
+
st.success(f"✅ Loaded {len(df)} student entries from both files.")
|
82 |
|
83 |
# Enhanced RAM extraction with better parsing
|
84 |
def extract_numeric_ram(ram) -> Optional[int]:
|