GabrielSalem commited on
Commit
c0bf892
Β·
verified Β·
1 Parent(s): 2d5d541

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -43
app.py CHANGED
@@ -234,66 +234,84 @@ def continue_chat(chat_history, user_message, analysis_text):
234
  # Gradio UI
235
  # -----------------------
236
  def build_demo():
237
- with gr.Blocks(title="AURA Chat β€” Hedge Fund Picks", css="""
238
- .gradio-container { max-width: 1100px; margin: 18px auto; }
239
- .header {text-align: left; margin-bottom: 6px;}
240
- .muted {color: #7d8590; font-size: 14px;}
241
- .analysis-box { background: #ffffff; border-radius: 8px; padding: 12px; box-shadow: 0 4px 14px rgba(0,0,0,0.06);}
242
- """) as demo:
 
 
 
 
 
 
 
 
 
 
 
243
  gr.Markdown("# AURA Chat β€” Hedge Fund Picks")
244
  gr.Markdown("**Enter one or more data prompts (one per line)** β€” e.g. `SEC insider transactions october 2025 company XYZ`.\n\nOnly input prompts; model, tokens and timing are fixed. Press **Analyze** to fetch & generate the picks. After analysis you can chat with the assistant about the results.")
245
 
246
  with gr.Row():
247
  with gr.Column(scale=1):
248
- prompts = gr.Textbox(lines=6, label="Data Prompts (one per line)", placeholder="SEC insider transactions october 2025\n13F filings Q3 2025\ncompany: ACME corp insider buys")
 
 
 
 
249
  analyze_btn = gr.Button("Analyze", variant="primary")
250
  error_box = gr.Markdown("", visible=False)
251
  gr.Markdown(f"**Fixed settings:** Model = `{LLM_MODEL}` β€’ Max tokens = `{MAX_TOKENS}` β€’ Scrape delay = `{SCRAPE_DELAY}s`")
252
  gr.Markdown("**Important:** Add your `OPENAI_API_KEY` to Space Secrets before running.")
253
  with gr.Column(scale=1):
254
- analysis_out = gr.Textbox(label="Generated Analysis (Top picks with Investment Duration)", lines=18, interactive=False)
 
 
 
 
255
  gr.Markdown("**Chat with AURA about this analysis**")
256
  chatbot = gr.Chatbot(label="AURA Chat", height=420)
257
- user_input = gr.Textbox(placeholder="Ask a follow-up question about the analysis...", label="Your question")
 
 
 
258
  send_btn = gr.Button("Send")
259
 
260
- # State to hold the analysis text and chat history
261
- analysis_state = gr.State("") # holds the analysis text (string)
262
- chat_state = gr.State([]) # holds list of (user, assistant) tuples
263
-
264
- # Hook: Analyze button
265
- def on_analyze(prompts_text):
266
- analysis_text, initial_chat = analyze_and_seed_chat(prompts_text)
267
- if analysis_text.startswith("ERROR"):
268
- return gr.update(value=analysis_text), gr.update(visible=True, value=f"**Error:** {analysis_text}"), "", []
269
- # Set outputs: analysis_out, clear chatbot and seed it
270
- # analysis_text displayed in the big box; the chat seeded with the pair
271
- return analysis_text, gr.update(visible=False, value=""), analysis_text, initial_chat
272
-
273
- analyze_btn.click(fn=on_analyze, inputs=[prompts], outputs=[analysis_out, error_box, analysis_state, chat_state])
274
-
275
- # Hook: Send follow-up chat message
276
- def on_send(chat_state_list, user_msg, analysis_text):
277
- if not user_msg.strip():
278
- return chat_state_list, ""
279
- # chat_state_list is list of tuples
280
- updated_history = continue_chat(chat_state_list or [], user_msg, analysis_text)
281
- # Clear user input after sending
282
- return updated_history, ""
283
-
284
- send_btn.click(fn=on_send, inputs=[chat_state, user_input, analysis_state], outputs=[chat_state, user_input])
285
- # Also allow pressing Enter in the user_input box
286
- user_input.submit(fn=on_send, inputs=[chat_state, user_input, analysis_state], outputs=[chat_state, user_input])
287
-
288
- # Render chat_state into the Chatbot UI whenever it updates
289
- def render_chat(chat_state_list):
290
- # gr.Chatbot expects a list of (user, assistant) pairs
291
- return chat_state_list or []
292
-
293
- chat_state.change(fn=render_chat, inputs=[chat_state], outputs=[chatbot])
294
 
295
  return demo
296
 
 
297
  # -----------------------
298
  # Clean shutdown helper
299
  # -----------------------
 
234
  # Gradio UI
235
  # -----------------------
236
  def build_demo():
237
+ with gr.Blocks(title="AURA Chat β€” Hedge Fund Picks") as demo:
238
+
239
+ # Inject custom CSS in a totally safe, backward-compatible way
240
+ gr.HTML("""
241
+ <style>
242
+ .gradio-container { max-width: 1100px; margin: 18px auto; }
243
+ .header { text-align: left; margin-bottom: 6px; }
244
+ .muted { color: #7d8590; font-size: 14px; }
245
+ .analysis-box {
246
+ background: #ffffff;
247
+ border-radius: 8px;
248
+ padding: 12px;
249
+ box-shadow: 0 4px 14px rgba(0,0,0,0.06);
250
+ }
251
+ </style>
252
+ """)
253
+
254
  gr.Markdown("# AURA Chat β€” Hedge Fund Picks")
255
  gr.Markdown("**Enter one or more data prompts (one per line)** β€” e.g. `SEC insider transactions october 2025 company XYZ`.\n\nOnly input prompts; model, tokens and timing are fixed. Press **Analyze** to fetch & generate the picks. After analysis you can chat with the assistant about the results.")
256
 
257
  with gr.Row():
258
  with gr.Column(scale=1):
259
+ prompts = gr.Textbox(
260
+ lines=6,
261
+ label="Data Prompts (one per line)",
262
+ placeholder="SEC insider transactions october 2025\n13F filings Q3 2025\ncompany: ACME corp insider buys"
263
+ )
264
  analyze_btn = gr.Button("Analyze", variant="primary")
265
  error_box = gr.Markdown("", visible=False)
266
  gr.Markdown(f"**Fixed settings:** Model = `{LLM_MODEL}` β€’ Max tokens = `{MAX_TOKENS}` β€’ Scrape delay = `{SCRAPE_DELAY}s`")
267
  gr.Markdown("**Important:** Add your `OPENAI_API_KEY` to Space Secrets before running.")
268
  with gr.Column(scale=1):
269
+ analysis_out = gr.Textbox(
270
+ label="Generated Analysis (Top picks with Investment Duration)",
271
+ lines=18,
272
+ interactive=False
273
+ )
274
  gr.Markdown("**Chat with AURA about this analysis**")
275
  chatbot = gr.Chatbot(label="AURA Chat", height=420)
276
+ user_input = gr.Textbox(
277
+ placeholder="Ask a follow-up question about the analysis...",
278
+ label="Your question"
279
+ )
280
  send_btn = gr.Button("Send")
281
 
282
+ # States
283
+ analysis_state = gr.State("")
284
+ chat_state = gr.State([])
285
+
286
+ # Analyze click
287
+ analyze_btn.click(
288
+ fn=on_analyze,
289
+ inputs=[prompts],
290
+ outputs=[analysis_out, error_box, analysis_state, chat_state]
291
+ )
292
+
293
+ # Chat send
294
+ send_btn.click(
295
+ fn=on_send,
296
+ inputs=[chat_state, user_input, analysis_state],
297
+ outputs=[chat_state, user_input]
298
+ )
299
+ user_input.submit(
300
+ fn=on_send,
301
+ inputs=[chat_state, user_input, analysis_state],
302
+ outputs=[chat_state, user_input]
303
+ )
304
+
305
+ # Render chat
306
+ chat_state.change(
307
+ fn=render_chat,
308
+ inputs=[chat_state],
309
+ outputs=[chatbot]
310
+ )
 
 
 
 
 
311
 
312
  return demo
313
 
314
+
315
  # -----------------------
316
  # Clean shutdown helper
317
  # -----------------------