mallocode200 commited on
Commit
5c67c52
Β·
verified Β·
1 Parent(s): ab78f68

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +21 -0
  2. deep_research.py +110 -9
  3. research_manager.py +3 -2
README.md CHANGED
@@ -14,6 +14,7 @@ A comprehensive AI-powered research assistant that delivers high-quality, well-r
14
  ## πŸš€ Features
15
 
16
  ### πŸ€– Enhanced AI Research System
 
17
  - **Quality Evaluation**: Every report is automatically assessed for completeness, accuracy, and clarity
18
  - **Smart Optimization**: Reports scoring below 7/10 are automatically improved
19
  - **Multi-Strategy Search**: Uses multiple search approaches for comprehensive coverage
@@ -108,6 +109,25 @@ SENDGRID_FROM_EMAIL=your_verified_sender_email@example.com
108
  - **GPT-4**: High quality for complex analysis
109
  - **O1-Preview**: Advanced reasoning for technical topics
110
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  ## πŸ“Š Quality Assurance System
112
 
113
  Our enhanced research system includes automatic quality evaluation:
@@ -141,6 +161,7 @@ Our enhanced research system includes automatic quality evaluation:
141
  - Use "⚑ Quick Research" for fast results
142
 
143
  5. **Get Results**:
 
144
  - View comprehensive research report
145
  - See which model was used for the research
146
  - Receive email delivery (if configured)
 
14
  ## πŸš€ Features
15
 
16
  ### πŸ€– Enhanced AI Research System
17
+ - **Real-Time Progress Tracking**: See step-by-step progress as research happens
18
  - **Quality Evaluation**: Every report is automatically assessed for completeness, accuracy, and clarity
19
  - **Smart Optimization**: Reports scoring below 7/10 are automatically improved
20
  - **Multi-Strategy Search**: Uses multiple search approaches for comprehensive coverage
 
109
  - **GPT-4**: High quality for complex analysis
110
  - **O1-Preview**: Advanced reasoning for technical topics
111
 
112
+ ## πŸ“Š Real-Time Progress Tracking
113
+
114
+ The research assistant now provides live updates during the research process, showing exactly what's happening at each step:
115
+
116
+ ### Progress Steps
117
+ 1. **πŸ“‹ Planning**: AI analyzes your query and creates a strategic search plan
118
+ 2. **πŸ” Searching**: Performs multiple targeted web searches (shows progress for each search)
119
+ 3. **✍️ Writing**: Synthesizes information into a comprehensive initial report
120
+ 4. **πŸ” Evaluating**: AI quality assessment of the report
121
+ 5. **πŸ”§ Optimizing**: Improves the report if needed (only when quality score < 7/10)
122
+ 6. **πŸ“§ Delivering**: Email delivery (if configured) or final report display
123
+
124
+ ### Progress Display Features
125
+ - **Step-by-step visibility**: See exactly which phase is currently running
126
+ - **Individual search tracking**: Monitor each web search as it completes
127
+ - **Quality scores**: View the evaluation score and whether optimization was needed
128
+ - **Real-time updates**: Progress streams live without page refreshes
129
+ - **Trace integration**: Each step links to detailed OpenAI trace logs
130
+
131
  ## πŸ“Š Quality Assurance System
132
 
133
  Our enhanced research system includes automatic quality evaluation:
 
161
  - Use "⚑ Quick Research" for fast results
162
 
163
  5. **Get Results**:
164
+ - Watch real-time progress updates during research
165
  - View comprehensive research report
166
  - See which model was used for the research
167
  - Receive email delivery (if configured)
deep_research.py CHANGED
@@ -253,13 +253,110 @@ async def run_legacy_research(query: str, api_key: str, model: str, email_addres
253
  print(f"Error details: {error_details}")
254
  return f"❌ Error during research: {str(e)}\n\nPlease check your API key and model selection."
255
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
256
  async def run_enhanced_research_with_progress(query: str, api_key: str, model: str, email_address: str = "", send_email: bool = False):
257
- """Run enhanced research with progress tracking"""
258
- return await run_direct_research(query, api_key, model, email_address, send_email)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
 
260
  async def run_clarified_research_with_progress(answers: str, current_state: dict, email_address: str, send_email: bool):
261
- """Run research with clarification answers and progress tracking"""
262
- return await handle_research_with_answers(answers, current_state, email_address, send_email)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263
 
264
  # Custom CSS for better readability and contrast
265
  custom_css = """
@@ -646,25 +743,29 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="blue"), css=custom_css) as u
646
  research_button.click(
647
  fn=run_clarified_research_with_progress,
648
  inputs=[answers_textbox, state, email_textbox, send_email_checkbox],
649
- outputs=[output_area]
 
650
  )
651
 
652
  answers_textbox.submit(
653
  fn=run_clarified_research_with_progress,
654
  inputs=[answers_textbox, state, email_textbox, send_email_checkbox],
655
- outputs=[output_area]
 
656
  )
657
 
658
  enhanced_button.click(
659
  fn=run_enhanced_research_with_progress,
660
  inputs=[query_textbox, api_key_textbox, model_textbox, email_textbox, send_email_checkbox],
661
- outputs=[output_area]
 
662
  )
663
 
664
  direct_button.click(
665
- fn=run_legacy_research,
666
  inputs=[query_textbox, api_key_textbox, model_textbox, email_textbox, send_email_checkbox],
667
- outputs=[output_area]
 
668
  )
669
 
670
  if __name__ == "__main__":
 
253
  print(f"Error details: {error_details}")
254
  return f"❌ Error during research: {str(e)}\n\nPlease check your API key and model selection."
255
 
256
+ async def run_direct_research_with_progress(query: str, api_key: str, model: str, email_address: str = "", send_email: bool = False):
257
+ """Run direct research with real-time progress tracking"""
258
+ if not query.strip():
259
+ yield "Please enter a research query."
260
+ return
261
+
262
+ if not api_key.strip():
263
+ yield "Please provide your OpenAI API key."
264
+ return
265
+
266
+ try:
267
+ # Import here to avoid circular imports
268
+ from research_manager import run_research_with_progress
269
+
270
+ # Use the progress-enabled research function
271
+ async for progress_update in run_research_with_progress(
272
+ query=query,
273
+ email_address=email_address if send_email else None,
274
+ send_email=send_email,
275
+ api_key=api_key,
276
+ model=model
277
+ ):
278
+ yield progress_update
279
+
280
+ except Exception as e:
281
+ import traceback
282
+ error_details = traceback.format_exc()
283
+ print(f"Error details: {error_details}")
284
+ yield f"❌ Error during research: {str(e)}\n\nPlease check your API key and model selection."
285
+
286
  async def run_enhanced_research_with_progress(query: str, api_key: str, model: str, email_address: str = "", send_email: bool = False):
287
+ """Run enhanced research with real-time progress tracking"""
288
+ if not query.strip():
289
+ yield "Please enter a research query."
290
+ return
291
+
292
+ if not api_key.strip():
293
+ yield "Please provide your OpenAI API key."
294
+ return
295
+
296
+ try:
297
+ # Import here to avoid circular imports
298
+ from research_manager import run_research_with_progress
299
+
300
+ # Use the progress-enabled research function
301
+ async for progress_update in run_research_with_progress(
302
+ query=query,
303
+ email_address=email_address if send_email else None,
304
+ send_email=send_email,
305
+ api_key=api_key,
306
+ model=model
307
+ ):
308
+ yield progress_update
309
+
310
+ except Exception as e:
311
+ import traceback
312
+ error_details = traceback.format_exc()
313
+ print(f"Error details: {error_details}")
314
+ yield f"❌ Error during enhanced research: {str(e)}\n\nPlease check your API key and model selection."
315
 
316
  async def run_clarified_research_with_progress(answers: str, current_state: dict, email_address: str, send_email: bool):
317
+ """Run research with clarification answers and real-time progress tracking"""
318
+ if not current_state.get("query"):
319
+ yield "Please start by entering a research query first."
320
+ return
321
+
322
+ if not answers.strip():
323
+ yield "Please provide answers to the clarifying questions."
324
+ return
325
+
326
+ api_key = current_state.get("api_key", "")
327
+ model = current_state.get("model", "gpt-4o-mini")
328
+
329
+ if not api_key:
330
+ yield "API key missing. Please restart with your API key."
331
+ return
332
+
333
+ try:
334
+ # Parse answers (one per line)
335
+ answer_list = [line.strip() for line in answers.split('\n') if line.strip()]
336
+
337
+ # Format the query with clarifications
338
+ clarified_query = f"""Original query: {current_state['query']}
339
+
340
+ Clarifications provided:
341
+ {chr(10).join([f"{i+1}. {answer}" for i, answer in enumerate(answer_list)])}
342
+
343
+ Please use these clarifications to focus and refine the research approach."""
344
+
345
+ # Import here to avoid circular imports
346
+ from research_manager import run_research_with_progress
347
+
348
+ # Use the progress-enabled research function with clarified query
349
+ async for progress_update in run_research_with_progress(
350
+ query=clarified_query,
351
+ email_address=email_address if send_email else None,
352
+ send_email=send_email,
353
+ api_key=api_key,
354
+ model=model
355
+ ):
356
+ yield progress_update
357
+
358
+ except Exception as e:
359
+ yield f"❌ Error during research: {str(e)}"
360
 
361
  # Custom CSS for better readability and contrast
362
  custom_css = """
 
743
  research_button.click(
744
  fn=run_clarified_research_with_progress,
745
  inputs=[answers_textbox, state, email_textbox, send_email_checkbox],
746
+ outputs=[output_area],
747
+ show_progress=True
748
  )
749
 
750
  answers_textbox.submit(
751
  fn=run_clarified_research_with_progress,
752
  inputs=[answers_textbox, state, email_textbox, send_email_checkbox],
753
+ outputs=[output_area],
754
+ show_progress=True
755
  )
756
 
757
  enhanced_button.click(
758
  fn=run_enhanced_research_with_progress,
759
  inputs=[query_textbox, api_key_textbox, model_textbox, email_textbox, send_email_checkbox],
760
+ outputs=[output_area],
761
+ show_progress=True
762
  )
763
 
764
  direct_button.click(
765
+ fn=run_direct_research_with_progress,
766
  inputs=[query_textbox, api_key_textbox, model_textbox, email_textbox, send_email_checkbox],
767
+ outputs=[output_area],
768
+ show_progress=True
769
  )
770
 
771
  if __name__ == "__main__":
research_manager.py CHANGED
@@ -529,8 +529,9 @@ Please improve the report based on this feedback."""
529
 
530
  try:
531
  # Call the regular function directly
532
- result = await _send_report_email_to_address(final_report, email_address)
533
- yield f"βœ… **Email Sent Successfully** to {email_address}\n\n---\n\n"
 
534
  except Exception as e:
535
  yield f"❌ **Email Failed:** {str(e)}\n\n---\n\n"
536
  else:
 
529
 
530
  try:
531
  # Call the regular function directly
532
+ email_result = await _send_report_email_to_address(final_report, email_address)
533
+ email_status = email_result.get("status", "Email status unknown")
534
+ yield f"βœ… **Email Delivery:** {email_status}\n\n---\n\n"
535
  except Exception as e:
536
  yield f"❌ **Email Failed:** {str(e)}\n\n---\n\n"
537
  else: