CosmickVisions commited on
Commit
a184948
·
verified ·
1 Parent(s): b4e9662

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -31
app.py CHANGED
@@ -24,7 +24,7 @@ embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-
24
  # Set page config
25
  st.set_page_config(page_title="Neural-Vision Enhanced", layout="wide")
26
 
27
- # Custom CSS for Responsive Silver-Blue-Gold Theme
28
  st.markdown("""
29
  <style>
30
  :root {
@@ -57,6 +57,27 @@ st.markdown("""
57
  font-size: 1rem;
58
  margin-top: 5px;
59
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  .card {
61
  background-color: white;
62
  border-radius: 5px;
@@ -100,12 +121,6 @@ st.markdown("""
100
  .stButton > button:hover {
101
  background-color: #8C6B01;
102
  }
103
- .sidebar .sidebar-content {
104
- background-color: white;
105
- border-radius: 5px;
106
- padding: 15px;
107
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
108
- }
109
  @media (max-width: 768px) {
110
  .header-title {
111
  font-size: 1.4rem;
@@ -113,6 +128,15 @@ st.markdown("""
113
  .header-subtitle {
114
  font-size: 0.9rem;
115
  }
 
 
 
 
 
 
 
 
 
116
  .card, .chat-container {
117
  padding: 10px;
118
  }
@@ -160,7 +184,7 @@ PREBUILT_MODELS = {
160
  }
161
  }
162
 
163
- # Helper Functions (unchanged from previous)
164
  def convert_df_to_text(df):
165
  text = f"Dataset Summary: {df.shape[0]} rows, {df.shape[1]} columns\n"
166
  text += f"Missing Values: {df.isna().sum().sum()}\n"
@@ -211,16 +235,26 @@ def build_model_from_config(config, X, y=None):
211
  def main():
212
  st.markdown('<div class="header"><h1 class="header-title">Neural-Vision Enhanced</h1><p class="header-subtitle">Build & Train Neural Networks</p></div>', unsafe_allow_html=True)
213
 
214
- with st.sidebar:
215
- st.markdown('<div class="card"><h3>Data Input</h3></div>', unsafe_allow_html=True)
 
 
 
216
  uploaded_file = st.file_uploader("Upload CSV Dataset", type=["csv"])
217
  if uploaded_file:
218
  df = pd.read_csv(uploaded_file)
219
  st.session_state.vector_store = create_vector_store(convert_df_to_text(df))
220
  st.success("Dataset uploaded!")
 
 
 
 
 
 
 
221
 
222
- col1, col2 = st.columns([2, 1])
223
- with col1:
224
  st.markdown('<div class="card"><h2>Model Builder</h2></div>', unsafe_allow_html=True)
225
  mode = st.selectbox("Domain", ["Legal", "Financial", "Marketing"])
226
  model_builder_mode = st.radio("Mode", ["Prebuilt", "Custom"])
@@ -248,8 +282,9 @@ def main():
248
  st.session_state.model_config = {"type": "clustering", "n_clusters": st.number_input("Clusters", min_value=2, value=3)}
249
  if st.button("Finalize"): st.json(st.session_state.model_config)
250
 
251
- with col2:
252
  st.markdown('<div class="chat-container"><h3>Chat with Grok</h3></div>', unsafe_allow_html=True)
 
253
  prompt = st.text_input("Ask a question:")
254
  if prompt:
255
  response = get_groq_response(prompt, mode)
@@ -258,24 +293,27 @@ def main():
258
  for msg in st.session_state.chat_history:
259
  st.markdown(f'<div class={"user-message" if msg["role"] == "user" else "bot-message"}>{msg["content"]}</div>', unsafe_allow_html=True)
260
 
261
- if uploaded_file and st.session_state.model_config:
262
- st.markdown('<div class="card"><h2>Train Model</h2></div>', unsafe_allow_html=True)
263
- df = pd.read_csv(uploaded_file)
264
- X = df.drop(columns=[df.columns[-1]]) if st.session_state.model_config["type"] != "clustering" else df
265
- y = df[df.columns[-1]] if st.session_state.model_config["type"] != "clustering" else None
266
- if st.button("Train"):
267
- scaler = StandardScaler()
268
- X_scaled = scaler.fit_transform(X)
269
- model = build_model_from_config(st.session_state.model_config, X_scaled, y)
270
- if st.session_state.model_config["type"] != "clustering":
271
- X_train, X_test, y_train, y_test = train_test_split(X_scaled, y, test_size=0.2, random_state=42)
272
- model.fit(X_train, y_train)
273
- y_pred = model.predict(X_test)
274
- st.session_state.metrics = {"accuracy" if st.session_state.model_config["type"] == "classification" else "r2_score": accuracy_score(y_test, y_pred) if st.session_state.model_config["type"] == "classification" else r2_score(y_test, y_pred)}
275
- else:
276
- model.fit(X_scaled)
277
- st.session_state.metrics = {"silhouette_score": silhouette_score(X_scaled, model.labels_)}
278
- st.json(st.session_state.metrics)
 
 
 
279
 
280
  if __name__ == "__main__":
281
  main()
 
24
  # Set page config
25
  st.set_page_config(page_title="Neural-Vision Enhanced", layout="wide")
26
 
27
+ # Custom CSS for Responsive Silver-Blue-Gold Theme with Top Nav
28
  st.markdown("""
29
  <style>
30
  :root {
 
57
  font-size: 1rem;
58
  margin-top: 5px;
59
  }
60
+ .nav-bar {
61
+ background-color: white;
62
+ border-radius: 5px;
63
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
64
+ padding: 15px;
65
+ margin-bottom: 20px;
66
+ display: flex;
67
+ justify-content: space-around;
68
+ align-items: center;
69
+ }
70
+ .nav-item {
71
+ color: var(--blue);
72
+ font-weight: 500;
73
+ cursor: pointer;
74
+ padding: 5px 10px;
75
+ border-radius: 5px;
76
+ }
77
+ .nav-item:hover {
78
+ background-color: var(--gold);
79
+ color: white;
80
+ }
81
  .card {
82
  background-color: white;
83
  border-radius: 5px;
 
121
  .stButton > button:hover {
122
  background-color: #8C6B01;
123
  }
 
 
 
 
 
 
124
  @media (max-width: 768px) {
125
  .header-title {
126
  font-size: 1.4rem;
 
128
  .header-subtitle {
129
  font-size: 0.9rem;
130
  }
131
+ .nav-bar {
132
+ flex-direction: column;
133
+ padding: 10px;
134
+ }
135
+ .nav-item {
136
+ margin: 5px 0;
137
+ width: 100%;
138
+ text-align: center;
139
+ }
140
  .card, .chat-container {
141
  padding: 10px;
142
  }
 
184
  }
185
  }
186
 
187
+ # Helper Functions (unchanged)
188
  def convert_df_to_text(df):
189
  text = f"Dataset Summary: {df.shape[0]} rows, {df.shape[1]} columns\n"
190
  text += f"Missing Values: {df.isna().sum().sum()}\n"
 
235
  def main():
236
  st.markdown('<div class="header"><h1 class="header-title">Neural-Vision Enhanced</h1><p class="header-subtitle">Build & Train Neural Networks</p></div>', unsafe_allow_html=True)
237
 
238
+ # Top Navigation Bar
239
+ st.markdown('<div class="nav-bar">', unsafe_allow_html=True)
240
+ col1, col2, col3 = st.columns([1, 2, 1])
241
+ with col1:
242
+ st.markdown('<div class="nav-item">Data Input</div>', unsafe_allow_html=True)
243
  uploaded_file = st.file_uploader("Upload CSV Dataset", type=["csv"])
244
  if uploaded_file:
245
  df = pd.read_csv(uploaded_file)
246
  st.session_state.vector_store = create_vector_store(convert_df_to_text(df))
247
  st.success("Dataset uploaded!")
248
+ with col2:
249
+ st.markdown('<div class="nav-item">Navigation</div>', unsafe_allow_html=True)
250
+ nav_option = st.selectbox("Navigate", ["Model Builder", "Chat", "Train Model"], label_visibility="collapsed")
251
+ with col3:
252
+ st.markdown('<div class="nav-item">Info</div>', unsafe_allow_html=True)
253
+ st.write("Built with Streamlit & Groq")
254
+ st.markdown('</div>', unsafe_allow_html=True)
255
 
256
+ # Main Content
257
+ if nav_option == "Model Builder":
258
  st.markdown('<div class="card"><h2>Model Builder</h2></div>', unsafe_allow_html=True)
259
  mode = st.selectbox("Domain", ["Legal", "Financial", "Marketing"])
260
  model_builder_mode = st.radio("Mode", ["Prebuilt", "Custom"])
 
282
  st.session_state.model_config = {"type": "clustering", "n_clusters": st.number_input("Clusters", min_value=2, value=3)}
283
  if st.button("Finalize"): st.json(st.session_state.model_config)
284
 
285
+ elif nav_option == "Chat":
286
  st.markdown('<div class="chat-container"><h3>Chat with Grok</h3></div>', unsafe_allow_html=True)
287
+ mode = st.selectbox("Domain", ["Legal", "Financial", "Marketing"])
288
  prompt = st.text_input("Ask a question:")
289
  if prompt:
290
  response = get_groq_response(prompt, mode)
 
293
  for msg in st.session_state.chat_history:
294
  st.markdown(f'<div class={"user-message" if msg["role"] == "user" else "bot-message"}>{msg["content"]}</div>', unsafe_allow_html=True)
295
 
296
+ elif nav_option == "Train Model":
297
+ if uploaded_file and st.session_state.model_config:
298
+ st.markdown('<div class="card"><h2>Train Model</h2></div>', unsafe_allow_html=True)
299
+ df = pd.read_csv(uploaded_file)
300
+ X = df.drop(columns=[df.columns[-1]]) if st.session_state.model_config["type"] != "clustering" else df
301
+ y = df[df.columns[-1]] if st.session_state.model_config["type"] != "clustering" else None
302
+ if st.button("Train"):
303
+ scaler = StandardScaler()
304
+ X_scaled = scaler.fit_transform(X)
305
+ model = build_model_from_config(st.session_state.model_config, X_scaled, y)
306
+ if st.session_state.model_config["type"] != "clustering":
307
+ X_train, X_test, y_train, y_test = train_test_split(X_scaled, y, test_size=0.2, random_state=42)
308
+ model.fit(X_train, y_train)
309
+ y_pred = model.predict(X_test)
310
+ st.session_state.metrics = {"accuracy" if st.session_state.model_config["type"] == "classification" else "r2_score": accuracy_score(y_test, y_pred) if st.session_state.model_config["type"] == "classification" else r2_score(y_test, y_pred)}
311
+ else:
312
+ model.fit(X_scaled)
313
+ st.session_state.metrics = {"silhouette_score": silhouette_score(X_scaled, model.labels_)}
314
+ st.json(st.session_state.metrics)
315
+ else:
316
+ st.warning("Upload a dataset and configure a model first!")
317
 
318
  if __name__ == "__main__":
319
  main()