Spaces:
Sleeping
Sleeping
Priyansh Saxena commited on
Commit ·
acd7de3
1
Parent(s): 9d2e886
Migration Phase 5: Web interface implementation
Browse files
app.py
CHANGED
|
@@ -4,38 +4,22 @@ from dotenv import load_dotenv
|
|
| 4 |
from agent.graph import app
|
| 5 |
from agent.state import AgentState
|
| 6 |
|
|
|
|
| 7 |
load_dotenv()
|
| 8 |
|
| 9 |
-
st.set_page_config(page_title="AutoStream AI Sales Assistant", page_icon="🎬", layout="centered")
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
| 12 |
st.markdown("""
|
| 13 |
<style>
|
| 14 |
.stChatFloatingInputContainer {
|
| 15 |
bottom: 20px;
|
| 16 |
}
|
| 17 |
-
.main {
|
| 18 |
-
background-color: #0E1117;
|
| 19 |
-
}
|
| 20 |
-
h1 {
|
| 21 |
-
color: #E2E8F0;
|
| 22 |
-
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
| 23 |
-
font-weight: 700;
|
| 24 |
-
text-align: center;
|
| 25 |
-
margin-bottom: 2rem;
|
| 26 |
-
}
|
| 27 |
-
.subtitle {
|
| 28 |
-
color: #94A3B8;
|
| 29 |
-
text-align: center;
|
| 30 |
-
margin-bottom: 2rem;
|
| 31 |
-
font-size: 1.1rem;
|
| 32 |
-
}
|
| 33 |
-
.stAlert {
|
| 34 |
-
border-radius: 8px;
|
| 35 |
-
}
|
| 36 |
</style>
|
| 37 |
""", unsafe_allow_html=True)
|
| 38 |
|
|
|
|
| 39 |
if "messages" not in st.session_state:
|
| 40 |
st.session_state.messages = []
|
| 41 |
|
|
@@ -51,43 +35,54 @@ if "messages" not in st.session_state:
|
|
| 51 |
response=""
|
| 52 |
)
|
| 53 |
|
|
|
|
| 54 |
st.session_state.messages.append({"role": "assistant", "content": "Hello! I'm the AutoStream assistant. I can answer questions about our features and pricing. How can I help you today?"})
|
| 55 |
|
| 56 |
-
st.markdown("<h1>🎬 AutoStream Assistant</h1>", unsafe_allow_html=True)
|
| 57 |
-
st.markdown("<div class='subtitle'>Ask about features and pricing, or sign up for a plan instantly!</div>", unsafe_allow_html=True)
|
| 58 |
|
| 59 |
if not os.environ.get("OPENAI_API_KEY"):
|
| 60 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
for message in st.session_state.messages:
|
| 63 |
with st.chat_message(message["role"]):
|
| 64 |
st.markdown(message["content"])
|
| 65 |
|
|
|
|
| 66 |
if prompt := st.chat_input("What would you like to know?"):
|
| 67 |
|
| 68 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 69 |
with st.chat_message("user"):
|
| 70 |
st.markdown(prompt)
|
| 71 |
|
|
|
|
| 72 |
st.session_state.agent_state["current_message"] = prompt
|
| 73 |
|
|
|
|
| 74 |
with st.chat_message("assistant"):
|
| 75 |
with st.spinner("Thinking..."):
|
| 76 |
try:
|
|
|
|
| 77 |
result_state = app.invoke(st.session_state.agent_state)
|
| 78 |
st.session_state.agent_state = result_state
|
| 79 |
|
| 80 |
response = result_state["response"]
|
| 81 |
|
|
|
|
| 82 |
st.session_state.agent_state["conversation_history"].append({"role": "user", "content": prompt})
|
| 83 |
st.session_state.agent_state["conversation_history"].append({"role": "assistant", "content": response})
|
| 84 |
|
|
|
|
| 85 |
if len(st.session_state.agent_state["conversation_history"]) > 12:
|
| 86 |
st.session_state.agent_state["conversation_history"] = st.session_state.agent_state["conversation_history"][-12:]
|
| 87 |
|
|
|
|
| 88 |
st.markdown(response)
|
| 89 |
|
| 90 |
-
|
|
|
|
| 91 |
st.write(f"**Detected Intent:** `{result_state.get('detected_intent', 'UNKNOWN')}`")
|
| 92 |
if result_state.get("retrieved_documents") and result_state.get("detected_intent") in ["PRODUCT_QUERY", "PRICING_QUERY"]:
|
| 93 |
st.write(f"**RAG Retrieval:** Found {len(result_state['retrieved_documents'])} relevant knowledge chunks.")
|
|
@@ -104,4 +99,5 @@ if prompt := st.chat_input("What would you like to know?"):
|
|
| 104 |
response = f"An error occurred: {str(e)}"
|
| 105 |
st.error(response)
|
| 106 |
|
|
|
|
| 107 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
|
|
|
| 4 |
from agent.graph import app
|
| 5 |
from agent.state import AgentState
|
| 6 |
|
| 7 |
+
|
| 8 |
load_dotenv()
|
| 9 |
|
|
|
|
| 10 |
|
| 11 |
+
st.set_page_config(page_title="AutoStream AI Sales Assistant", page_icon="🤖", layout="centered")
|
| 12 |
+
|
| 13 |
+
|
| 14 |
st.markdown("""
|
| 15 |
<style>
|
| 16 |
.stChatFloatingInputContainer {
|
| 17 |
bottom: 20px;
|
| 18 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</style>
|
| 20 |
""", unsafe_allow_html=True)
|
| 21 |
|
| 22 |
+
|
| 23 |
if "messages" not in st.session_state:
|
| 24 |
st.session_state.messages = []
|
| 25 |
|
|
|
|
| 35 |
response=""
|
| 36 |
)
|
| 37 |
|
| 38 |
+
|
| 39 |
st.session_state.messages.append({"role": "assistant", "content": "Hello! I'm the AutoStream assistant. I can answer questions about our features and pricing. How can I help you today?"})
|
| 40 |
|
|
|
|
|
|
|
| 41 |
|
| 42 |
if not os.environ.get("OPENAI_API_KEY"):
|
| 43 |
+
st.warning("⚠️ OPENAI_API_KEY is not set. Please set it in your environment to use the agent.")
|
| 44 |
+
|
| 45 |
+
st.title("🤖 AutoStream AI Sales Assistant")
|
| 46 |
+
st.markdown("Ask me about AutoStream features and pricing, or sign up for a plan!")
|
| 47 |
+
|
| 48 |
|
| 49 |
for message in st.session_state.messages:
|
| 50 |
with st.chat_message(message["role"]):
|
| 51 |
st.markdown(message["content"])
|
| 52 |
|
| 53 |
+
|
| 54 |
if prompt := st.chat_input("What would you like to know?"):
|
| 55 |
|
| 56 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 57 |
with st.chat_message("user"):
|
| 58 |
st.markdown(prompt)
|
| 59 |
|
| 60 |
+
|
| 61 |
st.session_state.agent_state["current_message"] = prompt
|
| 62 |
|
| 63 |
+
|
| 64 |
with st.chat_message("assistant"):
|
| 65 |
with st.spinner("Thinking..."):
|
| 66 |
try:
|
| 67 |
+
|
| 68 |
result_state = app.invoke(st.session_state.agent_state)
|
| 69 |
st.session_state.agent_state = result_state
|
| 70 |
|
| 71 |
response = result_state["response"]
|
| 72 |
|
| 73 |
+
|
| 74 |
st.session_state.agent_state["conversation_history"].append({"role": "user", "content": prompt})
|
| 75 |
st.session_state.agent_state["conversation_history"].append({"role": "assistant", "content": response})
|
| 76 |
|
| 77 |
+
|
| 78 |
if len(st.session_state.agent_state["conversation_history"]) > 12:
|
| 79 |
st.session_state.agent_state["conversation_history"] = st.session_state.agent_state["conversation_history"][-12:]
|
| 80 |
|
| 81 |
+
|
| 82 |
st.markdown(response)
|
| 83 |
|
| 84 |
+
|
| 85 |
+
with st.expander("Agent Reasoning & State"):
|
| 86 |
st.write(f"**Detected Intent:** `{result_state.get('detected_intent', 'UNKNOWN')}`")
|
| 87 |
if result_state.get("retrieved_documents") and result_state.get("detected_intent") in ["PRODUCT_QUERY", "PRICING_QUERY"]:
|
| 88 |
st.write(f"**RAG Retrieval:** Found {len(result_state['retrieved_documents'])} relevant knowledge chunks.")
|
|
|
|
| 99 |
response = f"An error occurred: {str(e)}"
|
| 100 |
st.error(response)
|
| 101 |
|
| 102 |
+
|
| 103 |
st.session_state.messages.append({"role": "assistant", "content": response})
|