|
| 1 | +# Deployment |
| 2 | + |
| 3 | +CSV-AI v2 is structured to deploy three ways out of the box, with a fourth (API split) being a small future task. |
| 4 | + |
| 5 | +## 1. Streamlit Community Cloud |
| 6 | + |
| 7 | +1. Push this repo to GitHub. |
| 8 | +2. On [streamlit.io/cloud](https://streamlit.io/cloud), create a new app pointing at this repo. |
| 9 | +3. Set **Main file path** to `streamlit_app.py`. |
| 10 | +4. Under **Settings → Secrets**, paste: |
| 11 | + |
| 12 | + ```toml |
| 13 | + OPENAI_API_KEY = "sk-..." |
| 14 | + ANTHROPIC_API_KEY = "sk-ant-..." |
| 15 | + ``` |
| 16 | + |
| 17 | +5. Deploy. `requirements.txt` is picked up automatically. |
| 18 | + |
| 19 | +> Streamlit Cloud's sandbox can't reach a local Ollama instance — pick `openai` or `anthropic` as your default provider in `Settings → Advanced`. |
| 20 | +
|
| 21 | +## 2. Local development |
| 22 | + |
| 23 | +```bash |
| 24 | +git clone https://github.com/Safiullah-Rahu/CSV-AI.git |
| 25 | +cd CSV-AI |
| 26 | +python -m venv .venv && source .venv/bin/activate |
| 27 | +pip install -r requirements-dev.txt |
| 28 | +cp .env.example .env # fill in keys |
| 29 | +streamlit run streamlit_app.py |
| 30 | +``` |
| 31 | + |
| 32 | +Optional — run a local Ollama: |
| 33 | + |
| 34 | +```bash |
| 35 | +ollama serve & |
| 36 | +ollama pull llama3.1 |
| 37 | +# then in the sidebar: provider = ollama, model = llama3.1 |
| 38 | +``` |
| 39 | + |
| 40 | +## 3. Docker / Docker Compose |
| 41 | + |
| 42 | +```bash |
| 43 | +cp .env.example .env # fill in keys |
| 44 | +docker compose up --build |
| 45 | +``` |
| 46 | + |
| 47 | +Open <http://localhost:8501>. The container runs `streamlit run streamlit_app.py` on port 8501 with a healthcheck. |
| 48 | + |
| 49 | +For a bare-metal Docker run: |
| 50 | + |
| 51 | +```bash |
| 52 | +docker build -t csv-ai . |
| 53 | +docker run --rm -p 8501:8501 --env-file .env csv-ai |
| 54 | +``` |
| 55 | + |
| 56 | +## 4. Generic VPS |
| 57 | + |
| 58 | +The Dockerfile is the recommended path on any Linux VPS — drop it behind nginx with an SSL terminator. If you want to skip Docker: |
| 59 | + |
| 60 | +```bash |
| 61 | +# As a non-root user on the VPS: |
| 62 | +git clone https://github.com/Safiullah-Rahu/CSV-AI.git /opt/csv-ai |
| 63 | +cd /opt/csv-ai |
| 64 | +python3.11 -m venv .venv && source .venv/bin/activate |
| 65 | +pip install -r requirements.txt |
| 66 | +cp .env.example .env # fill in keys |
| 67 | + |
| 68 | +# Run as a systemd unit (see snippet below): |
| 69 | +sudo systemctl enable --now csv-ai.service |
| 70 | +``` |
| 71 | + |
| 72 | +`csv-ai.service`: |
| 73 | + |
| 74 | +```ini |
| 75 | +[Unit] |
| 76 | +Description=CSV-AI Streamlit app |
| 77 | +After=network.target |
| 78 | + |
| 79 | +[Service] |
| 80 | +User=csvai |
| 81 | +WorkingDirectory=/opt/csv-ai |
| 82 | +EnvironmentFile=/opt/csv-ai/.env |
| 83 | +ExecStart=/opt/csv-ai/.venv/bin/streamlit run streamlit_app.py --server.port=8501 --server.address=127.0.0.1 |
| 84 | +Restart=on-failure |
| 85 | + |
| 86 | +[Install] |
| 87 | +WantedBy=multi-user.target |
| 88 | +``` |
| 89 | + |
| 90 | +Front it with nginx: |
| 91 | + |
| 92 | +```nginx |
| 93 | +server { |
| 94 | + listen 443 ssl http2; |
| 95 | + server_name csv-ai.example.com; |
| 96 | + # SSL certs ... |
| 97 | + location / { |
| 98 | + proxy_pass http://127.0.0.1:8501; |
| 99 | + proxy_http_version 1.1; |
| 100 | + proxy_set_header Upgrade $http_upgrade; |
| 101 | + proxy_set_header Connection "upgrade"; |
| 102 | + proxy_set_header Host $host; |
| 103 | + proxy_read_timeout 300; |
| 104 | + } |
| 105 | +} |
| 106 | +``` |
| 107 | + |
| 108 | +## 5. Future: API/backend split |
| 109 | + |
| 110 | +`app/services/` has no Streamlit imports, so wrapping it in FastAPI is mostly mechanical: |
| 111 | + |
| 112 | +```python |
| 113 | +# api/main.py — future |
| 114 | +from fastapi import FastAPI |
| 115 | +from pydantic import BaseModel |
| 116 | +import pandas as pd |
| 117 | + |
| 118 | +from app.llm.factory import build_provider |
| 119 | +from app.services import ChatService |
| 120 | + |
| 121 | +api = FastAPI() |
| 122 | + |
| 123 | +class ChatReq(BaseModel): |
| 124 | + provider: str |
| 125 | + model: str |
| 126 | + question: str |
| 127 | + csv_path: str |
| 128 | + |
| 129 | +@api.post("/chat") |
| 130 | +def chat(req: ChatReq): |
| 131 | + provider = build_provider(req.provider, model=req.model) |
| 132 | + df = pd.read_csv(req.csv_path) |
| 133 | + return {"answer": ChatService(provider=provider, df=df).ask(req.question)} |
| 134 | +``` |
| 135 | + |
| 136 | +Same engine, different transport. The Streamlit app can stay, become a thin client of the API, or both can run side-by-side. |
| 137 | + |
| 138 | +## Health checks & observability |
| 139 | + |
| 140 | +- The Streamlit endpoint `/_stcore/health` returns 200 when ready (used by the Dockerfile healthcheck). |
| 141 | +- Logs go to stderr under the `csvai.*` namespace (see `app/utils/logging.py`). Set `LOG_LEVEL=DEBUG` for verbose output. |
0 commit comments