Spaces:
Sleeping
Sleeping
google-labs-jules[bot] archc0der commited on
Commit ·
c987214
1
Parent(s): 0643073
feat: Add Streamlit UI, Dockerfile, and HF Spaces config
Browse filesCo-authored-by: archc0der <119496494+archc0der@users.noreply.github.com>
Files changed (4)
- DockerfileAdded+28
- README.md+20-2
- app.pyAdded+103
- requirements.txt+1
12345678910111213141516171819202122232425262728# Use the official Python 3.10 image from DockerHubFROM python:3.10-slim
# Set the working directoryWORKDIR /app
# Copy the requirements file and install dependenciesCOPY requirements.txt .RUN pip install --no-cache-dir -r requirements.txt
# Copy the application codeCOPY . .
# Expose the default port for Streamlit and HuggingFace SpacesEXPOSE 7860
# Create a non-root user for HuggingFace Spaces (required by HF)RUN useradd -m -u 1000 userUSER user
# Define environment variablesENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH \ STREAMLIT_SERVER_PORT=7860 \ STREAMLIT_SERVER_ADDRESS=0.0.0.0
# Start the Streamlit applicationCMD ["streamlit", "run", "app.py"]123456783 unmodified lines1213141516171811 unmodified lines30313233343536# AutoStream Conversational AI Agent## Project OverviewThis 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.## System ArchitectureThe system is designed as an agentic workflow using **LangGraph**, replacing traditional linear chatbots with a stateful, branching graph architecture.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.3 unmodified lines5. **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).6. **Tool Execution**: Once all fields are collected, the agent safely executes a simulated backend lead-capture tool.## Running Locally### Prerequisites- Python 3.9+11 unmodified lines```### Running the CLI AgentTo interact with the conversational agent:```bashpython main.py```12345678910111213141516171819202122232425263 unmodified lines3031323334353611 unmodified lines48495051525354---title: AutoStream AI Agentemoji: 🤖colorFrom: bluecolorTo: purplesdk: dockerapp_port: 7860---# AutoStream Conversational AI Agent## Project OverviewThis 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.## Web Interface (Streamlit)A highly interactive, modern web interface is included via `Streamlit`. It can be run locally or hosted directly on HuggingFace Spaces.### Running the Web Interface Locally```bashstreamlit run app.py```This will open up a browser window where you can converse with the AutoStream Assistant directly.## System ArchitectureThe system is designed as an agentic workflow using **LangGraph**, replacing traditional linear chatbots with a stateful, branching graph architecture.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.3 unmodified lines5. **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).6. **Tool Execution**: Once all fields are collected, the agent safely executes a simulated backend lead-capture tool.## Running Locally (CLI)### Prerequisites- Python 3.9+11 unmodified lines```### Running the CLI AgentTo interact with the conversational agent via the terminal:```bashpython main.py```
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103import streamlit as stimport osfrom dotenv import load_dotenvfrom agent.graph import appfrom agent.state import AgentState
load_dotenv()
st.set_page_config(page_title="AutoStream AI Sales Assistant", page_icon="🤖", layout="centered")
st.markdown("""<style> .stChatFloatingInputContainer { bottom: 20px; }</style>""", unsafe_allow_html=True)
if "messages" not in st.session_state: st.session_state.messages = []
st.session_state.agent_state = AgentState( conversation_history=[], current_message="", detected_intent=None, retrieved_documents=[], user_name=None, user_email=None, creator_platform=None, lead_ready=False, response="" )
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?"})
if not os.environ.get("OPENAI_API_KEY"): st.warning("⚠️ OPENAI_API_KEY is not set. Please set it in your environment to use the agent.")
st.title("🤖 AutoStream AI Sales Assistant")st.markdown("Ask me about AutoStream features and pricing, or sign up for a plan!")
for message in st.session_state.messages: with st.chat_message(message["role"]): st.markdown(message["content"])
if prompt := st.chat_input("What would you like to know?"):
st.session_state.messages.append({"role": "user", "content": prompt}) with st.chat_message("user"): st.markdown(prompt)
st.session_state.agent_state["current_message"] = prompt
with st.chat_message("assistant"): with st.spinner("Thinking..."): try:
result_state = app.invoke(st.session_state.agent_state) st.session_state.agent_state = result_state
response = result_state["response"]
st.session_state.agent_state["conversation_history"].append({"role": "user", "content": prompt}) st.session_state.agent_state["conversation_history"].append({"role": "assistant", "content": response})
if len(st.session_state.agent_state["conversation_history"]) > 12: st.session_state.agent_state["conversation_history"] = st.session_state.agent_state["conversation_history"][-12:]
st.markdown(response)
with st.expander("Agent Reasoning & State"): st.write(f"**Detected Intent:** `{result_state.get('detected_intent', 'UNKNOWN')}`") if result_state.get("retrieved_documents") and result_state.get("detected_intent") in ["PRODUCT_QUERY", "PRICING_QUERY"]: st.write(f"**RAG Retrieval:** Found {len(result_state['retrieved_documents'])} relevant knowledge chunks.")
st.write("**Lead Data:**") st.json({ "user_name": result_state.get("user_name"), "user_email": result_state.get("user_email"), "creator_platform": result_state.get("creator_platform"), "lead_ready": result_state.get("lead_ready") })
except Exception as e: response = f"An error occurred: {str(e)}" st.error(response)
st.session_state.messages.append({"role": "assistant", "content": response})7 unmodified lines89107 unmodified linespydanticpytestpytest-mock7 unmodified lines8910117 unmodified linespydanticpytestpytest-mockstreamlit
DockerfileAdded+28
README.md+20-2
app.pyAdded+103
requirements.txt+1