Spaces:
Sleeping
Sleeping
A newer version of the Gradio SDK is available:
6.5.1
metadata
title: SafeSpace AI API
emoji: π‘οΈ
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 4.44.0
app_file: app.py
pinned: false
license: mit
SafeSpace AI API π‘οΈ
AI-powered threat detection and safety analysis for enhanced public safety
π Live Demo
This API is deployed on Hugging Face Spaces and provides real-time threat detection capabilities using advanced machine learning models.
π€ Features
- π Threat Detection: AI-powered analysis of potential threats in text
- π Sentiment Analysis: Emotional tone detection to enhance threat assessment
- π Location-based Analysis: Geographic threat assessment for specific cities
- π§ Multi-Model Ensemble: Combines multiple ML models for better accuracy
- β‘ Real-time Processing: Fast API responses for real-time applications
- π News Integration: Analyzes real-world news for threat identification
π API Endpoints
Core Endpoints
GET /- API information and statusGET /health- Health checkGET /docs- Interactive API documentation
Threat Analysis
GET /api/threats/?city={city}- Get threats for a specific cityPOST /api/threats/analyze- Analyze text for threatsGET /api/threats/heatmap- Multi-city threat heatmapGET /api/threats/demo- Demo analysis endpointGET /api/threats/batch- Batch analysis for multiple citiesPOST /api/threats/advice- Generate AI safety advice
Model Management
GET /api/models/status- Check model statusPOST /api/models/reload- Reload ML modelsGET /api/models/info- Detailed model informationPOST /api/models/test- Test models with sample dataGET /api/models/performance- Model performance metrics
π§ ML Models
Threat Detection Classifier (
Threat.pkl)- Binary classification for threat detection
- Trained on safety-related text data
Sentiment Analysis Model (
sentiment.pkl)- Sentiment and emotion analysis
- Enhances threat detection accuracy
Context Classification Model (
contextClassifier.onnx)- ONNX neural network for context understanding
- Provides nuanced text interpretation
π Usage Example
Analyze Text for Threats
import requests
# Analyze a single text
response = requests.post(
"https://your-space-name.hf.space/api/threats/analyze",
json={
"text": "Breaking news: Emergency services responding to incident downtown",
"city": "New York"
}
)
result = response.json()
print(f"Threat Level: {result['level']}")
print(f"Confidence: {result['confidence']:.2%}")
print(f"Safety Advice: {result['safety_advice']}")
Get City Threats
# Get threats for a specific city
response = requests.get("https://your-space-name.hf.space/api/threats/?city=Delhi&limit=10")
threats = response.json()
print(f"Found {threats['total_threats']} threats for {threats['city']}")
for threat in threats['threats']:
print(f"- {threat['title']} ({threat['level']} threat)")
π οΈ Technical Stack
- FastAPI - Modern, fast web framework
- scikit-learn - Traditional ML models
- ONNX Runtime - Optimized neural network inference
- Uvicorn - ASGI server
- NewsAPI - Real-time news integration
- OpenRouter - AI-powered safety advice generation
π Safety Features
- Multi-layered Analysis: Combines multiple models for robust detection
- Real-time Monitoring: Continuously analyzes news and social media
- Contextual Understanding: Considers location and context for accurate assessment
- Safety Advice Generation: Provides actionable safety recommendations
- Performance Monitoring: Tracks model accuracy and response times
π Model Performance
- Threat Detection Accuracy: 94%
- False Positive Rate: <4%
- Average Response Time: <150ms
- Ensemble Confidence: Multi-model validation
π Use Cases
- Public Safety Monitoring: Real-time threat assessment for cities
- Content Moderation: Automated safety analysis for platforms
- Emergency Response: Quick threat categorization for first responders
- Risk Assessment: Location-based safety analysis for travelers
- News Analysis: Automated threat detection in news feeds
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π€ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Deployed on Hugging Face Spaces π€