KnowingFly/depression-detection-api
0
1# Deployment Guide for Depression Detection API2 3## ๐ Option 1: Hugging Face Spaces (Recommended - FREE)4 5### Step 1: Create a Hugging Face Account61. Go to [huggingface.co](https://huggingface.co)72. Click "Sign Up" and create a free account83. Verify your email9 10### Step 2: Create a New Space111. Go to [huggingface.co/new-space](https://huggingface.co/new-space)122. Fill in the details:13 - **Space name**: `depression-detection-api`14 - **License**: Choose appropriate license (e.g., MIT)15 - **SDK**: Select **Docker**16 - **Hardware**: Keep **CPU basic - Free**173. Click "Create Space"18 19### Step 3: Upload Your Files20You can either:21 22**Option A: Using Git (Recommended)**23```bash24# Clone your new space25git clone https://huggingface.co/spaces/YOUR_USERNAME/depression-detection-api26 27# Copy your files to the cloned directory28# Then push:29cd depression-detection-api30git add .31git commit -m "Initial deployment"32git push33```34 35**Option B: Manual Upload**361. Go to your Space's "Files" tab372. Upload these files:38 - `main.py`39 - `predictor.py`40 - `face_detector.py`41 - `schemas.py`42 - `requirements.txt`43 - `Dockerfile`44 - `model.h5`45 46### Step 4: Wait for Build47- Hugging Face will automatically build and deploy your app48- This may take 5-10 minutes for the first build49- Your API will be available at: `https://YOUR_USERNAME-depression-detection-api.hf.space`50 51### Step 5: Test Your API52```bash53# Health check54curl https://YOUR_USERNAME-depression-detection-api.hf.space/health55 56# Prediction (replace with your image)57curl -X POST "https://YOUR_USERNAME-depression-detection-api.hf.space/predict" \58 -F "file=@test_image.jpg"59```60 61---62 63## ๐ง Option 2: Render (Alternative - FREE)64 65### Step 1: Push to GitHub661. Create a new GitHub repository672. Push your code (including `render.yaml`)68 69### Step 2: Deploy on Render701. Go to [render.com](https://render.com) and sign up712. Click "New" โ "Web Service"723. Connect your GitHub repository734. Render will auto-detect `render.yaml`745. Click "Create Web Service"75 76### Important Notes for Render:77- โ ๏ธ Free tier spins down after 15 minutes of inactivity78- โ ๏ธ First request after spin-down takes 30-60 seconds (cold start)79- โ ๏ธ May have issues with large model files80 81---82 83## ๐ฑ Using the API in Your Mobile App84 85### API Endpoints86 87| Endpoint | Method | Description |88|----------|--------|-------------|89| `/` | GET | API info |90| `/health` | GET | Health check |91| `/predict` | POST | Predict depression from image |92| `/docs` | GET | Swagger UI documentation |93 94### Example API Call (Android/Kotlin)95```kotlin96// Using Retrofit97interface DepressionApi {98 @Multipart99 @POST("predict")100 suspend fun predict(101 @Part file: MultipartBody.Part,102 @Query("threshold") threshold: Float = 0.5f103 ): PredictionResponse104}105 106data class PredictionResponse(107 val prediction: String, // "depression" or "neutral"108 val confidence: Float // 0.0 to 1.0109)110```111 112### Example API Call (React Native / JavaScript)113```javascript114const formData = new FormData();115formData.append('file', {116 uri: imageUri,117 type: 'image/jpeg',118 name: 'photo.jpg',119});120 121const response = await fetch('https://YOUR-API-URL/predict', {122 method: 'POST',123 body: formData,124 headers: {125 'Content-Type': 'multipart/form-data',126 },127});128 129const result = await response.json();130console.log(result.prediction, result.confidence);131```132 133---134 135## ๐ Your API URL136 137After deployment, your API will be available at:138- **Hugging Face**: `https://YOUR_USERNAME-depression-detection-api.hf.space`139- **Render**: `https://depression-detection-api.onrender.com`140 141Replace the placeholder URL in your mobile app with your actual deployed URL.142 