Update app.py
Browse files
app.py
CHANGED
|
@@ -1,83 +1,53 @@
|
|
| 1 |
-
import
|
| 2 |
-
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
st.
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
st.
|
| 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 |
-
st.write("**Final Answer:**")
|
| 55 |
-
st.write(answer)
|
| 56 |
-
st.session_state.show_reset_button = True
|
| 57 |
-
except Exception as e:
|
| 58 |
-
st.error(f"An error occurred: {str(e)}\n{traceback.format_exc()}")
|
| 59 |
-
st.session_state.show_reset_button = True
|
| 60 |
-
else:
|
| 61 |
-
st.warning("Please enter a question!")
|
| 62 |
-
# Reset the trigger flag after submission
|
| 63 |
-
st.session_state.reset_triggered = False
|
| 64 |
-
|
| 65 |
-
# Function to clear the input state
|
| 66 |
-
def clear_input():
|
| 67 |
-
st.session_state.show_reset_button = False
|
| 68 |
-
st.session_state.question = ""
|
| 69 |
-
st.session_state.pop("question_input", None)
|
| 70 |
-
st.session_state.pop("question_form", None)
|
| 71 |
-
st.session_state.reset_triggered = True
|
| 72 |
-
|
| 73 |
-
# Show Reset button only if show_reset_button is True
|
| 74 |
-
if st.session_state.show_reset_button:
|
| 75 |
-
if st.button("Reset"):
|
| 76 |
-
# Clear the input and reset state
|
| 77 |
-
clear_input()
|
| 78 |
-
# Refresh the webpage
|
| 79 |
-
st.rerun()
|
| 80 |
-
|
| 81 |
-
# Execute JavaScript to clear the input field if reset was triggered
|
| 82 |
-
if st.session_state.reset_triggered:
|
| 83 |
-
components.html(clear_input_js, height=0)
|
|
|
|
| 1 |
+
import uuid
|
| 2 |
+
import traceback
|
| 3 |
+
import streamlit as st
|
| 4 |
+
from deep_research_system import run_deep_research_system
|
| 5 |
+
|
| 6 |
+
# Set page configuration
|
| 7 |
+
st.set_page_config(page_title="Deep Research AI", layout="centered")
|
| 8 |
+
|
| 9 |
+
# Session state setup
|
| 10 |
+
if "question" not in st.session_state:
|
| 11 |
+
st.session_state.question = ""
|
| 12 |
+
if "show_result" not in st.session_state:
|
| 13 |
+
st.session_state.show_result = False
|
| 14 |
+
if "input_key" not in st.session_state:
|
| 15 |
+
st.session_state.input_key = str(uuid.uuid4()) # Unique key for the input field
|
| 16 |
+
|
| 17 |
+
# Title
|
| 18 |
+
st.title("Deep Research AI Agentic System")
|
| 19 |
+
st.write("Enter a question below to get the latest insights from web research. Click 'Reset' to start over.")
|
| 20 |
+
|
| 21 |
+
# Text input (outside form for easier control)
|
| 22 |
+
st.session_state.question = st.text_input(
|
| 23 |
+
"Your Question",
|
| 24 |
+
value=st.session_state.question,
|
| 25 |
+
placeholder="e.g., What are the latest advancements in quantum computing?",
|
| 26 |
+
key=st.session_state.input_key
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
# Submit button
|
| 30 |
+
if st.button("Get Answer"):
|
| 31 |
+
if st.session_state.question.strip() != "":
|
| 32 |
+
st.session_state.show_result = True
|
| 33 |
+
st.write(f"Research Agent: Searching for '{st.session_state.question}'...")
|
| 34 |
+
try:
|
| 35 |
+
with st.spinner("Gathering research data..."):
|
| 36 |
+
answer = run_deep_research_system(st.session_state.question)
|
| 37 |
+
st.success("Research complete!.Answer Drafter Agent: Drafted the final answer.")
|
| 38 |
+
st.markdown("**Final Answer:**")
|
| 39 |
+
st.write(answer)
|
| 40 |
+
except Exception as e:
|
| 41 |
+
st.error(f"An error occurred: {str(e)}\n{traceback.format_exc()}")
|
| 42 |
+
else:
|
| 43 |
+
st.warning("Please enter a question!")
|
| 44 |
+
|
| 45 |
+
# Show result
|
| 46 |
+
if st.session_state.show_result:
|
| 47 |
+
# Reset button
|
| 48 |
+
if st.button("Reset"):
|
| 49 |
+
# Clear session and reset input widget key to force input clear
|
| 50 |
+
st.session_state.question = ""
|
| 51 |
+
st.session_state.show_result = False
|
| 52 |
+
st.session_state.input_key = str(uuid.uuid4()) # New key forces fresh input widget
|
| 53 |
+
st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|