Spaces:
Runtime error
Runtime error
File size: 3,146 Bytes
a6c98bd 81c2320 |
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 |
import traceback
import streamlit as st
import streamlit.components.v1 as components
from deep_research_system import run_deep_research_system
if __name__ == "__main__":
# Set page configuration
st.set_page_config(page_title="Deep Research AI", layout="centered")
# Title and instructions
st.title("Deep Research AI Agentic System")
st.write("Enter a question below to get the latest insights from web research. Click 'Reset' to start over.")
# Initialize session state
if "show_reset_button" not in st.session_state:
st.session_state.show_reset_button = False
if "question" not in st.session_state:
st.session_state.question = ""
if "reset_triggered" not in st.session_state:
st.session_state.reset_triggered = False
# JavaScript to clear the input field
clear_input_js = """
<script>
const input = document.querySelector('input[aria-label="Your Question"]');
if (input) {
input.value = '';
}
</script>
"""
# Use a form to manage the question input and submission
with st.form(key="question_form"):
st.session_state.question = st.text_input(
"Your Question",
placeholder="e.g., What are the latest advancements in quantum computing?",
value=st.session_state.question,
key="question_input"
)
submit_button = st.form_submit_button("Get Answer")
# Process the form submission
if submit_button:
if st.session_state.question:
st.write(f"Research Agent: Searching for '{st.session_state.question}'...")
try:
with st.spinner("Gathering research data..."):
answer = run_deep_research_system(st.session_state.question)
st.write("Research Agent: Found 5 relevant sources.")
st.write("Answer Drafter Agent: Drafted the final answer.")
st.write("**Final Answer:**")
st.write(answer)
st.session_state.show_reset_button = True
except Exception as e:
st.error(f"An error occurred: {str(e)}\n{traceback.format_exc()}")
st.session_state.show_reset_button = True
else:
st.warning("Please enter a question!")
# Reset the trigger flag after submission
st.session_state.reset_triggered = False
# Function to clear the input state
def clear_input():
st.session_state.show_reset_button = False
st.session_state.question = ""
st.session_state.pop("question_input", None)
st.session_state.pop("question_form", None)
st.session_state.reset_triggered = True
# Show Reset button only if show_reset_button is True
if st.session_state.show_reset_button:
if st.button("Reset"):
# Clear the input and reset state
clear_input()
# Refresh the webpage
st.rerun()
# Execute JavaScript to clear the input field if reset was triggered
if st.session_state.reset_triggered:
components.html(clear_input_js, height=0) |