-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Expand file tree
/
Copy pathapp.py
More file actions
88 lines (73 loc) · 3.44 KB
/
app.py
File metadata and controls
88 lines (73 loc) · 3.44 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
import asyncio
import os
import streamlit as st
from research import run_deep_research
# Set up page configuration
st.set_page_config(page_title="🔍 Agentic Deep Researcher", layout="wide")
# Initialize session state variables
if "brightdata_api_key" not in st.session_state:
st.session_state.brightdata_api_key = ""
if "messages" not in st.session_state:
st.session_state.messages = []
def reset_chat():
st.session_state.messages = []
# Sidebar: Brightdata Configuration with updated logo link
with st.sidebar:
brightdata_html = """
<div style='display: flex; align-items: center; gap: 10px; margin-top: 5px;'>
<img src="https://mintcdn.com/brightdata/ilemiSHw8UogZ13k/logo/dark.svg?fit=max&auto=format&n=ilemiSHw8UogZ13k&q=85&s=915f8674c063645e01169d17413062dc" width="180">
<span style='font-size: 20px; color: white;'>Configuration</span>
</div>
"""
st.markdown(brightdata_html, unsafe_allow_html=True)
st.write("")
st.markdown(
"[Get your API key](https://brightdata.com/ai/mcp-server)", unsafe_allow_html=True
)
brightdata_api_key = st.text_input("Enter your Brightdata API Key", type="password")
if brightdata_api_key:
st.session_state.brightdata_api_key = brightdata_api_key
# Update the environment variable
os.environ["BRIGHT_DATA_API_TOKEN"] = brightdata_api_key
st.success("API Key stored successfully!")
# Main Chat Interface Header with powered by logos from original code links
col1, col2 = st.columns([6, 1])
with col1:
st.markdown(
"<h2 style='color: #0066cc;'>🔍 Agentic Deep Researcher</h2>",
unsafe_allow_html=True,
)
powered_by_html = """
<div style='display: flex; align-items: center; gap: 10px; margin-top: 5px;'>
<span style='font-size: 20px; color: #666;'>Powered by</span>
<img src="https://cdn.prod.website-files.com/66cf2bfc3ed15b02da0ca770/66d07240057721394308addd_Logo%20(1).svg" width="80">
<span style='font-size: 20px; color: #666;'>and</span>
<img src="https://mintcdn.com/brightdata/ilemiSHw8UogZ13k/logo/dark.svg?fit=max&auto=format&n=ilemiSHw8UogZ13k&q=85&s=915f8674c063645e01169d17413062dc" width="105">
</div>
"""
st.markdown(powered_by_html, unsafe_allow_html=True)
with col2:
st.button("Clear ↺", on_click=reset_chat)
# Add spacing between header and chat history
st.markdown("<div style='height: 30px;'></div>", unsafe_allow_html=True)
# Display chat history
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
# Accept user input and process the research query
if prompt := st.chat_input("Ask a question..."):
st.session_state.messages.append({"role": "user", "content": prompt})
with st.chat_message("user"):
st.markdown(prompt)
if not st.session_state.brightdata_api_key:
response = "Please enter your Brightdata API Key in the sidebar."
else:
with st.spinner("Researching... This may take a moment..."):
try:
result = asyncio.run(run_deep_research(prompt))
response = result
except Exception as e:
response = f"An error occurred: {str(e)}"
with st.chat_message("assistant"):
st.markdown(response)
st.session_state.messages.append({"role": "assistant", "content": response})