Suryansh14124 commited on
Commit
12fc687
·
verified ·
1 Parent(s): d64fc99

Delete src/App3.py

Browse files
Files changed (1) hide show
  1. src/App3.py +0 -330
src/App3.py DELETED
@@ -1,330 +0,0 @@
1
- import streamlit as st
2
- import pandas as pd
3
- import re
4
- import plotly.express as px
5
- import plotly.graph_objects as go
6
- from typing import Optional, Tuple
7
-
8
- # ✅ MUST be the first Streamlit command
9
- st.set_page_config(
10
- page_title="LLM Compatibility Advisor",
11
- layout="wide",
12
- page_icon="🧠",
13
- initial_sidebar_state="expanded"
14
- )
15
-
16
- # Enhanced data loading with error handling
17
- @st.cache_data
18
- def load_data():
19
- try:
20
- df = pd.read_excel("ICFAI.xlsx", sheet_name="Form Responses 1")
21
- df.columns = df.columns.str.strip()
22
- return df, None
23
- except FileNotFoundError:
24
- return None, "Excel file 'ICFAI.xlsx' not found. Please upload the file."
25
- except Exception as e:
26
- return None, f"Error loading data: {str(e)}"
27
-
28
- # Enhanced RAM extraction with better parsing
29
- def extract_numeric_ram(ram) -> Optional[int]:
30
- if pd.isna(ram):
31
- return None
32
-
33
- ram_str = str(ram).lower().replace(" ", "")
34
-
35
- # Handle various formats: "8GB", "8 GB", "8gb", "8192MB", etc.
36
- gb_match = re.search(r"(\d+(?:\.\d+)?)(?:gb|g)", ram_str)
37
- if gb_match:
38
- return int(float(gb_match.group(1)))
39
-
40
- # Handle MB format
41
- mb_match = re.search(r"(\d+)(?:mb|m)", ram_str)
42
- if mb_match:
43
- return max(1, int(int(mb_match.group(1)) / 1024)) # Convert MB to GB
44
-
45
- # Handle plain numbers (assume GB)
46
- plain_match = re.search(r"(\d+)", ram_str)
47
- if plain_match:
48
- return int(plain_match.group(1))
49
-
50
- return None
51
-
52
- # Enhanced LLM recommendation with performance tiers
53
- def recommend_llm(ram_str) -> Tuple[str, str, str]:
54
- """Returns (recommendation, performance_tier, additional_info)"""
55
- ram = extract_numeric_ram(ram_str)
56
-
57
- if ram is None:
58
- return "⚪ Check exact specs or test with quantized models.", "Unknown", "Verify RAM specifications"
59
-
60
- if ram <= 2:
61
- return ("🔸 DistilBERT, MobileBERT, TinyBERT",
62
- "Basic",
63
- "Suitable for simple NLP tasks, limited context")
64
- elif ram <= 4:
65
- return ("🔸 MiniLM, TinyLLaMA, DistilRoBERTa",
66
- "Basic",
67
- "Good for text classification, basic chat")
68
- elif ram <= 6:
69
- return ("🟠 Phi-1.5, Alpaca.cpp (3B), Mistral Tiny",
70
- "Moderate",
71
- "Decent reasoning, short conversations")
72
- elif ram <= 8:
73
- return ("🟠 Phi-2, Gemma 2B, LLaMA 2 7B (4-bit)",
74
- "Moderate",
75
- "Good general purpose, coding assistance")
76
- elif ram <= 12:
77
- return ("🟢 LLaMA 2 7B (GGUF), Mistral 7B (int4)",
78
- "Good",
79
- "Strong performance, longer contexts")
80
- elif ram <= 16:
81
- return ("🟢 Mixtral 8x7B (4-bit), Command R+",
82
- "Good",
83
- "Excellent reasoning, complex tasks")
84
- elif ram <= 24:
85
- return ("🔵 LLaMA 2 13B, Mistral 7B FP16, Gemma 7B",
86
- "High",
87
- "Professional grade, high accuracy")
88
- else:
89
- return ("🔵 Mixtral 8x7B Full, LLaMA 2 70B (quantized)",
90
- "High",
91
- "Top-tier performance, enterprise ready")
92
-
93
- # Enhanced OS detection with better icons
94
- def get_os_info(os_name) -> Tuple[str, str]:
95
- """Returns (icon, clean_name)"""
96
- if pd.isna(os_name):
97
- return "💻", "Not specified"
98
-
99
- os = str(os_name).lower()
100
- if "windows" in os:
101
- return "🪟", os_name
102
- elif "mac" in os or "darwin" in os:
103
- return "🍎", os_name
104
- elif "linux" in os or "ubuntu" in os:
105
- return "🐧", os_name
106
- elif "android" in os:
107
- return "🤖", os_name
108
- elif "ios" in os:
109
- return "📱", os_name
110
- else:
111
- return "💻", os_name
112
-
113
- # Performance visualization
114
- def create_performance_chart(df):
115
- """Create a performance distribution chart"""
116
- laptop_rams = df["Laptop RAM"].apply(extract_numeric_ram).dropna()
117
- mobile_rams = df["Mobile RAM"].apply(extract_numeric_ram).dropna()
118
-
119
- fig = go.Figure()
120
-
121
- fig.add_trace(go.Histogram(
122
- x=laptop_rams,
123
- name="Laptop RAM",
124
- opacity=0.7,
125
- nbinsx=10
126
- ))
127
-
128
- fig.add_trace(go.Histogram(
129
- x=mobile_rams,
130
- name="Mobile RAM",
131
- opacity=0.7,
132
- nbinsx=10
133
- ))
134
-
135
- fig.update_layout(
136
- title="RAM Distribution Across Devices",
137
- xaxis_title="RAM (GB)",
138
- yaxis_title="Number of Students",
139
- barmode='overlay',
140
- height=400
141
- )
142
-
143
- return fig
144
-
145
- # Main App
146
- st.title("🧠 LLM Compatibility Advisor")
147
- st.markdown("Get personalized, device-based suggestions for running LLMs efficiently!")
148
-
149
- # Load data
150
- df, error = load_data()
151
-
152
- if error:
153
- st.error(error)
154
- st.info("Please ensure the Excel file 'BITS_INTERNS.xlsx' is in the same directory as this script.")
155
- st.stop()
156
-
157
- if df is None or df.empty:
158
- st.error("No data found in the Excel file.")
159
- st.stop()
160
-
161
- # Sidebar filters and info
162
- with st.sidebar:
163
- st.header("🔍 Filters & Info")
164
-
165
- # Performance tier filter
166
- performance_filter = st.multiselect(
167
- "Filter by Performance Tier:",
168
- ["Basic", "Moderate", "Good", "High", "Unknown"],
169
- default=["Basic", "Moderate", "Good", "High", "Unknown"]
170
- )
171
-
172
- # RAM range filter
173
- st.subheader("RAM Range Filter")
174
- min_ram = st.slider("Minimum RAM (GB)", 0, 32, 0)
175
- max_ram = st.slider("Maximum RAM (GB)", 0, 64, 64)
176
-
177
- st.markdown("---")
178
- st.markdown("### 📊 Quick Stats")
179
- st.metric("Total Students", len(df))
180
-
181
- # Calculate average RAM
182
- avg_laptop_ram = df["Laptop RAM"].apply(extract_numeric_ram).mean()
183
- avg_mobile_ram = df["Mobile RAM"].apply(extract_numeric_ram).mean()
184
-
185
- if not pd.isna(avg_laptop_ram):
186
- st.metric("Avg Laptop RAM", f"{avg_laptop_ram:.1f} GB")
187
- if not pd.isna(avg_mobile_ram):
188
- st.metric("Avg Mobile RAM", f"{avg_mobile_ram:.1f} GB")
189
-
190
- # User selection with search
191
- st.subheader("👤 Individual Student Analysis")
192
- selected_user = st.selectbox(
193
- "Choose a student:",
194
- options=[""] + list(df["Full Name"].unique()),
195
- format_func=lambda x: "Select a student..." if x == "" else x
196
- )
197
-
198
- if selected_user:
199
- user_data = df[df["Full Name"] == selected_user].iloc[0]
200
-
201
- # Enhanced user display
202
- col1, col2 = st.columns(2)
203
-
204
- with col1:
205
- st.markdown("### 💻 Laptop Configuration")
206
- laptop_os_icon, laptop_os_name = get_os_info(user_data.get('Laptop Operating System'))
207
- laptop_ram = user_data.get('Laptop RAM', 'Not specified')
208
- laptop_rec, laptop_tier, laptop_info = recommend_llm(laptop_ram)
209
-
210
- st.markdown(f"**OS:** {laptop_os_icon} {laptop_os_name}")
211
- st.markdown(f"**RAM:** {laptop_ram}")
212
- st.markdown(f"**Performance Tier:** {laptop_tier}")
213
-
214
- st.success(f"**💡 Recommendation:** {laptop_rec}")
215
- st.info(f"**ℹ️ Notes:** {laptop_info}")
216
-
217
- with col2:
218
- st.markdown("### 📱 Mobile Configuration")
219
- mobile_os_icon, mobile_os_name = get_os_info(user_data.get('Mobile Operating System'))
220
- mobile_ram = user_data.get('Mobile RAM', 'Not specified')
221
- mobile_rec, mobile_tier, mobile_info = recommend_llm(mobile_ram)
222
-
223
- st.markdown(f"**OS:** {mobile_os_icon} {mobile_os_name}")
224
- st.markdown(f"**RAM:** {mobile_ram}")
225
- st.markdown(f"**Performance Tier:** {mobile_tier}")
226
-
227
- st.success(f"**💡 Recommendation:** {mobile_rec}")
228
- st.info(f"**ℹ️ Notes:** {mobile_info}")
229
-
230
- # Batch Analysis Section
231
- st.markdown("---")
232
- st.header("📊 Batch Analysis & Insights")
233
-
234
- # Create enhanced batch table
235
- df_display = df[["Full Name", "Laptop RAM", "Mobile RAM"]].copy()
236
-
237
- # Add recommendations and performance tiers
238
- laptop_recommendations = df["Laptop RAM"].apply(lambda x: recommend_llm(x)[0])
239
- mobile_recommendations = df["Mobile RAM"].apply(lambda x: recommend_llm(x)[0])
240
- laptop_tiers = df["Laptop RAM"].apply(lambda x: recommend_llm(x)[1])
241
- mobile_tiers = df["Mobile RAM"].apply(lambda x: recommend_llm(x)[1])
242
-
243
- df_display["Laptop LLM"] = laptop_recommendations
244
- df_display["Mobile LLM"] = mobile_recommendations
245
- df_display["Laptop Tier"] = laptop_tiers
246
- df_display["Mobile Tier"] = mobile_tiers
247
-
248
- # Filter based on sidebar selections
249
- laptop_ram_numeric = df["Laptop RAM"].apply(extract_numeric_ram)
250
- mobile_ram_numeric = df["Mobile RAM"].apply(extract_numeric_ram)
251
-
252
- # Apply filters
253
- mask = (
254
- (laptop_tiers.isin(performance_filter) | mobile_tiers.isin(performance_filter)) &
255
- ((laptop_ram_numeric.between(min_ram, max_ram)) | (mobile_ram_numeric.between(min_ram, max_ram)))
256
- )
257
-
258
- df_filtered = df_display[mask]
259
-
260
- # Display filtered table
261
- st.subheader(f"📋 Student Recommendations ({len(df_filtered)} students)")
262
- st.dataframe(
263
- df_filtered,
264
- use_container_width=True,
265
- column_config={
266
- "Full Name": st.column_config.TextColumn("Student Name", width="medium"),
267
- "Laptop RAM": st.column_config.TextColumn("Laptop RAM", width="small"),
268
- "Mobile RAM": st.column_config.TextColumn("Mobile RAM", width="small"),
269
- "Laptop LLM": st.column_config.TextColumn("Laptop Recommendation", width="large"),
270
- "Mobile LLM": st.column_config.TextColumn("Mobile Recommendation", width="large"),
271
- "Laptop Tier": st.column_config.TextColumn("L-Tier", width="small"),
272
- "Mobile Tier": st.column_config.TextColumn("M-Tier", width="small"),
273
- }
274
- )
275
-
276
- # Performance distribution chart
277
- if len(df) > 1:
278
- st.subheader("📈 RAM Distribution Analysis")
279
- fig = create_performance_chart(df)
280
- st.plotly_chart(fig, use_container_width=True)
281
-
282
- # Performance tier summary
283
- st.subheader("��� Performance Tier Summary")
284
- tier_col1, tier_col2 = st.columns(2)
285
-
286
- with tier_col1:
287
- st.markdown("**Laptop Performance Tiers:**")
288
- laptop_tier_counts = laptop_tiers.value_counts()
289
- for tier, count in laptop_tier_counts.items():
290
- percentage = (count / len(laptop_tiers)) * 100
291
- st.write(f"• {tier}: {count} students ({percentage:.1f}%)")
292
-
293
- with tier_col2:
294
- st.markdown("**Mobile Performance Tiers:**")
295
- mobile_tier_counts = mobile_tiers.value_counts()
296
- for tier, count in mobile_tier_counts.items():
297
- percentage = (count / len(mobile_tiers)) * 100
298
- st.write(f"• {tier}: {count} students ({percentage:.1f}%)")
299
-
300
- # Enhanced reference table
301
- with st.expander("📘 Comprehensive LLM Reference Guide"):
302
- st.markdown("""
303
- ## RAM-to-LLM Compatibility Matrix
304
-
305
- | RAM Size | Performance Tier | Recommended Models | Use Cases | Additional Notes |
306
- |----------|------------------|-------------------|-----------|------------------|
307
- | ≤2GB | 🔸 Basic | DistilBERT, MobileBERT, TinyBERT | Simple NLP, text classification | Limited context, fast inference |
308
- | 4GB | 🔸 Basic | MiniLM, TinyLLaMA, DistilRoBERTa | Basic chat, QA systems | Good for mobile deployment |
309
- | 6GB | 🟠 Moderate | Phi-1.5, Alpaca.cpp (3B), Mistral Tiny | Reasoning tasks, short conversations | Balanced performance/memory |
310
- | 8GB | 🟠 Moderate | Phi-2, Gemma 2B, LLaMA 2 7B (4-bit) | General purpose, coding help | Popular sweet spot |
311
- | 12GB | 🟢 Good | LLaMA 2 7B (GGUF), Mistral 7B (int4) | Professional tasks, longer context | Production ready |
312
- | 16GB | 🟢 Good | Mixtral 8x7B (4-bit), Command R+ | Complex reasoning, analysis | Excellent capabilities |
313
- | 24GB | 🔵 High | LLaMA 2 13B, Mistral 7B FP16, Gemma 7B | High-accuracy tasks, research | Professional grade |
314
- | >24GB | 🔵 High | Mixtral 8x7B Full, LLaMA 2 70B (quantized) | Enterprise applications | Top-tier performance |
315
-
316
- ### 🔧 Optimization Tips:
317
- - **Quantization**: Use 4-bit or 8-bit quantization to reduce memory usage
318
- - **GGUF Format**: Optimized format for CPU inference with lower memory overhead
319
- - **Context Length**: Longer contexts require significantly more memory
320
- - **Batch Size**: Reduce batch size for inference to save memory
321
- """)
322
-
323
- # Footer with additional resources
324
- st.markdown("---")
325
- st.markdown("""
326
- ### 🔗 Additional Resources
327
- - **Quantization Tools**: GPTQ, GGML, bitsandbytes
328
- - **Inference Engines**: llama.cpp, vLLM, TensorRT-LLM
329
- - **Model Repositories**: Hugging Face, Ollama, LM Studio
330
- """)