Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,7 +19,6 @@ os.environ['DOC_PATH'] = './local' # Path to the folder with documents
|
|
| 19 |
|
| 20 |
# Constants
|
| 21 |
REPORT_TYPE = "research_report"
|
| 22 |
-
DOCUMENT_FILE = 'removed_code.txt' # Name of the document file
|
| 23 |
|
| 24 |
# Function to capture output to the standard output
|
| 25 |
@contextmanager
|
|
@@ -41,21 +40,23 @@ def run_async(coroutine):
|
|
| 41 |
async def fetch_report(query, report_type):
|
| 42 |
"""
|
| 43 |
Fetch a research report based on the provided query and report type.
|
| 44 |
-
Research is conducted on a local document
|
| 45 |
"""
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
| 50 |
|
| 51 |
# Streamlit interface
|
| 52 |
st.title("Google Leak Reporting Tool")
|
| 53 |
|
| 54 |
-
# User input for the query using a text area
|
| 55 |
query = st.text_area(
|
| 56 |
"Enter your research query:",
|
| 57 |
"Extract all the information about how the ranking for internal links works.",
|
| 58 |
-
height=150 #
|
| 59 |
)
|
| 60 |
|
| 61 |
# Placeholder for the progress expander
|
|
@@ -67,16 +68,15 @@ if st.button("Generate Report"):
|
|
| 67 |
if not query:
|
| 68 |
st.warning("Please enter a query to generate a report.")
|
| 69 |
else:
|
| 70 |
-
#
|
| 71 |
progress_placeholder.info("Starting research...")
|
| 72 |
# Run the research asynchronously and capture output
|
| 73 |
-
with
|
| 74 |
report = run_async(fetch_report(query, REPORT_TYPE))
|
| 75 |
|
| 76 |
-
if report:
|
| 77 |
st.success("Report generated successfully!")
|
| 78 |
st.write(report) # Display the report in the app
|
| 79 |
-
|
| 80 |
# Create a download button for the report
|
| 81 |
st.download_button(
|
| 82 |
label="Download Report as Text File",
|
|
@@ -85,4 +85,4 @@ if st.button("Generate Report"):
|
|
| 85 |
mime="text/plain"
|
| 86 |
)
|
| 87 |
else:
|
| 88 |
-
st.error(
|
|
|
|
| 19 |
|
| 20 |
# Constants
|
| 21 |
REPORT_TYPE = "research_report"
|
|
|
|
| 22 |
|
| 23 |
# Function to capture output to the standard output
|
| 24 |
@contextmanager
|
|
|
|
| 40 |
async def fetch_report(query, report_type):
|
| 41 |
"""
|
| 42 |
Fetch a research report based on the provided query and 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 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
|
|
|
|
| 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",
|
|
|
|
| 85 |
mime="text/plain"
|
| 86 |
)
|
| 87 |
else:
|
| 88 |
+
st.error(report) # Show the error message if any
|