QuantumLearner commited on
Commit
a31c9e8
·
verified ·
1 Parent(s): f5da570

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -22,11 +22,7 @@ if not openai_api_key or not tavily_api_key:
22
  # Define the asynchronous function to get the report and capture logs
23
  async def get_report(query: str, report_type: str, sources: list, report_source: str):
24
  f = io.StringIO()
25
- logs_container = st.empty()
26
- logs = ''
27
-
28
- # Create the text area widget once before the loop
29
- logs_container.text_area("Agent Logs", logs, height=200, key="realtime_logs_display")
30
 
31
  with redirect_stdout(f):
32
  if report_source == 'local':
@@ -35,19 +31,22 @@ async def get_report(query: str, report_type: str, sources: list, report_source:
35
  else:
36
  researcher = GPTResearcher(query=query, report_type=report_type, source_urls=sources)
37
 
 
38
  await researcher.conduct_research()
39
 
40
  while True:
41
  logs = f.getvalue()
42
- # Update the content of the text area via session_state
43
- st.session_state.realtime_logs_display = logs
44
- await asyncio.sleep(1) # Update every second
45
  if "Finalized research step" in logs:
46
  break
47
 
 
48
  report = await researcher.write_report()
49
  return report, f.getvalue()
50
 
 
51
  # Function to create PDF using fpdf with UTF-8 encoding
52
  class PDF(FPDF):
53
  def header(self):
 
22
  # Define the asynchronous function to get the report and capture logs
23
  async def get_report(query: str, report_type: str, sources: list, report_source: str):
24
  f = io.StringIO()
25
+ logs_container = st.empty() # Create a placeholder for the logs
 
 
 
 
26
 
27
  with redirect_stdout(f):
28
  if report_source == 'local':
 
31
  else:
32
  researcher = GPTResearcher(query=query, report_type=report_type, source_urls=sources)
33
 
34
+ # Start the research process
35
  await researcher.conduct_research()
36
 
37
  while True:
38
  logs = f.getvalue()
39
+ # Update the text area within the placeholder
40
+ logs_container.text_area("Agent Logs", logs, height=200)
41
+ await asyncio.sleep(1) # Wait for a second before the next update
42
  if "Finalized research step" in logs:
43
  break
44
 
45
+ # Generate the final report
46
  report = await researcher.write_report()
47
  return report, f.getvalue()
48
 
49
+
50
  # Function to create PDF using fpdf with UTF-8 encoding
51
  class PDF(FPDF):
52
  def header(self):