Spaces:
Running
Running
pdate src/app.py to prepend the sqlite:/// prefix to the database path.
Browse files- Dockerfile +13 -9
- src/app.py +16 -12
Dockerfile
CHANGED
|
@@ -1,35 +1,39 @@
|
|
| 1 |
-
# Use the official Python minimal image
|
| 2 |
FROM python:3.10-slim
|
| 3 |
|
| 4 |
# 1. Install system tools
|
| 5 |
-
# Added '
|
|
|
|
| 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 (
|
| 14 |
RUN curl -fsSL https://ollama.com/install.sh | sh
|
| 15 |
|
| 16 |
-
# 3. Setup User
|
| 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.
|
| 23 |
WORKDIR $HOME/app
|
| 24 |
|
| 25 |
-
# 5.
|
| 26 |
COPY --chown=user requirements.txt $HOME/app/
|
| 27 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 28 |
|
| 29 |
-
# 6. Copy
|
| 30 |
COPY --chown=user . $HOME/app
|
| 31 |
|
| 32 |
-
# 7.
|
|
|
|
| 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 |
-
#
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
vector_path = os.path.join(current_dir, "mshauri_fedha_chroma_db")
|
| 36 |
|
| 37 |
# Check if data exists (Debugging for Space deployment)
|
| 38 |
-
|
| 39 |
-
|
|
|
|
| 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"
|
| 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 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
| 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}")
|