Spaces:
Running
Running
Initial setup of Streamlit app for Hugging Face Spaces
Browse files- .DS_Store +0 -0
- .gitignore +1 -0
- app.py +53 -0
- requirements.txt +0 -0
.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.streamlit/secrets.toml
|
app.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
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"]
|
| 8 |
+
tavily_api_key = st.secrets["TAVILY_API_KEY"]
|
| 9 |
+
|
| 10 |
+
# Apply the asyncio patch from nest_asyncio if required
|
| 11 |
+
nest_asyncio.apply()
|
| 12 |
+
|
| 13 |
+
# Constants
|
| 14 |
+
REPORT_TYPE = "research_report" # Assuming this remains constant; modify as needed
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
# Function to handle asynchronous calls
|
| 18 |
+
def run_async(coroutine):
|
| 19 |
+
loop = asyncio.get_event_loop()
|
| 20 |
+
return loop.run_until_complete(coroutine)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# Streamlit interface
|
| 24 |
+
st.title("GPT Research Report Generator")
|
| 25 |
+
|
| 26 |
+
# User inputs
|
| 27 |
+
query = st.text_input(
|
| 28 |
+
"Enter your research query:",
|
| 29 |
+
"Extract all the information about how the ranking for internal links works.",
|
| 30 |
+
)
|
| 31 |
+
report_type = st.selectbox(
|
| 32 |
+
"Select report type:",
|
| 33 |
+
options=["research_report", "summary", "detailed_analysis"],
|
| 34 |
+
index=0,
|
| 35 |
+
)
|
| 36 |
+
sources = st.text_area("Enter source URLs (one per line if multiple):")
|
| 37 |
+
|
| 38 |
+
# Processing the sources input into a list
|
| 39 |
+
source_urls = [url.strip() for url in sources.split("\n") if url.strip()]
|
| 40 |
+
|
| 41 |
+
# Button to generate report
|
| 42 |
+
if st.button("Generate Report"):
|
| 43 |
+
if not query:
|
| 44 |
+
st.warning("Please enter a query to generate a report.")
|
| 45 |
+
else:
|
| 46 |
+
with st.spinner("Generating report..."):
|
| 47 |
+
# Fetch the report asynchronously
|
| 48 |
+
fetch_report_coroutine = fetch_report(
|
| 49 |
+
query, report_type, source_urls if source_urls else None
|
| 50 |
+
)
|
| 51 |
+
report = run_async(fetch_report_coroutine)
|
| 52 |
+
st.success("Report generated successfully!")
|
| 53 |
+
st.write(report)
|
requirements.txt
ADDED
|
File without changes
|