cyberandy commited on
Commit
187985b
·
verified ·
1 Parent(s): a2cd918

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -35
app.py CHANGED
@@ -15,27 +15,18 @@ tavily_api_key = st.secrets["TAVILY_API_KEY"]
15
  nest_asyncio.apply()
16
 
17
  # Set the document path environment variable
18
- os.environ['DOC_PATH'] = './local' # Path to the folder with documents
19
 
20
  # Constants
21
  REPORT_TYPE = "research_report"
22
 
23
- # Function to capture output to the standard output
24
- @contextmanager
25
- def st_capture(output_func):
26
- old_out = sys.stdout
27
- sys.stdout = StringIO()
28
- try:
29
- yield
30
- output_func(sys.stdout.getvalue())
31
- finally:
32
- sys.stdout = old_out
33
 
34
  # Function to handle asynchronous calls
35
  def run_async(coroutine):
36
  loop = asyncio.get_event_loop()
37
  return loop.run_until_complete(coroutine)
38
 
 
39
  # Define the asynchronous function to fetch the report
40
  async def fetch_report(query, report_type):
41
  """
@@ -43,46 +34,42 @@ async def fetch_report(query, report_type):
43
  Research is conducted on a local document.
44
  """
45
  try:
46
- researcher = GPTResearcher(query=query, report_type=report_type, report_source='local')
 
 
47
  await researcher.conduct_research()
48
  return await researcher.write_report()
49
  except Exception as e:
50
  return f"Error during research: {str(e)}"
51
 
 
52
  # Streamlit interface
53
- st.title("Google Algo Leak Reporting Tool")
54
 
55
  # User input for the query using a text area
56
  query = st.text_area(
57
  "Enter your research query:",
58
  "Extract all the information about how the ranking for internal links works.",
59
- height=150 # Adjustable height
60
  )
61
 
62
- # Placeholder for the progress expander
63
- progress_expander = st.expander("See research progress", expanded=True)
64
- progress_placeholder = progress_expander.empty()
65
-
66
  # Start the report generation process
67
  if st.button("Generate Report"):
68
  if not query:
69
  st.warning("Please enter a query to generate a report.")
70
  else:
71
- # Display initial progress information
72
- progress_placeholder.info("Starting research...")
73
- # Run the research asynchronously and capture output
74
- with st_capture(progress_placeholder.code):
75
  report = run_async(fetch_report(query, REPORT_TYPE))
76
-
77
- if report and not report.startswith("Error"):
78
- st.success("Report generated successfully!")
79
- st.write(report) # Display the report in the app
80
- # Create a download button for the report
81
- st.download_button(
82
- label="Download Report as Text File",
83
- data=report,
84
- file_name="research_report.txt",
85
- mime="text/plain"
86
- )
87
- else:
88
- st.error(report) # Show the error message if any
 
15
  nest_asyncio.apply()
16
 
17
  # Set the document path environment variable
18
+ os.environ["DOC_PATH"] = "./local" # Path to the folder with documents
19
 
20
  # Constants
21
  REPORT_TYPE = "research_report"
22
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  # Function to handle asynchronous calls
25
  def run_async(coroutine):
26
  loop = asyncio.get_event_loop()
27
  return loop.run_until_complete(coroutine)
28
 
29
+
30
  # Define the asynchronous function to fetch the report
31
  async def fetch_report(query, report_type):
32
  """
 
34
  Research is conducted on a local document.
35
  """
36
  try:
37
+ researcher = GPTResearcher(
38
+ query=query, report_type=report_type, report_source="local"
39
+ )
40
  await researcher.conduct_research()
41
  return await researcher.write_report()
42
  except Exception as e:
43
  return f"Error during research: {str(e)}"
44
 
45
+
46
  # Streamlit interface
47
+ st.title("Google Leak Reporting Tool")
48
 
49
  # User input for the query using a text area
50
  query = st.text_area(
51
  "Enter your research query:",
52
  "Extract all the information about how the ranking for internal links works.",
53
+ height=150, # Adjustable height
54
  )
55
 
 
 
 
 
56
  # Start the report generation process
57
  if st.button("Generate Report"):
58
  if not query:
59
  st.warning("Please enter a query to generate a report.")
60
  else:
61
+ with st.spinner("Generating report..."):
 
 
 
62
  report = run_async(fetch_report(query, REPORT_TYPE))
63
+ # Display the report or error message
64
+ if report and not report.startswith("Error"):
65
+ st.success("Report generated successfully!")
66
+ st.write(report) # Display the report in the app
67
+ # Create a download button for the report
68
+ st.download_button(
69
+ label="Download Report as Text File",
70
+ data=report,
71
+ file_name="research_report.txt",
72
+ mime="text/plain",
73
+ )
74
+ else:
75
+ st.error(report) # Show the error message if any