File size: 3,704 Bytes
7306a70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# 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.