Spaces:
Sleeping
Sleeping
metadata
title: Panic Detection API
emoji: π¨
colorFrom: red
colorTo: pink
sdk: docker
pinned: false
app_file: app.py
π¨ Panic Detection API
A machine learning API for detecting panic situations based on health metrics using a CNN model.
π― Features
- Real-time Panic Detection: Analyzes health metrics to detect potential panic situations
- RESTful API: Easy integration with mobile and web applications
- Fast Predictions: Optimized CNN model for quick responses
- Input Features:
- Gender (Male/Female)
- Age (years)
- Weight (kg)
- Heart Rate (bpm)
- Step Count
- Activity (Running, Walking, Sitting, Standing, Cycling)
π Quick Start
Try the API Now
Visit the interactive API documentation:
https://Shib-Sankar-Das-Panic-Detection.hf.space/docs
Example Request
curl -X POST "https://Shib-Sankar-Das-Panic-Detection.hf.space/predict" \
-H "Content-Type: application/json" \
-d '{
"gender": "Male",
"age": 25,
"weight": 70.5,
"heartrate": 120,
"stepcount": 5000,
"activity": "Running"
}'
Example Response
{
"panic_detected": true,
"panic_probability": 0.85,
"confidence": "high",
"input_data": {
"gender": "Male",
"age": 25,
"weight": 70.5,
"heartrate": 120,
"stepcount": 5000,
"activity": "Running"
}
}
π API Endpoints
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | API information |
/health |
GET | Health check |
/model-info |
GET | Model details |
/predict |
POST | Single prediction |
/batch-predict |
POST | Batch predictions |
/docs |
GET | Interactive API docs |
π§ Usage Examples
Python
import requests
url = "https://Shib-Sankar-Das-Panic-Detection.hf.space/predict"
data = {
"gender": "Male",
"age": 25,
"weight": 70.5,
"heartrate": 120,
"stepcount": 5000,
"activity": "Running"
}
response = requests.post(url, json=data)
result = response.json()
print(f"Panic detected: {result['panic_detected']}")
print(f"Probability: {result['panic_probability']}")
Flutter/Dart
import 'dart:convert';
import 'package:http/http.dart' as http;
Future<Map<String, dynamic>> detectPanic({
required String gender,
required int age,
required double weight,
required int heartrate,
required int stepcount,
required String activity,
}) async {
final response = await http.post(
Uri.parse('https://Shib-Sankar-Das-Panic-Detection.hf.space/predict'),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({
'gender': gender,
'age': age,
'weight': weight,
'heartrate': heartrate,
'stepcount': stepcount,
'activity': activity,
}),
);
return jsonDecode(response.body);
}
JavaScript
const detectPanic = async (data) => {
const response = await fetch(
'https://Shib-Sankar-Das-Panic-Detection.hf.space/predict',
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
}
);
return await response.json();
};
// Usage
const result = await detectPanic({
gender: "Male",
age: 25,
weight: 70.5,
heartrate: 120,
stepcount: 5000,
activity: "Running"
});
π Model Information
- Model Type: Convolutional Neural Network (CNN)
- Input Shape: 6 features (gender, age, weight, heartrate, stepcount, activity)
- Output: Binary classification (0-1 probability)
- Threshold: 0.5 for panic detection
- Framework: TensorFlow/Keras
π Input Validation
All inputs are validated:
- gender: Must be "Male" or "Female"
- age: 1-120 years
- weight: 20-300 kg
- heartrate: 40-220 bpm
- stepcount: 0-50000 steps
- activity: "Running", "Walking", "Sitting", "Standing", or "Cycling"
π CORS
CORS is enabled for all origins, making it easy to integrate with web and mobile applications.
π Response Format
Every prediction returns:
panic_detected(boolean): Whether panic was detectedpanic_probability(float): Probability score (0-1)confidence(string): "high", "medium", or "low"input_data(object): Echo of input for verification
β‘ Performance
- Response Time: < 1 second (typical)
- Cold Start: ~30 seconds (after inactivity)
- Availability: 24/7 (Hugging Face Spaces)
π οΈ Technology Stack
- Backend: FastAPI + Uvicorn
- ML Framework: TensorFlow 2.15
- Preprocessing: Scikit-learn
- Deployment: Docker on Hugging Face Spaces
π Support
For issues or questions:
- Check the
/docsendpoint for interactive testing - Visit the
/healthendpoint to verify API status - Review the
/model-infoendpoint for valid input values
π License
MIT License
Built with β€οΈ for health monitoring applications