File size: 2,394 Bytes
c0a2f04
a1d082f
5654a6b
 
dbcc073
5654a6b
 
 
c0a2f04
 
 
 
 
5654a6b
 
 
dbcc073
187985b
dbcc073
c0a2f04
dbcc073
 
5654a6b
 
 
 
 
 
 
 
 
07df051
dbcc073
f32cee6
07df051
e1ecda6
187985b
 
 
5654a6b
 
e1ecda6
 
07df051
527848d
c0a2f04
187985b
c0a2f04
e1ecda6
04d19e0
c0a2f04
04d19e0
187985b
c0a2f04
 
5229ff8
c0a2f04
 
 
 
187985b
5654a6b
187985b
 
 
 
 
 
 
 
 
 
 
 
f32cee6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import streamlit as st
from gpt_researcher import GPTResearcher
import asyncio
import nest_asyncio
import os
from contextlib import contextmanager
from io import StringIO
import sys

# Access secrets
openai_api_key = st.secrets["OPENAI_API_KEY"]
tavily_api_key = st.secrets["TAVILY_API_KEY"]

# Apply the asyncio patch from nest_asyncio if required
nest_asyncio.apply()

# Set the document path environment variable
os.environ["DOC_PATH"] = "./local"  # Path to the folder with documents

# Constants
REPORT_TYPE = "research_report"


# Function to handle asynchronous calls
def run_async(coroutine):
    loop = asyncio.get_event_loop()
    return loop.run_until_complete(coroutine)


# Define the asynchronous function to fetch the report
async def fetch_report(query, report_type):
    """
    Fetch a research report based on the provided query and report type.
    Research is conducted on a local document.
    """
    try:
        researcher = GPTResearcher(
            query=query, report_type=report_type, report_source="local"
        )
        await researcher.conduct_research()
        return await researcher.write_report()
    except Exception as e:
        return f"Error during research: {str(e)}"


# Streamlit interface
st.title("Google Leak Reporting Tool")

# User input for the query using a text area
query = st.text_area(
    "Enter your research query:",
    "Extract all the information about how the ranking for internal links works.",
    height=150,  # Adjustable height
)

# Start the report generation process
if st.button("Generate Report"):
    if not query:
        st.warning("Please enter a query to generate a report.")
    else:
        with st.spinner("Generating report..."):
            report = run_async(fetch_report(query, REPORT_TYPE))
            # Display the report or error message
            if report and not report.startswith("Error"):
                st.success("Report generated successfully!")
                st.write(report)  # Display the report in the app
                # Create a download button for the report
                st.download_button(
                    label="Download Report as Text File",
                    data=report,
                    file_name="research_report.txt",
                    mime="text/plain",
                )
            else:
                st.error(report)  # Show the error message if any