Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,10 @@
|
|
| 1 |
import streamlit as st
|
| 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"]
|
|
@@ -18,6 +20,17 @@ os.environ['DOC_PATH'] = './local' # Path to the folder with documents
|
|
| 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()
|
|
@@ -37,20 +50,34 @@ async def fetch_report(query, report_type):
|
|
| 37 |
# Streamlit interface
|
| 38 |
st.title("Google Leak Reporting Tool")
|
| 39 |
|
| 40 |
-
# User input for the query
|
| 41 |
-
query = st.
|
| 42 |
"Enter your research query:",
|
| 43 |
-
"Extract all the information about how the ranking for internal links works."
|
|
|
|
| 44 |
)
|
| 45 |
|
|
|
|
| 46 |
# Button to generate report
|
| 47 |
if st.button("Generate Report"):
|
| 48 |
if not query:
|
| 49 |
st.warning("Please enter a query to generate a report.")
|
| 50 |
else:
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
| 55 |
st.success("Report generated successfully!")
|
| 56 |
-
st.write(report)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
import asyncio
|
| 3 |
import nest_asyncio
|
| 4 |
import os
|
| 5 |
+
import sys
|
| 6 |
+
from contextlib import contextmanager
|
| 7 |
+
from io import StringIO
|
| 8 |
|
| 9 |
# Access secrets
|
| 10 |
openai_api_key = st.secrets["OPENAI_API_KEY"]
|
|
|
|
| 20 |
REPORT_TYPE = "research_report"
|
| 21 |
DOCUMENT_FILE = 'removed_code.txt' # Name of the document file
|
| 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()
|
|
|
|
| 50 |
# Streamlit interface
|
| 51 |
st.title("Google Leak Reporting Tool")
|
| 52 |
|
| 53 |
+
# User input for the query using a text area for multi-line input
|
| 54 |
+
query = st.text_area(
|
| 55 |
"Enter your research query:",
|
| 56 |
+
"Extract all the information about how the ranking for internal links works.",
|
| 57 |
+
height=150 # You can adjust the height as needed
|
| 58 |
)
|
| 59 |
|
| 60 |
+
|
| 61 |
# Button to generate report
|
| 62 |
if st.button("Generate Report"):
|
| 63 |
if not query:
|
| 64 |
st.warning("Please enter a query to generate a report.")
|
| 65 |
else:
|
| 66 |
+
# Collapsible expander to show progress
|
| 67 |
+
with st.expander("See research progress"):
|
| 68 |
+
with st_capture(st.write):
|
| 69 |
+
report = run_async(fetch_report(query, "research_report"))
|
| 70 |
+
|
| 71 |
+
if report:
|
| 72 |
st.success("Report generated successfully!")
|
| 73 |
+
st.write(report) # Display the report in the app
|
| 74 |
+
|
| 75 |
+
# Create a download button and provide the report as a downloadable file
|
| 76 |
+
st.download_button(
|
| 77 |
+
label="Download Report as Text File",
|
| 78 |
+
data=report,
|
| 79 |
+
file_name="research_report.txt",
|
| 80 |
+
mime="text/plain"
|
| 81 |
+
)
|
| 82 |
+
else:
|
| 83 |
+
st.error("Failed to generate the report.")
|