subashdvorak commited on
Commit
398d766
Β·
verified Β·
1 Parent(s): 8dfd1ea

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +89 -88
src/streamlit_app.py CHANGED
@@ -25,16 +25,16 @@ if 'generated_image' not in st.session_state:
25
  st.subheader("Step 1: Context Analysis")
26
  msg = st.text_input("Describe your business here until i say to move forward:")
27
  if st.button("Submit"):
28
- st.spinner("Analyzing your context....")
29
- resp = requests.post(f"{API_URL}/context-analysis", json={"message": msg})
30
- if resp.ok:
31
- response = resp.json()
32
- st.markdown(response.get('response'))
33
- if response.get('complete') == True:
34
- st.session_state.business_details = response.get("business_details", {})
35
- st.success('Context analysis completed. Scroll Down to step 2 now.')
36
- else:
37
- st.error("Failed to analyze context.")
38
 
39
  if st.session_state.business_details != {}:
40
  st.json(st.session_state.business_details)
@@ -44,18 +44,17 @@ st.markdown("---")
44
  # ---------------------- IDEATION ----------------------
45
  st.subheader("Step 2: Generate Ideas")
46
  if st.button("Generate Creative Ideas"):
47
- st.spinner("Implementing the ideation. Please wait....")
48
- resp = requests.post(f"{API_URL}/ideation")
49
- if resp.ok:
50
- result = resp.json()
51
- st.session_state.final_ideation = result["response"]["improver_response"][-1]
52
- # st.write("Final Ideas:")
53
- # for idea in eval(st.session_state.final_ideation):
54
- # st.markdown(f"- {idea}")
55
- else:
56
- st.error("Failed to generate ideas.")
57
 
58
- st.markdown("---")
59
  if len(st.session_state.final_ideation)>0:
60
  # st.subheader("Final Ideations")
61
  st.markdown(f"*Idea:1* - {eval(st.session_state.final_ideation)[0]}")
@@ -63,20 +62,21 @@ if len(st.session_state.final_ideation)>0:
63
  st.markdown(f"*Idea:3* - {eval(st.session_state.final_ideation)[2]}")
64
  st.markdown(f"*Idea:4* - {eval(st.session_state.final_ideation)[3]}")
65
  st.success('Ideas are generated. Go down to refine your ideas.')
 
66
 
67
 
68
  # ---------------------- HUMAN REFINEMENT ----------------------
69
  st.subheader("Step 3: Human Feedback Loop")
70
  query = st.text_input("Suggest a change or improvement to the ideas:")
71
  if st.button("Refine with Feedback"):
72
- st.spinner("Making changes. Please wait....")
73
- resp = requests.post(f"{API_URL}/human-idea-refining", json={"query": query})
74
- if resp.ok:
75
- refined = resp.json()['response']
76
- st.session_state.human_interactions.append(refined)
77
- # st.markdown(refined)
78
- else:
79
- st.error("Failed to refine ideas.")
80
 
81
  if len(st.session_state.human_interactions)>0:
82
  st.markdown(st.session_state.human_interactions[-1])
@@ -112,7 +112,6 @@ if uploaded_files:
112
 
113
  def call_brainstorming_api():
114
  print('Selected topics:', st.session_state.topics_to_pass)
115
- st.spinner("Brainstorming. Please wait...")
116
  response = requests.post(
117
  f"{API_URL}/brainstrom", # Replace with your actual endpoint
118
  params={"thread_id": "my-session"},
@@ -152,52 +151,54 @@ with col2:
152
  st.info("No brainstorming topics yet. Click 'Generate Brainstorm' to start.")
153
 
154
  if st.button("πŸš€ Brainstorm"):
155
- # Truncate future if we're not at the end
156
- if st.session_state.history_index < len(st.session_state.history) - 1:
157
- st.session_state.history = st.session_state.history[:st.session_state.history_index + 1]
158
-
159
- # Save current state to history
160
- current_state = {
161
- "selected_topics": st.session_state.selected_topics.copy(),
162
- "selected_from_brainstorm": st.session_state.selected_from_brainstorm.copy(),
163
- "story": st.session_state.story,
164
- "brainstorming_topics": st.session_state.brainstorming_topics.copy()
165
- }
166
- st.session_state.history.append(current_state)
167
- st.session_state.history_index += 1
168
-
169
- # Update current state
170
- st.session_state.selected_topics.extend(st.session_state.selected_from_brainstorm)
171
- st.session_state.selected_from_brainstorm = []
172
-
173
- call_brainstorming_api()
174
- st.rerun()
 
 
175
 
176
  if st.button("πŸ”™ Back"):
177
- st.spinner("Going back....")
178
- if st.session_state.history_index > 0:
179
- st.session_state.history_index -= 1
180
- state = st.session_state.history[st.session_state.history_index]
181
- st.session_state.selected_topics = state["selected_topics"]
182
- st.session_state.selected_from_brainstorm = state["selected_from_brainstorm"]
183
- st.session_state.story = state["story"]
184
- st.session_state.brainstorming_topics = state["brainstorming_topics"]
185
- st.rerun()
186
- else:
187
- st.warning("You're at the first step.")
188
 
189
  if st.button("πŸ”œ Forward"):
190
- st.spinner("Going Forward....")
191
- if st.session_state.history_index < len(st.session_state.history) - 1:
192
- st.session_state.history_index += 1
193
- state = st.session_state.history[st.session_state.history_index]
194
- st.session_state.selected_topics = state["selected_topics"]
195
- st.session_state.selected_from_brainstorm = state["selected_from_brainstorm"]
196
- st.session_state.story = state["story"]
197
- st.session_state.brainstorming_topics = state["brainstorming_topics"]
198
- st.rerun()
199
- else:
200
- st.warning("You're at the most recent step.")
201
 
202
  st.markdown("---")
203
 
@@ -205,14 +206,14 @@ st.markdown("---")
205
  # ---------------------- FINAL STORY ----------------------
206
  st.subheader("πŸ“– Step 5: Final Story")
207
  if st.button("Generate Final Story"):
208
- st.spinner("Generating final story. Please wait...")
209
- resp = requests.post(f"{API_URL}/generate-final-story")
210
- if resp.ok:
211
- st.session_state.final_story = resp.json()['response']
212
- # st.markdown(st.session_state.final_story)
213
- else:
214
- st.error("Failed to generate final story.")
215
- st.markdown(st.session_state.final_story)
216
  st.markdown("---")
217
 
218
 
@@ -223,14 +224,14 @@ if "generated_image" not in st.session_state:
223
  st.session_state.generated_image = None
224
 
225
  if st.button("Generate Image from Story"):
226
- st.spinner("Generating image. Please wait...")
227
- resp = requests.post(f"{API_URL}/generate-image")
228
- if resp.ok:
229
- img_base64 = resp.json()['response']
230
- st.session_state.generated_image=img_base64
231
- st.success("Image generated successfully.")
232
- else:
233
- st.error("Failed to generate image.")
234
 
235
  # Display image if it exists
236
  if st.session_state.generated_image != "":
 
25
  st.subheader("Step 1: Context Analysis")
26
  msg = st.text_input("Describe your business here until i say to move forward:")
27
  if st.button("Submit"):
28
+ with st.spinner("Analyzing your context...."):
29
+ resp = requests.post(f"{API_URL}/context-analysis", json={"message": msg})
30
+ if resp.ok:
31
+ response = resp.json()
32
+ st.markdown(response.get('response'))
33
+ if response.get('complete') == True:
34
+ st.session_state.business_details = response.get("business_details", {})
35
+ st.success('Context analysis completed. Scroll Down to step 2 now.')
36
+ else:
37
+ st.error("Failed to analyze context.")
38
 
39
  if st.session_state.business_details != {}:
40
  st.json(st.session_state.business_details)
 
44
  # ---------------------- IDEATION ----------------------
45
  st.subheader("Step 2: Generate Ideas")
46
  if st.button("Generate Creative Ideas"):
47
+ with st.spinner("Implementing the ideation. Please wait...."):
48
+ resp = requests.post(f"{API_URL}/ideation")
49
+ if resp.ok:
50
+ result = resp.json()
51
+ st.session_state.final_ideation = result["response"]["improver_response"][-1]
52
+ # st.write("Final Ideas:")
53
+ # for idea in eval(st.session_state.final_ideation):
54
+ # st.markdown(f"- {idea}")
55
+ else:
56
+ st.error("Failed to generate ideas.")
57
 
 
58
  if len(st.session_state.final_ideation)>0:
59
  # st.subheader("Final Ideations")
60
  st.markdown(f"*Idea:1* - {eval(st.session_state.final_ideation)[0]}")
 
62
  st.markdown(f"*Idea:3* - {eval(st.session_state.final_ideation)[2]}")
63
  st.markdown(f"*Idea:4* - {eval(st.session_state.final_ideation)[3]}")
64
  st.success('Ideas are generated. Go down to refine your ideas.')
65
+ st.markdown("---")
66
 
67
 
68
  # ---------------------- HUMAN REFINEMENT ----------------------
69
  st.subheader("Step 3: Human Feedback Loop")
70
  query = st.text_input("Suggest a change or improvement to the ideas:")
71
  if st.button("Refine with Feedback"):
72
+ with st.spinner("Making changes. Please wait...."):
73
+ resp = requests.post(f"{API_URL}/human-idea-refining", json={"query": query})
74
+ if resp.ok:
75
+ refined = resp.json()['response']
76
+ st.session_state.human_interactions.append(refined)
77
+ # st.markdown(refined)
78
+ else:
79
+ st.error("Failed to refine ideas.")
80
 
81
  if len(st.session_state.human_interactions)>0:
82
  st.markdown(st.session_state.human_interactions[-1])
 
112
 
113
  def call_brainstorming_api():
114
  print('Selected topics:', st.session_state.topics_to_pass)
 
115
  response = requests.post(
116
  f"{API_URL}/brainstrom", # Replace with your actual endpoint
117
  params={"thread_id": "my-session"},
 
151
  st.info("No brainstorming topics yet. Click 'Generate Brainstorm' to start.")
152
 
153
  if st.button("πŸš€ Brainstorm"):
154
+ with st.spinner("Brainstorming. Please wait..."):
155
+
156
+ # Truncate future if we're not at the end
157
+ if st.session_state.history_index < len(st.session_state.history) - 1:
158
+ st.session_state.history = st.session_state.history[:st.session_state.history_index + 1]
159
+
160
+ # Save current state to history
161
+ current_state = {
162
+ "selected_topics": st.session_state.selected_topics.copy(),
163
+ "selected_from_brainstorm": st.session_state.selected_from_brainstorm.copy(),
164
+ "story": st.session_state.story,
165
+ "brainstorming_topics": st.session_state.brainstorming_topics.copy()
166
+ }
167
+ st.session_state.history.append(current_state)
168
+ st.session_state.history_index += 1
169
+
170
+ # Update current state
171
+ st.session_state.selected_topics.extend(st.session_state.selected_from_brainstorm)
172
+ st.session_state.selected_from_brainstorm = []
173
+
174
+ call_brainstorming_api()
175
+ st.rerun()
176
 
177
  if st.button("πŸ”™ Back"):
178
+ with st.spinner("Going back...."):
179
+ if st.session_state.history_index > 0:
180
+ st.session_state.history_index -= 1
181
+ state = st.session_state.history[st.session_state.history_index]
182
+ st.session_state.selected_topics = state["selected_topics"]
183
+ st.session_state.selected_from_brainstorm = state["selected_from_brainstorm"]
184
+ st.session_state.story = state["story"]
185
+ st.session_state.brainstorming_topics = state["brainstorming_topics"]
186
+ st.rerun()
187
+ else:
188
+ st.warning("You're at the first step.")
189
 
190
  if st.button("πŸ”œ Forward"):
191
+ with st.spinner("Going Forward...."):
192
+ if st.session_state.history_index < len(st.session_state.history) - 1:
193
+ st.session_state.history_index += 1
194
+ state = st.session_state.history[st.session_state.history_index]
195
+ st.session_state.selected_topics = state["selected_topics"]
196
+ st.session_state.selected_from_brainstorm = state["selected_from_brainstorm"]
197
+ st.session_state.story = state["story"]
198
+ st.session_state.brainstorming_topics = state["brainstorming_topics"]
199
+ st.rerun()
200
+ else:
201
+ st.warning("You're at the most recent step.")
202
 
203
  st.markdown("---")
204
 
 
206
  # ---------------------- FINAL STORY ----------------------
207
  st.subheader("πŸ“– Step 5: Final Story")
208
  if st.button("Generate Final Story"):
209
+ with st.spinner("Generating final story. Please wait..."):
210
+ resp = requests.post(f"{API_URL}/generate-final-story")
211
+ if resp.ok:
212
+ st.session_state.final_story = resp.json()['response']
213
+ # st.markdown(st.session_state.final_story)
214
+ else:
215
+ st.error("Failed to generate final story.")
216
+ st.markdown(st.session_state.final_story)
217
  st.markdown("---")
218
 
219
 
 
224
  st.session_state.generated_image = None
225
 
226
  if st.button("Generate Image from Story"):
227
+ with st.spinner("Generating image. Please wait..."):
228
+ resp = requests.post(f"{API_URL}/generate-image")
229
+ if resp.ok:
230
+ img_base64 = resp.json()['response']
231
+ st.session_state.generated_image=img_base64
232
+ st.success("Image generated successfully.")
233
+ else:
234
+ st.error("Failed to generate image.")
235
 
236
  # Display image if it exists
237
  if st.session_state.generated_image != "":