ThireshS commited on
Commit
017de5c
Β·
verified Β·
1 Parent(s): e4f4cff

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +93 -73
src/streamlit_app.py CHANGED
@@ -3,8 +3,8 @@ import os
3
  import json
4
  import streamlit as st
5
  from app_assets import app_logo
6
- from app_utils import parse_data_dictionary
7
-
8
  from workflow_nodes import (
9
  think_sections_node,
10
  enhance_plan_node,
@@ -14,37 +14,40 @@ from workflow_nodes import (
14
  correct_notebook_node,
15
  write_insights_node
16
  )
17
-
18
  from workflow_nodes import InteractiveCaseStudyState
19
 
20
-
21
  st.set_page_config(layout="wide")
22
 
 
 
 
 
23
  st.title("πŸ““ NBforge Demo")
24
 
25
- st.logo(app_logo,size='large',link='https://www.mygreatlearning.com/')
 
26
 
27
  # ─── Session State Initialization ─────────────────────────────────────────────
28
  if "state" not in st.session_state:
29
  st.session_state.state = InteractiveCaseStudyState()
30
- st.session_state.plan_ready = False
31
- st.session_state.plan_approved = None
32
- st.session_state.notebook_ready = False
33
- st.session_state.notebook_approved = None
34
- st.session_state.exec_ready = False
35
- st.session_state.execution_approved = None
36
 
37
  s = st.session_state.state
38
 
39
  # ─── 1) Collect Inputs ────────────────────────────────────────────────────────
40
  st.header("1. πŸ”§ Provide Your Inputs")
41
- s["domain"] = st.selectbox("πŸ“‚ Select Domain", [
42
- "EDA","Machine Learning","Deep Learning","Natural Language Processing",
43
- "Computer Vision","Generative AI Prompt Engineering","Generative AI RAG"
44
  ])
45
- s["topics_and_subtopics"] = st.text_area("πŸ“š Weekly Topics & Subtopics", height=80)
46
- s["problem_statement"] = st.text_area("🧩 Problem Statement", height=80)
47
- s["dataset_type"] = st.selectbox("πŸ“ Dataset Type", ["csv","pdf","images","json"])
48
 
49
  uploaded = st.file_uploader("⬆️ Upload Dataset", accept_multiple_files=False)
50
  if uploaded:
@@ -55,47 +58,44 @@ if uploaded:
55
  s["dataset_file_path"] = path
56
  st.success(f"Dataset saved to `{path}`")
57
 
58
- # Data dictionary input
59
  s["data_dictionary"] = {}
60
  dd = st.text_area("πŸ“– Data Dictionary")
61
  s["data_dictionary"] = parse_data_dictionary(dd)
62
- # try:
63
- # s["data_dictionary"] = json.loads(dd) if dd.strip() else {}
64
- # except json.JSONDecodeError:
65
- # st.error("Invalid JSON in Data Dictionary")
66
 
67
- s["additional_instructions"] = st.text_area(
68
- "πŸ“ Additional Instructions (optional)", height=68
69
- )
70
 
71
  # Kick off plan generation
72
- if st.session_state.plan_ready==False:
73
  if st.button("πŸš€ Generate Plan") and uploaded:
74
  with st.spinner("Designing notebook plan…"):
75
  s = think_sections_node(s)
76
- st.session_state.plan_ready = True
77
- st.session_state.plan_approved = None
78
- st.session_state.notebook_ready = False
79
- st.session_state.exec_ready = False
80
 
81
  # ─── 2) Review & Enhance Plan ────────────────────────────────────────────────
82
  if st.session_state.plan_ready:
83
  st.subheader("2. πŸ” Review Notebook Plan")
84
- st.json(s["plan"])
85
-
86
- #ask approval once
 
 
87
  if st.session_state.plan_approved is None:
88
- st.session_state.plan_approved = st.radio("Approve this plan?", index=None, options=["YES","NO"])
89
  st.write(f"Plan approved: {st.session_state.plan_approved}")
90
 
91
-
92
  # on approval, let user move on
93
  if st.session_state.plan_approved == "YES":
94
  if st.button("➑️ Next: Write Code"):
95
  with st.spinner("Writing notebook skeleton…"):
96
  s = write_code_node(s)
97
- st.session_state.notebook_ready = True
98
  st.session_state.notebook_approved = None
 
99
  # on rejection, collect feedback & loop back
100
  elif st.session_state.plan_approved == "NO":
101
  st.text_area("What should be changed in the plan?", key="plan_fb")
@@ -104,6 +104,7 @@ if st.session_state.plan_ready:
104
  s["plan_feedback"] = st.session_state.plan_fb
105
  with st.spinner("Modifying notebook plan…"):
106
  s = enhance_plan_node(s)
 
107
  # reset approval so we review again
108
  st.session_state.plan_approved = None
109
  st.rerun()
@@ -111,19 +112,29 @@ if st.session_state.plan_ready:
111
  # ─── 3) Review & Modify Notebook ─────────────────────────────────────────────
112
  if st.session_state.notebook_ready:
113
  st.subheader("3. πŸ’» Review Notebook Skeleton")
114
- st.json(s["raw_notebook"])
 
 
 
 
 
 
 
 
 
 
115
 
116
  if st.session_state.notebook_approved is None:
117
- st.session_state.notebook_approved = st.radio("Looks good?", index=None, options=["YES","NO"])
118
  st.write(f"notebook approved: {st.session_state.notebook_approved}")
119
 
120
  if st.session_state.notebook_approved == "YES":
121
  if st.button("➑️ Next: Execute Notebook"):
122
  with st.spinner("Executing notebook…"):
123
  s = execute_notebook_node(s)
124
- st.session_state.exec_ready = True
125
  st.session_state.execution_approved = None
126
-
127
  elif st.session_state.notebook_approved == "NO":
128
  st.write("πŸ›  Please provide your feedback on the notebook skeleton:")
129
  st.text_area("What needs changing in the notebook skeleton?", key="nb_fb")
@@ -135,10 +146,22 @@ if st.session_state.notebook_ready:
135
  st.session_state.notebook_approved = None
136
  st.rerun()
137
 
 
 
138
  # ─── 4) Review & Correct Execution ───────────────────────────────────────────
139
- if st.session_state.exec_ready:
140
  st.subheader("4. πŸš€ Execution Results")
141
- st.json(s.get("executed_notebook"))
 
 
 
 
 
 
 
 
 
 
142
 
143
  if s.get("execution_error"):
144
  # Always reset approval until they choose Download As-Is
@@ -157,11 +180,7 @@ if st.session_state.exec_ready:
157
  st.session_state.execution_approved = True
158
 
159
  elif st.session_state.exec_action == "Provide Feedback":
160
- fb = st.text_area(
161
- "πŸ“ Describe how I should fix the error:",
162
- height=80,
163
- key="exec_feedback"
164
- )
165
  st.write(f"Execution feedback: {st.session_state.exec_feedback}")
166
  if st.button("πŸ›  Apply Feedback"):
167
  s["execution_feedback"] = fb
@@ -173,7 +192,7 @@ if st.session_state.exec_ready:
173
  st.session_state.execution_approved = None
174
  st.rerun()
175
 
176
- elif st.session_state.exec_action=="Auto-Correct & Retry": # Auto-Correct & Retry
177
  if st.button("πŸ”§ Auto-Correct & Retry"):
178
  s["execution_feedback"] = ""
179
  with st.spinner("Auto-correcting and re-executing…"):
@@ -187,27 +206,25 @@ if st.session_state.exec_ready:
187
  # If execution succeeded OR user chose β€œDownload As-Is”, show downloads
188
  if not s.get("execution_error") or st.session_state.execution_approved:
189
  st.success("βœ… Ready to download your artifacts!")
190
- st.download_button(
191
- "πŸ“₯ Download plan.json",
192
- data=json.dumps(s["plan"], indent=2),
193
- file_name="plan.json",
194
- mime="application/json",
195
- )
196
- st.download_button(
197
- "πŸ“₯ Download raw_notebook.ipynb",
198
- data=json.dumps(s["raw_notebook"], indent=2),
199
- file_name="raw_notebook.ipynb",
200
- mime="application/json",
201
- )
202
- st.download_button(
203
- "πŸ“₯ Download executed_notebook.ipynb",
204
- data=s["executed_notebook"],
205
- file_name="executed_notebook.ipynb",
206
- mime="application/json",
207
- )
208
-
209
-
210
- # ─── 5) Optionally Write Insights ─────────────────────────────────────────────
211
  # Only show this once the user has downloaded (or chosen) the executed notebook
212
  if st.session_state.exec_ready and (
213
  not s.get("execution_error") or st.session_state.execution_approved
@@ -221,22 +238,25 @@ if st.session_state.exec_ready and (
221
  else:
222
  st.success("Notebook executed end-to-end without errors!")
223
  st.info("You can now generate insights and conclusions based on the executed notebook.")
224
-
225
  # Ask permission
226
  st.session_state.insights_opt = st.radio(
227
  "Shall I proceed to write the insights and conclusion for this notebook?", index=None,
228
  options=["YES", "NO"]
229
- )
230
 
231
  if st.session_state.insights_opt == "YES":
232
  if st.button("πŸ“ Generate Insights Now"):
233
  with st.spinner("Writing observations & final recommendations…"):
234
  s = write_insights_node(s)
235
  st.success("πŸŽ‰ Insights generated!")
 
236
  # Render the final notebook with insights inline
237
  st.markdown("#### Final Notebook with Insights")
238
- st.json(s["final_notebook"])
239
- # Offer download
 
 
240
  st.download_button(
241
  "πŸ“₯ Download Final Notebook (.ipynb)",
242
  data=json.dumps(s["final_notebook"], indent=2),
 
3
  import json
4
  import streamlit as st
5
  from app_assets import app_logo
6
+ import io
7
+ from app_utils import parse_data_dictionary, display_notebook, style_css
8
  from workflow_nodes import (
9
  think_sections_node,
10
  enhance_plan_node,
 
14
  correct_notebook_node,
15
  write_insights_node
16
  )
 
17
  from workflow_nodes import InteractiveCaseStudyState
18
 
 
19
  st.set_page_config(layout="wide")
20
 
21
+ # Apply CSS styling
22
+ # This will apply the styles defined in style.css to the Streamlit app
23
+ style_css("style.css")
24
+
25
  st.title("πŸ““ NBforge Demo")
26
 
27
+ st.logo(app_logo, size='large', link='https://www.mygreatlearning.com/')
28
+
29
 
30
  # ─── Session State Initialization ─────────────────────────────────────────────
31
  if "state" not in st.session_state:
32
  st.session_state.state = InteractiveCaseStudyState()
33
+ st.session_state.plan_ready = False
34
+ st.session_state.plan_approved = None
35
+ st.session_state.notebook_ready = False
36
+ st.session_state.notebook_approved = None
37
+ st.session_state.exec_ready = False
38
+ st.session_state.execution_approved = None
39
 
40
  s = st.session_state.state
41
 
42
  # ─── 1) Collect Inputs ────────────────────────────────────────────────────────
43
  st.header("1. πŸ”§ Provide Your Inputs")
44
+ s["domain"] = st.selectbox("πŸ“‚ Select Domain", [
45
+ "EDA", "Machine Learning", "Deep Learning", "Natural Language Processing",
46
+ "Computer Vision", "Generative AI Prompt Engineering", "Generative AI RAG"
47
  ])
48
+ s["topics_and_subtopics"] = st.text_area("πŸ“š Weekly Topics & Subtopics", height=80)
49
+ s["problem_statement"] = st.text_area("🧩 Problem Statement", height=80)
50
+ s["dataset_type"] = st.selectbox("πŸ“ Dataset Type", ["csv", "pdf", "images", "json"])
51
 
52
  uploaded = st.file_uploader("⬆️ Upload Dataset", accept_multiple_files=False)
53
  if uploaded:
 
58
  s["dataset_file_path"] = path
59
  st.success(f"Dataset saved to `{path}`")
60
 
 
61
  s["data_dictionary"] = {}
62
  dd = st.text_area("πŸ“– Data Dictionary")
63
  s["data_dictionary"] = parse_data_dictionary(dd)
 
 
 
 
64
 
65
+ s["additional_instructions"] = st.text_area("πŸ“ Additional Instructions (optional)", height=60)
66
+
 
67
 
68
  # Kick off plan generation
69
+ if not st.session_state.plan_ready:
70
  if st.button("πŸš€ Generate Plan") and uploaded:
71
  with st.spinner("Designing notebook plan…"):
72
  s = think_sections_node(s)
73
+ st.session_state.plan_ready = True
74
+ st.session_state.plan_approved = None
75
+ st.session_state.notebook_ready = False
76
+ st.session_state.exec_ready = False
77
 
78
  # ─── 2) Review & Enhance Plan ────────────────────────────────────────────────
79
  if st.session_state.plan_ready:
80
  st.subheader("2. πŸ” Review Notebook Plan")
81
+
82
+ with st.expander("πŸ“‘ View Generated Plan"):
83
+ st.json(s["plan"])
84
+
85
+ # ask approval once
86
  if st.session_state.plan_approved is None:
87
+ st.session_state.plan_approved = st.radio("Approve this plan?", index=None, options=["YES", "NO"])
88
  st.write(f"Plan approved: {st.session_state.plan_approved}")
89
 
90
+
91
  # on approval, let user move on
92
  if st.session_state.plan_approved == "YES":
93
  if st.button("➑️ Next: Write Code"):
94
  with st.spinner("Writing notebook skeleton…"):
95
  s = write_code_node(s)
96
+ st.session_state.notebook_ready = True
97
  st.session_state.notebook_approved = None
98
+
99
  # on rejection, collect feedback & loop back
100
  elif st.session_state.plan_approved == "NO":
101
  st.text_area("What should be changed in the plan?", key="plan_fb")
 
104
  s["plan_feedback"] = st.session_state.plan_fb
105
  with st.spinner("Modifying notebook plan…"):
106
  s = enhance_plan_node(s)
107
+
108
  # reset approval so we review again
109
  st.session_state.plan_approved = None
110
  st.rerun()
 
112
  # ─── 3) Review & Modify Notebook ─────────────────────────────────────────────
113
  if st.session_state.notebook_ready:
114
  st.subheader("3. πŸ’» Review Notebook Skeleton")
115
+ with st.expander("πŸ“„ View Notebook Skeleton"):
116
+ display_notebook(io.StringIO(json.dumps(s["raw_notebook"], indent=2)))
117
+
118
+ st.info("----------------------------------------------------------------")
119
+ st.write("**NOTE**: If it’s hard to read here, download and open in Colab:")
120
+ st.download_button(
121
+ "Download raw_notebook.ipynb",
122
+ data=json.dumps(s["raw_notebook"], indent=2),
123
+ file_name="raw_notebook.ipynb",
124
+ mime="application/json",
125
+ )
126
 
127
  if st.session_state.notebook_approved is None:
128
+ st.session_state.notebook_approved = st.radio("Looks good?", index=None, options=["YES", "NO"])
129
  st.write(f"notebook approved: {st.session_state.notebook_approved}")
130
 
131
  if st.session_state.notebook_approved == "YES":
132
  if st.button("➑️ Next: Execute Notebook"):
133
  with st.spinner("Executing notebook…"):
134
  s = execute_notebook_node(s)
135
+ st.session_state.exec_ready = True
136
  st.session_state.execution_approved = None
137
+
138
  elif st.session_state.notebook_approved == "NO":
139
  st.write("πŸ›  Please provide your feedback on the notebook skeleton:")
140
  st.text_area("What needs changing in the notebook skeleton?", key="nb_fb")
 
146
  st.session_state.notebook_approved = None
147
  st.rerun()
148
 
149
+
150
+
151
  # ─── 4) Review & Correct Execution ───────────────────────────────────────────
152
+ if st.session_state.exec_ready:
153
  st.subheader("4. πŸš€ Execution Results")
154
+ with st.expander("πŸ“„ View Executed Notebook"):
155
+ display_notebook(io.StringIO(s["executed_notebook"]))
156
+
157
+ st.info("----------------------------------------------------------------")
158
+ st.write("**NOTE**: If it’s hard to read here, download and open in Colab:")
159
+ st.download_button(
160
+ "Download executed_notebook.ipynb",
161
+ data=s["executed_notebook"],
162
+ file_name="executed_notebook.ipynb",
163
+ mime="application/json",
164
+ )
165
 
166
  if s.get("execution_error"):
167
  # Always reset approval until they choose Download As-Is
 
180
  st.session_state.execution_approved = True
181
 
182
  elif st.session_state.exec_action == "Provide Feedback":
183
+ fb = st.text_area("πŸ“ Describe how I should fix the error:", height=80, key="exec_feedback")
 
 
 
 
184
  st.write(f"Execution feedback: {st.session_state.exec_feedback}")
185
  if st.button("πŸ›  Apply Feedback"):
186
  s["execution_feedback"] = fb
 
192
  st.session_state.execution_approved = None
193
  st.rerun()
194
 
195
+ elif st.session_state.exec_action == "Auto-Correct & Retry":
196
  if st.button("πŸ”§ Auto-Correct & Retry"):
197
  s["execution_feedback"] = ""
198
  with st.spinner("Auto-correcting and re-executing…"):
 
206
  # If execution succeeded OR user chose β€œDownload As-Is”, show downloads
207
  if not s.get("execution_error") or st.session_state.execution_approved:
208
  st.success("βœ… Ready to download your artifacts!")
209
+ st.download_button("πŸ“₯ Download plan.json",
210
+ data=json.dumps(s["plan"], indent=2),
211
+ file_name="plan.json",
212
+ mime="application/json"
213
+ )
214
+ st.download_button("πŸ“₯ Download raw_notebook.ipynb",
215
+ data=json.dumps(s["raw_notebook"], indent=2),
216
+ file_name="raw_notebook.ipynb",
217
+ mime="application/json"
218
+ )
219
+ st.download_button("πŸ“₯ Download executed_notebook.ipynb",
220
+ data=s["executed_notebook"],
221
+ file_name="executed_notebook.ipynb",
222
+ mime="application/json"
223
+ )
224
+
225
+
226
+
227
+ # ─── 5) Generate Insights (Optional) ──────────────────────────────────────────
 
 
228
  # Only show this once the user has downloaded (or chosen) the executed notebook
229
  if st.session_state.exec_ready and (
230
  not s.get("execution_error") or st.session_state.execution_approved
 
238
  else:
239
  st.success("Notebook executed end-to-end without errors!")
240
  st.info("You can now generate insights and conclusions based on the executed notebook.")
241
+
242
  # Ask permission
243
  st.session_state.insights_opt = st.radio(
244
  "Shall I proceed to write the insights and conclusion for this notebook?", index=None,
245
  options=["YES", "NO"]
246
+ )
247
 
248
  if st.session_state.insights_opt == "YES":
249
  if st.button("πŸ“ Generate Insights Now"):
250
  with st.spinner("Writing observations & final recommendations…"):
251
  s = write_insights_node(s)
252
  st.success("πŸŽ‰ Insights generated!")
253
+
254
  # Render the final notebook with insights inline
255
  st.markdown("#### Final Notebook with Insights")
256
+ with st.expander("πŸ“„ View Final Notebook with Insights"):
257
+ display_notebook(io.StringIO(json.dumps(s["final_notebook"], indent=2)))
258
+
259
+ # Offer download
260
  st.download_button(
261
  "πŸ“₯ Download Final Notebook (.ipynb)",
262
  data=json.dumps(s["final_notebook"], indent=2),