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
- Go to huggingface.co
- Click "Sign Up" and create a free account
- Verify your email
Step 2: Create a New Space
- Go to huggingface.co/new-space
- Fill in the details:
- Space name:
depression-detection-api - License: Choose appropriate license (e.g., MIT)
- SDK: Select Docker
- Hardware: Keep CPU basic - Free
- Space name:
- Click "Create Space"
Step 3: Upload Your Files
You can either:
Option A: Using Git (Recommended)
# 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
- Go to your Space's "Files" tab
- Upload these files:
main.pypredictor.pyface_detector.pyschemas.pyrequirements.txtDockerfilemodel.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
# 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
- Create a new GitHub repository
- Push your code (including
render.yaml)
Step 2: Deploy on Render
- Go to render.com and sign up
- Click "New" β "Web Service"
- Connect your GitHub repository
- Render will auto-detect
render.yaml - 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)
// 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)
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.