Spaces:
Running
Running
File size: 1,611 Bytes
c0a2f04 |
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 |
import streamlit as st
from gpt_researcher import GPTResearcher
import asyncio
import nest_asyncio
# 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()
# Constants
REPORT_TYPE = "research_report" # Assuming this remains constant; modify as needed
# Function to handle asynchronous calls
def run_async(coroutine):
loop = asyncio.get_event_loop()
return loop.run_until_complete(coroutine)
# Streamlit interface
st.title("GPT Research Report Generator")
# User inputs
query = st.text_input(
"Enter your research query:",
"Extract all the information about how the ranking for internal links works.",
)
report_type = st.selectbox(
"Select report type:",
options=["research_report", "summary", "detailed_analysis"],
index=0,
)
sources = st.text_area("Enter source URLs (one per line if multiple):")
# Processing the sources input into a list
source_urls = [url.strip() for url in sources.split("\n") if url.strip()]
# Button to generate report
if st.button("Generate Report"):
if not query:
st.warning("Please enter a query to generate a report.")
else:
with st.spinner("Generating report..."):
# Fetch the report asynchronously
fetch_report_coroutine = fetch_report(
query, report_type, source_urls if source_urls else None
)
report = run_async(fetch_report_coroutine)
st.success("Report generated successfully!")
st.write(report)
|