Entz commited on
Commit
4885d74
·
verified ·
1 Parent(s): e67b323

Upload 2 files

Browse files
Files changed (2) hide show
  1. Dockerfile +14 -17
  2. frontend.py +4 -4
Dockerfile CHANGED
@@ -1,26 +1,23 @@
1
- # Dockerfile
2
  FROM python:3.10-slim
3
 
 
4
  WORKDIR /app
5
- # tells the system to treat /app as the "home" directory, so Streamlit will create /app/.streamlit instead of /.streamlit.
6
- # /app is already writable as root, so no permission issues.
7
- ENV HOME=/app
8
 
9
- # (Optional) system deps if you need them; safe to remove if not needed
10
- RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/*
 
11
 
12
- # Install Python deps
13
- COPY requirements.txt /app/
14
- RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt
15
 
16
- # Copy code
17
- COPY . /app
18
 
19
- # Do NOT set STREAMLIT_SERVER_PORT here.
20
- # Spaces will inject $PORT at runtime.
21
 
 
 
22
 
23
- # Start Streamlit on the port Spaces provides, and bind to 0.0.0.0
24
- # CMD ["bash", "-lc", "streamlit run /app/frontend.py --server.port $PORT --server.address 0.0.0.0"]
25
- # CMD ["sh", "-c", "streamlit run /app/frontend.py --server.port $PORT --server.address 0.0.0.0"]
26
- CMD ["streamlit", "run", "/app/frontend.py", "--server.port", "8501", "--server.address", "0.0.0.0"]
 
 
1
  FROM python:3.10-slim
2
 
3
+ # Set working directory in the container
4
  WORKDIR /app
 
 
 
5
 
6
+ # Copy requirements and install dependencies
7
+ COPY requirements.txt .
8
+ RUN pip install --no-cache-dir -r requirements.txt
9
 
10
+ # Create non-root user for HF Spaces and make /app writable
11
+ RUN adduser --disabled-password --gecos '' --uid 1000 --gid 1000 user && chown -R user:user /app
 
12
 
13
+ # Copy application files
14
+ COPY . .
15
 
16
+ # Expose Streamlit port
17
+ EXPOSE 8501
18
 
19
+ # Health check for Streamlit
20
+ HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health || exit 1
21
 
22
+ # Run Streamlit as the non-root user
23
+ CMD ["streamlit", "run", "frontend.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
 
frontend.py CHANGED
@@ -59,7 +59,8 @@ with st.sidebar:
59
 
60
  # Show available tools
61
  st.markdown("### 🛠️ Available Tools")
62
- for tool in st.session_state.available_tools:
 
63
  st.markdown(f"• `{tool}`")
64
  else:
65
  st.info("⏳ Agent Initializing...")
@@ -200,10 +201,9 @@ if prompt := st.chat_input("Type your message here..."):
200
  message_placeholder.markdown(response)
201
  st.session_state.messages.append({"role": "assistant", "content": response})
202
 
203
- # Initialize agent on first load
204
- # Optional: manual connect so page renders fast
205
  if not st.session_state.agent_initialized:
206
- if st.sidebar.button("🔌 Connect agent"):
207
  asyncio.run(initialize_agent())
208
 
209
  # Footer
 
59
 
60
  # Show available tools
61
  st.markdown("### 🛠️ Available Tools")
62
+ available_tools = st.session_state.get("available_tools", [])
63
+ for tool in available_tools:
64
  st.markdown(f"• `{tool}`")
65
  else:
66
  st.info("⏳ Agent Initializing...")
 
201
  message_placeholder.markdown(response)
202
  st.session_state.messages.append({"role": "assistant", "content": response})
203
 
204
+ # Auto-initialize agent on first load
 
205
  if not st.session_state.agent_initialized:
206
+ with st.spinner("🔧 Initializing agent..."):
207
  asyncio.run(initialize_agent())
208
 
209
  # Footer