Data_eng_designer / DEPLOY_TO_IOS.md
focustiki's picture
Upload 12 files
9bcadf3 verified
|
Raw
History Blame Contribute Delete
4.22 kB
# πŸ“± Deploy DE Assistant to iOS β€” Step by Step ($0)
## What you get
A PWA that installs on your iPhone home screen like a native app, with:
- Full chat interface with markdown rendering
- **Voice input** (speak your question)
- **Voice output** (AI reads the answer aloud)
- Works offline for the UI shell
- Connected to Groq's free-tier LLM (sub-500ms responses)
---
## Option A: Hugging Face Spaces (Recommended β€” 5 minutes)
HF Spaces gives you a free public HTTPS URL β€” required for the PWA to work on iOS.
### Step 1 β€” Get a free Groq API key
1. Go to [console.groq.com](https://console.groq.com)
2. Sign up β†’ API Keys β†’ Create API Key
3. Copy the key (starts with `gsk_`)
### Step 2 β€” Create a Hugging Face Space
1. Go to [huggingface.co/new-space](https://huggingface.co/new-space)
2. Space name: `de-knowledge-assistant`
3. SDK: **Docker** (not Gradio/Streamlit)
4. Visibility: Public
### Step 3 β€” Create a Dockerfile in the Space
```dockerfile
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 7860
CMD ["python", "app.py"]
```
### Step 4 β€” Upload all files
Push these files to the Space repo (via git or HF UI):
```
app.py
rag.py
agent.py
requirements.txt
static/index.html
static/manifest.json
static/sw.js
knowledge/data_engineering_patterns.pdf
Dockerfile
```
```bash
# Using git
git clone https://huggingface.co/spaces/your-username/de-knowledge-assistant
cd de-knowledge-assistant
# copy all de-assistant/ files here
git add .
git commit -m "Initial deployment"
git push
```
### Step 5 β€” Set the Groq API key as a secret
In HF Spaces β†’ Settings β†’ Repository Secrets:
- Name: `GROQ_API_KEY`
- Value: your `gsk_...` key
### Step 6 β€” Add to iPhone home screen
1. Wait for the Space to build (~3 min)
2. Open your Space URL in **Safari on iPhone**:
`https://your-username-de-knowledge-assistant.hf.space`
3. Tap the **Share** button (box with arrow) β†’ **Add to Home Screen**
4. Name it "DE Assistant" β†’ **Add**
Done! It now appears on your home screen like a native app. πŸŽ‰
---
## Option B: Local + Ngrok (instant, for testing)
Run locally and expose with a free ngrok tunnel so Safari can reach it:
```bash
# Terminal 1 β€” start the app
./setup.sh
# Terminal 2 β€” expose publicly
brew install ngrok # or download at ngrok.com
ngrok http 8000
```
Copy the `https://xxxx.ngrok.io` URL β†’ open in iPhone Safari β†’ Add to Home Screen.
---
## Enabling Voice on iOS
Voice requires HTTPS (which HF Spaces provides). After installing the PWA:
1. Open the app from your home screen
2. Tap the **🎀 microphone button**
3. iOS will ask for microphone permission β†’ **Allow**
4. Speak your question β€” the AI will reply and read the answer aloud
> **Tip**: The voice assistant also reads back the AI's answer using the device's
> built-in text-to-speech (no extra API needed).
---
## Architecture Overview
```
iPhone (Safari PWA)
β”‚
β”‚ HTTPS / SSE streaming
β–Ό
Hugging Face Spaces (free)
β”‚ FastAPI app.py
β”‚ β”œβ”€ /api/chat β†’ agent.py (streaming)
β”‚ └─ /api/search β†’ rag.py (vector search)
β”‚
β”œβ”€ RAG pipeline
β”‚ β”œβ”€ PDF β†’ PyPDF2 β†’ 800-char chunks
β”‚ β”œβ”€ sentence-transformers/all-MiniLM-L6-v2 (free, CPU)
β”‚ └─ ChromaDB in-memory (MMR retrieval)
β”‚
└─ Groq API (free tier)
└─ llama-3.1-8b-instant (< 500ms latency)
```
---
## Connecting to Databricks (optional upgrade)
Once you have a Databricks workspace:
1. Run `databricks/agent_notebook.py` to register the MLflow model
2. Create a Model Serving endpoint (free on Databricks trial)
3. Add `DATABRICKS_ENDPOINT_URL` and `DATABRICKS_TOKEN` to HF Spaces secrets
4. The agent automatically routes to Databricks when those vars are set
---
## Free Tier Limits (as of 2024)
| Service | Free Limit |
|---------|------------|
| Groq API | 14,400 requests/day, 30 req/min |
| HF Spaces | 2 vCPU, 16 GB RAM, always-on |
| ChromaDB | Unlimited (in-memory) |
| sentence-transformers | Unlimited (local) |
The embedding model (~90 MB) is downloaded on first start and cached in HF Spaces.