google-labs-jules[bot] archc0der commited on
Commit
c987214
·
1 Parent(s): 0643073

feat: Add Streamlit UI, Dockerfile, and HF Spaces config

Browse files

Co-authored-by: archc0der <119496494+archc0der@users.noreply.github.com>

Files changed (4) hide show
  1. Dockerfile +28 -0
  2. README.md +20 -2
  3. app.py +103 -0
  4. requirements.txt +1 -0
Dockerfile ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use the official Python 3.10 image from DockerHub
2
+ FROM python:3.10-slim
3
+
4
+ # Set the working directory
5
+ WORKDIR /app
6
+
7
+ # Copy the requirements file and install dependencies
8
+ COPY requirements.txt .
9
+ RUN pip install --no-cache-dir -r requirements.txt
10
+
11
+ # Copy the application code
12
+ COPY . .
13
+
14
+ # Expose the default port for Streamlit and HuggingFace Spaces
15
+ EXPOSE 7860
16
+
17
+ # Create a non-root user for HuggingFace Spaces (required by HF)
18
+ RUN useradd -m -u 1000 user
19
+ USER user
20
+
21
+ # Define environment variables
22
+ ENV HOME=/home/user \
23
+ PATH=/home/user/.local/bin:$PATH \
24
+ STREAMLIT_SERVER_PORT=7860 \
25
+ STREAMLIT_SERVER_ADDRESS=0.0.0.0
26
+
27
+ # Start the Streamlit application
28
+ CMD ["streamlit", "run", "app.py"]
README.md CHANGED
@@ -1,8 +1,26 @@
 
 
 
 
 
 
 
 
 
1
  # AutoStream Conversational AI Agent
2
 
3
  ## Project Overview
4
  This project is a production-quality Conversational AI Agent built for **AutoStream**, a fictional SaaS company. It handles customer inquiries, answers product questions using a Knowledge Base (RAG), and detects high-intent users to seamlessly collect lead information and execute backend lead capture functions.
5
 
 
 
 
 
 
 
 
 
 
6
  ## System Architecture
7
  The system is designed as an agentic workflow using **LangGraph**, replacing traditional linear chatbots with a stateful, branching graph architecture.
8
  1. **User Input & State Management**: User messages and conversational context are persisted in a shared `AgentState` that tracks details like intent, history, and collected lead fields.
@@ -12,7 +30,7 @@ The system is designed as an agentic workflow using **LangGraph**, replacing tra
12
  5. **Lead Qualification**: High-intent users are routed to a multi-turn lead collection workflow. The agent selectively asks for missing fields (Name, Email, Creator Platform).
13
  6. **Tool Execution**: Once all fields are collected, the agent safely executes a simulated backend lead-capture tool.
14
 
15
- ## Running Locally
16
 
17
  ### Prerequisites
18
  - Python 3.9+
@@ -30,7 +48,7 @@ The system is designed as an agentic workflow using **LangGraph**, replacing tra
30
  ```
31
 
32
  ### Running the CLI Agent
33
- To interact with the conversational agent:
34
  ```bash
35
  python main.py
36
  ```
 
1
+ ---
2
+ title: AutoStream AI Agent
3
+ emoji: 🤖
4
+ colorFrom: blue
5
+ colorTo: purple
6
+ sdk: docker
7
+ app_port: 7860
8
+ ---
9
+
10
  # AutoStream Conversational AI Agent
11
 
12
  ## Project Overview
13
  This project is a production-quality Conversational AI Agent built for **AutoStream**, a fictional SaaS company. It handles customer inquiries, answers product questions using a Knowledge Base (RAG), and detects high-intent users to seamlessly collect lead information and execute backend lead capture functions.
14
 
15
+ ## Web Interface (Streamlit)
16
+ A highly interactive, modern web interface is included via `Streamlit`. It can be run locally or hosted directly on HuggingFace Spaces.
17
+
18
+ ### Running the Web Interface Locally
19
+ ```bash
20
+ streamlit run app.py
21
+ ```
22
+ This will open up a browser window where you can converse with the AutoStream Assistant directly.
23
+
24
  ## System Architecture
25
  The system is designed as an agentic workflow using **LangGraph**, replacing traditional linear chatbots with a stateful, branching graph architecture.
26
  1. **User Input & State Management**: User messages and conversational context are persisted in a shared `AgentState` that tracks details like intent, history, and collected lead fields.
 
30
  5. **Lead Qualification**: High-intent users are routed to a multi-turn lead collection workflow. The agent selectively asks for missing fields (Name, Email, Creator Platform).
31
  6. **Tool Execution**: Once all fields are collected, the agent safely executes a simulated backend lead-capture tool.
32
 
33
+ ## Running Locally (CLI)
34
 
35
  ### Prerequisites
36
  - Python 3.9+
 
48
  ```
49
 
50
  ### Running the CLI Agent
51
+ To interact with the conversational agent via the terminal:
52
  ```bash
53
  python main.py
54
  ```
app.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ from dotenv import load_dotenv
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
+
26
+ st.session_state.agent_state = AgentState(
27
+ conversation_history=[],
28
+ current_message="",
29
+ detected_intent=None,
30
+ retrieved_documents=[],
31
+ user_name=None,
32
+ user_email=None,
33
+ creator_platform=None,
34
+ lead_ready=False,
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.")
89
+
90
+ st.write("**Lead Data:**")
91
+ st.json({
92
+ "user_name": result_state.get("user_name"),
93
+ "user_email": result_state.get("user_email"),
94
+ "creator_platform": result_state.get("creator_platform"),
95
+ "lead_ready": result_state.get("lead_ready")
96
+ })
97
+
98
+ except Exception as e:
99
+ response = f"An error occurred: {str(e)}"
100
+ st.error(response)
101
+
102
+
103
+ st.session_state.messages.append({"role": "assistant", "content": response})
requirements.txt CHANGED
@@ -8,3 +8,4 @@ python-dotenv
8
  pydantic
9
  pytest
10
  pytest-mock
 
 
8
  pydantic
9
  pytest
10
  pytest-mock
11
+ streamlit