teofizzy commited on
Commit
2d548c5
·
1 Parent(s): c20e590

pdate src/app.py to prepend the sqlite:/// prefix to the database path.

Browse files
Files changed (2) hide show
  1. Dockerfile +13 -9
  2. src/app.py +16 -12
Dockerfile CHANGED
@@ -1,35 +1,39 @@
1
- # Use the official Python minimal image (Best for CPU Basic tier)
2
  FROM python:3.10-slim
3
 
4
  # 1. Install system tools
5
- # Added 'zstd' which is now REQUIRED by the Ollama installer
 
6
  RUN apt-get update && apt-get install -y \
7
  curl \
8
  git \
 
9
  build-essential \
10
  zstd \
11
- && rm -rf /var/lib/apt/lists/*
 
12
 
13
- # 2. Install Ollama (Must be done as ROOT)
14
  RUN curl -fsSL https://ollama.com/install.sh | sh
15
 
16
- # 3. Setup User (Hugging Face Requirement)
17
  RUN useradd -m -u 1000 user
18
  USER user
19
  ENV HOME=/home/user \
20
  PATH=/home/user/.local/bin:$PATH
21
 
22
- # 4. Set Working Directory
23
  WORKDIR $HOME/app
24
 
25
- # 5. Install Python Requirements
26
  COPY --chown=user requirements.txt $HOME/app/
27
  RUN pip install --no-cache-dir -r requirements.txt
28
 
29
- # 6. Copy Application Code
30
  COPY --chown=user . $HOME/app
31
 
32
- # 7. STARTUP COMMAND
 
33
  CMD git clone https://huggingface.co/datasets/teofizzy/mshauri-data data_download && \
34
  mv data_download/mshauri_fedha_v6.db . && \
35
  mv data_download/mshauri_fedha_chroma_db . && \
 
1
+ # Use the official Python minimal image
2
  FROM python:3.10-slim
3
 
4
  # 1. Install system tools
5
+ # CRITICAL: Added 'git-lfs' so we download the REAL database files, not pointers.
6
+ # Added 'zstd' for Ollama.
7
  RUN apt-get update && apt-get install -y \
8
  curl \
9
  git \
10
+ git-lfs \
11
  build-essential \
12
  zstd \
13
+ && rm -rf /var/lib/apt/lists/* \
14
+ && git lfs install # <--- Initialize LFS
15
 
16
+ # 2. Install Ollama (Root)
17
  RUN curl -fsSL https://ollama.com/install.sh | sh
18
 
19
+ # 3. Setup User
20
  RUN useradd -m -u 1000 user
21
  USER user
22
  ENV HOME=/home/user \
23
  PATH=/home/user/.local/bin:$PATH
24
 
25
+ # 4. Workdir
26
  WORKDIR $HOME/app
27
 
28
+ # 5. Requirements
29
  COPY --chown=user requirements.txt $HOME/app/
30
  RUN pip install --no-cache-dir -r requirements.txt
31
 
32
+ # 6. Copy Code
33
  COPY --chown=user . $HOME/app
34
 
35
+ # 7. Startup
36
+ # We clone the dataset. git-lfs ensures we get the big files.
37
  CMD git clone https://huggingface.co/datasets/teofizzy/mshauri-data data_download && \
38
  mv data_download/mshauri_fedha_v6.db . && \
39
  mv data_download/mshauri_fedha_chroma_db . && \
src/app.py CHANGED
@@ -6,13 +6,11 @@ import streamlit as st
6
  import os
7
 
8
  # --- PATH SETUP ---
9
- # Since we run this from the root via Docker, we need to help python find 'mshauri_demo'
10
- # We add 'src/load' to the system path.
11
  current_dir = os.getcwd() # Should be /home/user/app in Docker
12
  load_dir = os.path.join(current_dir, "src", "load")
13
  sys.path.append(load_dir)
14
 
15
- # Import agent creator
16
  try:
17
  from mshauri_demo import create_mshauri_agent
18
  except ImportError as e:
@@ -30,13 +28,16 @@ if "messages" not in st.session_state:
30
 
31
  if "agent" not in st.session_state:
32
  with st.spinner("Initializing Mshauri Brain (Loading Models & Data)..."):
33
- # The Dockerfile downloads the data to the root folder (/home/user/app)
34
- sql_path = os.path.join(current_dir, "mshauri_fedha_v6.db")
 
 
35
  vector_path = os.path.join(current_dir, "mshauri_fedha_chroma_db")
36
 
37
  # Check if data exists (Debugging for Space deployment)
38
- if not os.path.exists(sql_path):
39
- st.error(f"❌ Database not found at {sql_path}. Did the clone fail?")
 
40
  st.stop()
41
 
42
  try:
@@ -44,7 +45,7 @@ if "agent" not in st.session_state:
44
  st.session_state.agent = create_mshauri_agent(
45
  sql_db_path=sql_path,
46
  vector_db_path=vector_path,
47
- llm_model="qwen2.5:7b" # Force 2.5 7 B which can use CPU basic
48
  )
49
  st.success("System Ready!")
50
  except Exception as e:
@@ -64,9 +65,12 @@ if prompt := st.chat_input("Ask about inflation, exchange rates, or economic tre
64
  with st.chat_message("assistant"):
65
  with st.spinner("Analyzing..."):
66
  try:
67
- response = st.session_state.agent.invoke({"input": prompt})
68
- output_text = response.get("output", "Error generating response.")
69
- st.markdown(output_text)
70
- st.session_state.messages.append({"role": "assistant", "content": output_text})
 
 
 
71
  except Exception as e:
72
  st.error(f"An error occurred: {e}")
 
6
  import os
7
 
8
  # --- PATH SETUP ---
 
 
9
  current_dir = os.getcwd() # Should be /home/user/app in Docker
10
  load_dir = os.path.join(current_dir, "src", "load")
11
  sys.path.append(load_dir)
12
 
13
+ # Import your agent creator
14
  try:
15
  from mshauri_demo import create_mshauri_agent
16
  except ImportError as e:
 
28
 
29
  if "agent" not in st.session_state:
30
  with st.spinner("Initializing Mshauri Brain (Loading Models & Data)..."):
31
+ # --- THE FIX IS HERE ---
32
+ # SQLAlchemy requires a URI starting with sqlite:///
33
+ # We use 4 slashes (sqlite:////) because it is an absolute path on Linux
34
+ sql_path = f"sqlite:///{os.path.join(current_dir, 'mshauri_fedha_v6.db')}"
35
  vector_path = os.path.join(current_dir, "mshauri_fedha_chroma_db")
36
 
37
  # Check if data exists (Debugging for Space deployment)
38
+ real_db_path = os.path.join(current_dir, "mshauri_fedha_v6.db")
39
+ if not os.path.exists(real_db_path):
40
+ st.error(f"❌ Database not found at {real_db_path}. Did the clone fail?")
41
  st.stop()
42
 
43
  try:
 
45
  st.session_state.agent = create_mshauri_agent(
46
  sql_db_path=sql_path,
47
  vector_db_path=vector_path,
48
+ llm_model="qwen2.5:7b"
49
  )
50
  st.success("System Ready!")
51
  except Exception as e:
 
65
  with st.chat_message("assistant"):
66
  with st.spinner("Analyzing..."):
67
  try:
68
+ if st.session_state.agent:
69
+ response = st.session_state.agent.invoke({"input": prompt})
70
+ output_text = response.get("output", "Error generating response.")
71
+ st.markdown(output_text)
72
+ st.session_state.messages.append({"role": "assistant", "content": output_text})
73
+ else:
74
+ st.error("Agent failed to initialize. Please refresh the page.")
75
  except Exception as e:
76
  st.error(f"An error occurred: {e}")