Merge branch 'main' of https://huggingface.co/spaces/dpv007/KeyStone
Browse files- Dockerfile +39 -0
- README.md +117 -0
Dockerfile
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM node:20 AS frontend
|
| 2 |
+
|
| 3 |
+
WORKDIR /frontend
|
| 4 |
+
|
| 5 |
+
COPY mobile/package.json ./
|
| 6 |
+
RUN npm install
|
| 7 |
+
|
| 8 |
+
COPY mobile/ .
|
| 9 |
+
RUN npx expo export --platform web
|
| 10 |
+
|
| 11 |
+
FROM python:3.11-slim
|
| 12 |
+
|
| 13 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 14 |
+
libmagic1 \
|
| 15 |
+
libmagic-dev \
|
| 16 |
+
libjpeg-dev \
|
| 17 |
+
zlib1g-dev \
|
| 18 |
+
libwebp-dev \
|
| 19 |
+
curl \
|
| 20 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 21 |
+
|
| 22 |
+
WORKDIR /app
|
| 23 |
+
|
| 24 |
+
COPY backend/requirements.txt ./requirements.txt
|
| 25 |
+
RUN pip install --no-cache-dir --upgrade pip && \
|
| 26 |
+
pip install --no-cache-dir -r requirements.txt
|
| 27 |
+
|
| 28 |
+
COPY backend/ .
|
| 29 |
+
COPY --from=frontend /frontend/dist ./web
|
| 30 |
+
|
| 31 |
+
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
|
| 32 |
+
USER appuser
|
| 33 |
+
|
| 34 |
+
EXPOSE 7860
|
| 35 |
+
|
| 36 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
|
| 37 |
+
CMD curl -f http://localhost:7860/health || exit 1
|
| 38 |
+
|
| 39 |
+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "2"]
|
README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: KeyStone Photo Cloud
|
| 3 |
+
emoji: π·
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: indigo
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
+
pinned: false
|
| 9 |
+
license: mit
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# KeyStone π· β Private Photo Cloud
|
| 13 |
+
|
| 14 |
+
> Your photos. Your cloud. Zero dependencies on Google or Apple.
|
| 15 |
+
|
| 16 |
+
KeyStone is a self-hosted Google Photos alternative with automatic mobile backup, deduplication, and AI-ready architecture.
|
| 17 |
+
|
| 18 |
+
## Architecture
|
| 19 |
+
|
| 20 |
+
```
|
| 21 |
+
Expo App (iOS + Android + Web)
|
| 22 |
+
β
|
| 23 |
+
Supabase Auth (JWT)
|
| 24 |
+
β
|
| 25 |
+
FastAPI Backend ββββββΊ Hugging Face Bucket (storage)
|
| 26 |
+
β
|
| 27 |
+
Supabase PostgreSQL
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
## Live Deployment
|
| 31 |
+
|
| 32 |
+
| Service | URL |
|
| 33 |
+
|---|---|
|
| 34 |
+
| π Backend API | https://dpv007-keystone.hf.space |
|
| 35 |
+
| π API Docs | https://dpv007-keystone.hf.space/docs |
|
| 36 |
+
|
| 37 |
+
## Quick Start
|
| 38 |
+
|
| 39 |
+
### Backend (local dev)
|
| 40 |
+
|
| 41 |
+
```bash
|
| 42 |
+
cd backend
|
| 43 |
+
cp .env.example .env # fill in your credentials
|
| 44 |
+
docker compose up # starts FastAPI + PostgreSQL
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
### Run database migrations
|
| 48 |
+
|
| 49 |
+
```bash
|
| 50 |
+
cd backend
|
| 51 |
+
alembic upgrade head
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
### Mobile App
|
| 55 |
+
|
| 56 |
+
```bash
|
| 57 |
+
cd mobile
|
| 58 |
+
cp .env.example .env # fill in Supabase keys
|
| 59 |
+
npm install
|
| 60 |
+
npm start # Expo dev server (iOS/Android/Web)
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
Open in browser: http://localhost:8081 (web), or scan QR in Expo Go.
|
| 64 |
+
|
| 65 |
+
## Environment Variables
|
| 66 |
+
|
| 67 |
+
### Backend (`backend/.env`)
|
| 68 |
+
|
| 69 |
+
| Variable | Description |
|
| 70 |
+
|---|---|
|
| 71 |
+
| `DATABASE_URL` | Supabase PostgreSQL connection string |
|
| 72 |
+
| `SUPABASE_URL` | Your Supabase project URL |
|
| 73 |
+
| `SUPABASE_JWT_SECRET` | JWT secret from Supabase Dashboard β Settings β API |
|
| 74 |
+
| `HF_TOKEN` | Hugging Face token with write access |
|
| 75 |
+
| `HF_DATASET_REPO` | HF Dataset repo for photo storage (e.g. `user/keystone-photos`) |
|
| 76 |
+
|
| 77 |
+
### Mobile (`mobile/.env`)
|
| 78 |
+
|
| 79 |
+
| Variable | Description |
|
| 80 |
+
|---|---|
|
| 81 |
+
| `EXPO_PUBLIC_API_URL` | Backend URL (defaults to HF Space URL) |
|
| 82 |
+
| `EXPO_PUBLIC_SUPABASE_URL` | Your Supabase project URL |
|
| 83 |
+
| `EXPO_PUBLIC_SUPABASE_ANON_KEY` | Supabase anon key |
|
| 84 |
+
|
| 85 |
+
## Features
|
| 86 |
+
|
| 87 |
+
- β
Email/password authentication via Supabase
|
| 88 |
+
- β
JWT verification on every API request
|
| 89 |
+
- β
SHA256 deduplication (never upload the same photo twice)
|
| 90 |
+
- β
Background sync (iOS + Android) with Wi-Fi-only option
|
| 91 |
+
- β
Battery-aware syncing
|
| 92 |
+
- β
Thumbnail generation (Pillow)
|
| 93 |
+
- β
Infinite-scroll gallery
|
| 94 |
+
- β
Albums with photo management
|
| 95 |
+
- β
Photo search (filename + AI tags)
|
| 96 |
+
- β
Favorites
|
| 97 |
+
- β
Soft delete
|
| 98 |
+
- β
Works on iOS, Android, and Web (same codebase)
|
| 99 |
+
- π CLIP semantic search
|
| 100 |
+
- π Face clustering
|
| 101 |
+
- π OCR text extraction
|
| 102 |
+
- π Auto albums
|
| 103 |
+
|
| 104 |
+
## Deployment to Hugging Face Spaces
|
| 105 |
+
|
| 106 |
+
The backend is a Docker Space. Push this repo and set the following secrets in the Space settings:
|
| 107 |
+
|
| 108 |
+
- `DATABASE_URL`
|
| 109 |
+
- `SUPABASE_URL`
|
| 110 |
+
- `SUPABASE_JWT_SECRET`
|
| 111 |
+
- `SUPABASE_SERVICE_ROLE_KEY`
|
| 112 |
+
- `HF_TOKEN`
|
| 113 |
+
- `HF_DATASET_REPO`
|
| 114 |
+
|
| 115 |
+
## License
|
| 116 |
+
|
| 117 |
+
MIT
|