Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,9 +3,8 @@ from gpt_researcher import GPTResearcher
|
|
| 3 |
import asyncio
|
| 4 |
import nest_asyncio
|
| 5 |
import os
|
| 6 |
-
from
|
| 7 |
-
|
| 8 |
-
import sys
|
| 9 |
|
| 10 |
# Access secrets
|
| 11 |
openai_api_key = st.secrets["OPENAI_API_KEY"]
|
|
@@ -20,18 +19,15 @@ os.environ["DOC_PATH"] = "./local" # Path to the folder with documents
|
|
| 20 |
# Constants
|
| 21 |
REPORT_TYPE = "research_report"
|
| 22 |
|
| 23 |
-
|
| 24 |
-
#
|
| 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 |
"""
|
| 33 |
Fetch a research report based on the provided query and report type.
|
| 34 |
-
Research is conducted on a local document.
|
| 35 |
"""
|
| 36 |
try:
|
| 37 |
researcher = GPTResearcher(
|
|
@@ -43,6 +39,13 @@ async def fetch_report(query, report_type):
|
|
| 43 |
return f"Error during research: {str(e)}"
|
| 44 |
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
# Streamlit interface
|
| 47 |
st.title("Google Leak Reporting Tool")
|
| 48 |
|
|
@@ -59,7 +62,10 @@ if st.button("Generate Report"):
|
|
| 59 |
st.warning("Please enter a query to generate a report.")
|
| 60 |
else:
|
| 61 |
with st.spinner("Generating report..."):
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
| 63 |
# Display the report or error message
|
| 64 |
if report and not report.startswith("Error"):
|
| 65 |
st.success("Report generated successfully!")
|
|
@@ -72,4 +78,4 @@ if st.button("Generate Report"):
|
|
| 72 |
mime="text/plain",
|
| 73 |
)
|
| 74 |
else:
|
| 75 |
-
st.error(report) # Show the error message if any
|
|
|
|
| 3 |
import asyncio
|
| 4 |
import nest_asyncio
|
| 5 |
import os
|
| 6 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 7 |
+
import threading
|
|
|
|
| 8 |
|
| 9 |
# Access secrets
|
| 10 |
openai_api_key = st.secrets["OPENAI_API_KEY"]
|
|
|
|
| 19 |
# Constants
|
| 20 |
REPORT_TYPE = "research_report"
|
| 21 |
|
| 22 |
+
# ThreadPoolExecutor to handle asynchronous tasks
|
| 23 |
+
executor = ThreadPoolExecutor(max_workers=4) # Adjust the number of workers as needed
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
|
| 26 |
# Define the asynchronous function to fetch the report
|
| 27 |
async def fetch_report(query, report_type):
|
| 28 |
"""
|
| 29 |
Fetch a research report based on the provided query and report type.
|
| 30 |
+
Research is conducted on a local document related to Google Search Algorithm Leak.
|
| 31 |
"""
|
| 32 |
try:
|
| 33 |
researcher = GPTResearcher(
|
|
|
|
| 39 |
return f"Error during research: {str(e)}"
|
| 40 |
|
| 41 |
|
| 42 |
+
# Function to run the asynchronous function in a separate thread
|
| 43 |
+
def run_async(coroutine):
|
| 44 |
+
loop = asyncio.new_event_loop()
|
| 45 |
+
asyncio.set_event_loop(loop)
|
| 46 |
+
return loop.run_until_complete(coroutine)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
# Streamlit interface
|
| 50 |
st.title("Google Leak Reporting Tool")
|
| 51 |
|
|
|
|
| 62 |
st.warning("Please enter a query to generate a report.")
|
| 63 |
else:
|
| 64 |
with st.spinner("Generating report..."):
|
| 65 |
+
# Submit the task to the ThreadPoolExecutor
|
| 66 |
+
future = executor.submit(run_async, fetch_report(query, REPORT_TYPE))
|
| 67 |
+
# Wait for the result
|
| 68 |
+
report = future.result()
|
| 69 |
# Display the report or error message
|
| 70 |
if report and not report.startswith("Error"):
|
| 71 |
st.success("Report generated successfully!")
|
|
|
|
| 78 |
mime="text/plain",
|
| 79 |
)
|
| 80 |
else:
|
| 81 |
+
st.error(report) # Show the error message if any
|