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 = """
Configuration
""" 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( "

🔍 Agentic Deep Researcher

", unsafe_allow_html=True, ) powered_by_html = """
Powered by and
""" 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("
", 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})