amirulhazym commited on
Commit
71164e1
·
1 Parent(s): 7e0c6a8

refactor(deploy)!: Convert to Docker deployment for full environment control

Browse files
Files changed (4) hide show
  1. Dockerfile +31 -0
  2. README.md +2 -3
  3. launcher.py +0 -58
  4. setup.sh +23 -0
Dockerfile ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use the official Python 3.10 image as our base
2
+ FROM python:3.10-slim
3
+
4
+ # Set the working directory inside the container
5
+ WORKDIR /code
6
+
7
+ # Install system-level dependencies required by our app and Git LFS
8
+ RUN apt-get update && apt-get install -y --no-install-recommends \
9
+ git \
10
+ git-lfs \
11
+ && git lfs install \
12
+ && rm -rf /var/lib/apt/lists/*
13
+
14
+ # Copy the requirements file first to leverage Docker cache
15
+ COPY requirements.txt requirements.txt
16
+
17
+ # Install Python dependencies
18
+ RUN pip install --no-cache-dir --upgrade pip
19
+ RUN pip install --no-cache-dir -r requirements.txt
20
+
21
+ # Copy the rest of the application code into the container
22
+ COPY . .
23
+
24
+ # Make our startup script executable
25
+ RUN chmod +x ./setup.sh
26
+
27
+ # Expose the port the Streamlit app will run on
28
+ EXPOSE 7860
29
+
30
+ # The command that will be run when the container starts
31
+ CMD ["bash", "./setup.sh"]
README.md CHANGED
@@ -3,9 +3,8 @@ title: AuraCart AI Assistant
3
  emoji: 🛒
4
  colorFrom: blue
5
  colorTo: green
6
- sdk: streamlit
7
- app_file: launcher.py
8
- python_version: "3.10"
9
  pinned: false
10
  ---
11
 
 
3
  emoji: 🛒
4
  colorFrom: blue
5
  colorTo: green
6
+ sdk: docker
7
+ python_version: 3.10
 
8
  pinned: false
9
  ---
10
 
launcher.py DELETED
@@ -1,58 +0,0 @@
1
- # Full, Final, and Corrected Code for: launcher.py
2
-
3
- import streamlit as st
4
- import subprocess
5
- import time
6
- import os
7
-
8
- # --- Use Streamlit's session state to ensure this runs only ONCE ---
9
- if 'backend_process' not in st.session_state:
10
- print("--- LAUNCHER: First run. Starting backend server... ---")
11
-
12
- # We construct the command to run uvicorn
13
- backend_command = [
14
- "uvicorn",
15
- "v2_multilingual_api.backend.main:app",
16
- "--host", "0.0.0.0",
17
- "--port", "8000"
18
- ]
19
-
20
- # Open log files for the backend's output and errors
21
- backend_log = open("backend.log", "w")
22
-
23
- # Start the backend process and store it in the session state
24
- st.session_state.backend_process = subprocess.Popen(
25
- backend_command, stdout=backend_log, stderr=backend_log
26
- )
27
-
28
- print(f"--- LAUNCHER: Backend process started with PID: {st.session_state.backend_process.pid} ---")
29
- print("--- LAUNCHER: Waiting 20 seconds for backend to initialize models... ---")
30
- time.sleep(20)
31
-
32
- # --- Health Check for the Backend ---
33
- # Check if the process crashed during startup
34
- if st.session_state.backend_process.poll() is not None:
35
- print("--- LAUNCHER: !!! BACKEND FAILED TO START ON INITIALIZATION !!! ---")
36
- backend_log.close()
37
- with open("backend.log", "r") as f:
38
- print(f.read())
39
- st.error("The backend server failed to start. Please check the logs.")
40
- # We use st.stop() to halt the app if the backend fails
41
- st.stop()
42
- else:
43
- print("--- LAUNCHER: Backend health check passed. Process is running. ---")
44
-
45
- # --- Step 3: Launch the Streamlit Frontend ---
46
- # This part of the code will run every time, but the backend is already running.
47
- # The command is to run the *actual* frontend app file.
48
-
49
- print("--- LAUNCHER: Handing off to the main Streamlit frontend application. ---")
50
-
51
- # We use os.system for simplicity to run the final command
52
- frontend_command = (
53
- "streamlit run v2_multilingual_api/frontend/app.py "
54
- "--server.port 7860 "
55
- "--server.address 0.0.0.0"
56
- )
57
-
58
- os.system(frontend_command)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
setup.sh ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # This script MUST be executable: chmod +x setup.sh
3
+
4
+ # Exit immediately if a command exits with a non-zero status.
5
+ set -e
6
+
7
+ echo "--- [setup.sh] Starting backend server... ---"
8
+ uvicorn v2_multilingual_api.backend.main:app --host 0.0.0.0 --port 8000 &
9
+
10
+ echo "--- [setup.sh] Waiting 20 seconds for backend to initialize models... ---"
11
+ sleep 20
12
+
13
+ echo "--- [setup.sh] Performing health check on the backend... ---"
14
+ # Use curl to check if the backend's root endpoint is responding
15
+ if curl --fail http://127.0.0.1:8000; then
16
+ echo "--- [setup.sh] Backend health check PASSED. Process is running. ---"
17
+ else
18
+ echo "--- [setup.sh] !!! BACKEND FAILED TO START OR IS UNRESPONSIVE !!! ---"
19
+ exit 1
20
+ fi
21
+
22
+ echo "--- [setup.sh] Starting frontend server... ---"
23
+ streamlit run v2_multilingual_api/frontend/app.py --server.port 7860 --server.address 0.0.0.0