Panic_Detection / README.md
Shib-Sankar-Das's picture
Force rebuild with correct Dockerfile
d10e9b2
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 detected
  • panic_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 /docs endpoint for interactive testing
  • Visit the /health endpoint to verify API status
  • Review the /model-info endpoint for valid input values

πŸ“œ License

MIT License


Built with ❀️ for health monitoring applications