Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import streamlit as st
|
|
| 2 |
from gpt_researcher import GPTResearcher
|
| 3 |
import asyncio
|
| 4 |
import nest_asyncio
|
|
|
|
| 5 |
|
| 6 |
# Access secrets
|
| 7 |
openai_api_key = st.secrets["OPENAI_API_KEY"]
|
|
@@ -10,36 +11,29 @@ tavily_api_key = st.secrets["TAVILY_API_KEY"]
|
|
| 10 |
# Apply the asyncio patch from nest_asyncio if required
|
| 11 |
nest_asyncio.apply()
|
| 12 |
|
|
|
|
|
|
|
|
|
|
| 13 |
# Constants
|
| 14 |
-
REPORT_TYPE = "research_report"
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
|
|
|
| 21 |
"""
|
| 22 |
-
Fetch a research report based on the provided query
|
| 23 |
-
|
| 24 |
"""
|
| 25 |
-
|
| 26 |
-
researcher = GPTResearcher(query=query, report_type=report_type, source_urls=sources)
|
| 27 |
-
|
| 28 |
-
# Conduct research
|
| 29 |
await researcher.conduct_research()
|
| 30 |
-
|
| 31 |
-
# Write the report after research has been conducted
|
| 32 |
report = await researcher.write_report()
|
| 33 |
-
|
| 34 |
-
# Return the completed report
|
| 35 |
return report
|
| 36 |
|
| 37 |
-
|
| 38 |
-
# Function to handle asynchronous calls
|
| 39 |
-
def run_async(coroutine):
|
| 40 |
-
loop = asyncio.get_event_loop()
|
| 41 |
-
return loop.run_until_complete(coroutine)
|
| 42 |
-
|
| 43 |
# Streamlit interface
|
| 44 |
st.title("Google Leak Reporting Tool")
|
| 45 |
|
|
@@ -55,8 +49,8 @@ if st.button("Generate Report"):
|
|
| 55 |
st.warning("Please enter a query to generate a report.")
|
| 56 |
else:
|
| 57 |
with st.spinner("Generating report..."):
|
| 58 |
-
# Fetch the report asynchronously using
|
| 59 |
-
fetch_report_coroutine = fetch_report(query, REPORT_TYPE
|
| 60 |
report = run_async(fetch_report_coroutine)
|
| 61 |
st.success("Report generated successfully!")
|
| 62 |
-
st.write(report)
|
|
|
|
| 2 |
from gpt_researcher import GPTResearcher
|
| 3 |
import asyncio
|
| 4 |
import nest_asyncio
|
| 5 |
+
import os
|
| 6 |
|
| 7 |
# Access secrets
|
| 8 |
openai_api_key = st.secrets["OPENAI_API_KEY"]
|
|
|
|
| 11 |
# Apply the asyncio patch from nest_asyncio if required
|
| 12 |
nest_asyncio.apply()
|
| 13 |
|
| 14 |
+
# Set the document path environment variable
|
| 15 |
+
os.environ['DOC_PATH'] = './' # Path to the folder with documents
|
| 16 |
+
|
| 17 |
# Constants
|
| 18 |
+
REPORT_TYPE = "research_report"
|
| 19 |
+
DOCUMENT_FILE = 'removed_code.txt' # Name of the document file
|
| 20 |
+
|
| 21 |
+
# Function to handle asynchronous calls
|
| 22 |
+
def run_async(coroutine):
|
| 23 |
+
loop = asyncio.get_event_loop()
|
| 24 |
+
return loop.run_until_complete(coroutine)
|
| 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 specified by DOCUMENT_FILE.
|
| 31 |
"""
|
| 32 |
+
researcher = GPTResearcher(query=query, report_type=report_type, report_source='local')
|
|
|
|
|
|
|
|
|
|
| 33 |
await researcher.conduct_research()
|
|
|
|
|
|
|
| 34 |
report = await researcher.write_report()
|
|
|
|
|
|
|
| 35 |
return report
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
# Streamlit interface
|
| 38 |
st.title("Google Leak Reporting Tool")
|
| 39 |
|
|
|
|
| 49 |
st.warning("Please enter a query to generate a report.")
|
| 50 |
else:
|
| 51 |
with st.spinner("Generating report..."):
|
| 52 |
+
# Fetch the report asynchronously using the local document
|
| 53 |
+
fetch_report_coroutine = fetch_report(query, REPORT_TYPE)
|
| 54 |
report = run_async(fetch_report_coroutine)
|
| 55 |
st.success("Report generated successfully!")
|
| 56 |
+
st.write(report)
|