Spaces:
Sleeping
Sleeping
|
Download README_DEPLOY.md from KnowingFly/depression-detection-api: direct link, hf CLI and curl.
- Browser
- Download file 3.7 kB
-
https://huggingface.co/spaces/KnowingFly/depression-detection-api/resolve/main/README_DEPLOY.md
- Command line
-
hf download hf://spaces/KnowingFly/depression-detection-api/README_DEPLOY.md
-
curl -L -o README_DEPLOY.md https://huggingface.co/spaces/KnowingFly/depression-detection-api/resolve/main/README_DEPLOY.md
3.7 kB
| # Deployment Guide for Depression Detection API | |
| ## 🚀 Option 1: Hugging Face Spaces (Recommended - FREE) | |
| ### Step 1: Create a Hugging Face Account | |
| 1. Go to [huggingface.co](https://huggingface.co) | |
| 2. Click "Sign Up" and create a free account | |
| 3. Verify your email | |
| ### Step 2: Create a New Space | |
| 1. Go to [huggingface.co/new-space](https://huggingface.co/new-space) | |
| 2. Fill in the details: | |
| - **Space name**: `depression-detection-api` | |
| - **License**: Choose appropriate license (e.g., MIT) | |
| - **SDK**: Select **Docker** | |
| - **Hardware**: Keep **CPU basic - Free** | |
| 3. Click "Create Space" | |
| ### Step 3: Upload Your Files | |
| You can either: | |
| **Option A: Using Git (Recommended)** | |
| ```bash | |
| # Clone your new space | |
| git clone https://huggingface.co/spaces/YOUR_USERNAME/depression-detection-api | |
| # Copy your files to the cloned directory | |
| # Then push: | |
| cd depression-detection-api | |
| git add . | |
| git commit -m "Initial deployment" | |
| git push | |
| ``` | |
| **Option B: Manual Upload** | |
| 1. Go to your Space's "Files" tab | |
| 2. Upload these files: | |
| - `main.py` | |
| - `predictor.py` | |
| - `face_detector.py` | |
| - `schemas.py` | |
| - `requirements.txt` | |
| - `Dockerfile` | |
| - `model.h5` | |
| ### Step 4: Wait for Build | |
| - Hugging Face will automatically build and deploy your app | |
| - This may take 5-10 minutes for the first build | |
| - Your API will be available at: `https://YOUR_USERNAME-depression-detection-api.hf.space` | |
| ### Step 5: Test Your API | |
| ```bash | |
| # Health check | |
| curl https://YOUR_USERNAME-depression-detection-api.hf.space/health | |
| # Prediction (replace with your image) | |
| curl -X POST "https://YOUR_USERNAME-depression-detection-api.hf.space/predict" \ | |
| -F "file=@test_image.jpg" | |
| ``` | |
| --- | |
| ## 🔧 Option 2: Render (Alternative - FREE) | |
| ### Step 1: Push to GitHub | |
| 1. Create a new GitHub repository | |
| 2. Push your code (including `render.yaml`) | |
| ### Step 2: Deploy on Render | |
| 1. Go to [render.com](https://render.com) and sign up | |
| 2. Click "New" → "Web Service" | |
| 3. Connect your GitHub repository | |
| 4. Render will auto-detect `render.yaml` | |
| 5. Click "Create Web Service" | |
| ### Important Notes for Render: | |
| - ⚠️ Free tier spins down after 15 minutes of inactivity | |
| - ⚠️ First request after spin-down takes 30-60 seconds (cold start) | |
| - ⚠️ May have issues with large model files | |
| --- | |
| ## 📱 Using the API in Your Mobile App | |
| ### API Endpoints | |
| | Endpoint | Method | Description | | |
| |----------|--------|-------------| | |
| | `/` | GET | API info | | |
| | `/health` | GET | Health check | | |
| | `/predict` | POST | Predict depression from image | | |
| | `/docs` | GET | Swagger UI documentation | | |
| ### Example API Call (Android/Kotlin) | |
| ```kotlin | |
| // Using Retrofit | |
| interface DepressionApi { | |
| @Multipart | |
| @POST("predict") | |
| suspend fun predict( | |
| @Part file: MultipartBody.Part, | |
| @Query("threshold") threshold: Float = 0.5f | |
| ): PredictionResponse | |
| } | |
| data class PredictionResponse( | |
| val prediction: String, // "depression" or "neutral" | |
| val confidence: Float // 0.0 to 1.0 | |
| ) | |
| ``` | |
| ### Example API Call (React Native / JavaScript) | |
| ```javascript | |
| const formData = new FormData(); | |
| formData.append('file', { | |
| uri: imageUri, | |
| type: 'image/jpeg', | |
| name: 'photo.jpg', | |
| }); | |
| const response = await fetch('https://YOUR-API-URL/predict', { | |
| method: 'POST', | |
| body: formData, | |
| headers: { | |
| 'Content-Type': 'multipart/form-data', | |
| }, | |
| }); | |
| const result = await response.json(); | |
| console.log(result.prediction, result.confidence); | |
| ``` | |
| --- | |
| ## 🔗 Your API URL | |
| After deployment, your API will be available at: | |
| - **Hugging Face**: `https://YOUR_USERNAME-depression-detection-api.hf.space` | |
| - **Render**: `https://depression-detection-api.onrender.com` | |
| Replace the placeholder URL in your mobile app with your actual deployed URL. | |