Spaces:
Sleeping
Sleeping
Delete README.md
Browse files
README.md
DELETED
|
@@ -1,101 +0,0 @@
|
|
| 1 |
-
# SafeSpace FastAPI Backend
|
| 2 |
-
|
| 3 |
-
## Overview
|
| 4 |
-
FastAPI backend service for threat intelligence and safety recommendations with ML-enhanced categorization.
|
| 5 |
-
|
| 6 |
-
## Current Status
|
| 7 |
-
β
**WORKING** - Server running successfully on http://localhost:8000
|
| 8 |
-
|
| 9 |
-
### Features
|
| 10 |
-
- β
**Threat Detection API** - `/api/threats` endpoint working
|
| 11 |
-
- β
**ML Model Integration** - NB-SVM threat classifier loaded and working
|
| 12 |
-
- β
**News API Integration** - Fetching real news data
|
| 13 |
-
- β
**Health Check** - `/health` endpoint available
|
| 14 |
-
- β
**API Documentation** - Available at `/docs`
|
| 15 |
-
- β οΈ **AI Advice Generation** - Working with fallback (OpenRouter API key needed)
|
| 16 |
-
- β οΈ **ONNX Model** - Optional, not currently available
|
| 17 |
-
|
| 18 |
-
### API Endpoints
|
| 19 |
-
- `GET /` - Root endpoint
|
| 20 |
-
- `GET /health` - Health check
|
| 21 |
-
- `GET /api/test` - Test endpoint
|
| 22 |
-
- `GET /api/threats?city={city}` - Get threats for specific city
|
| 23 |
-
- `GET /api/threats/{id}` - Get threat details
|
| 24 |
-
- `GET /api/models/status` - ML model status
|
| 25 |
-
- `POST /api/models/download` - Download ML models
|
| 26 |
-
|
| 27 |
-
## Quick Start
|
| 28 |
-
|
| 29 |
-
### 1. Install Dependencies
|
| 30 |
-
```bash
|
| 31 |
-
cd backend/fastapi
|
| 32 |
-
pip install -r requirements.txt
|
| 33 |
-
```
|
| 34 |
-
|
| 35 |
-
### 2. Start Server
|
| 36 |
-
```bash
|
| 37 |
-
# Option 1: Direct Python
|
| 38 |
-
python run.py
|
| 39 |
-
|
| 40 |
-
# Option 2: Windows Batch File
|
| 41 |
-
start_fastapi.bat
|
| 42 |
-
|
| 43 |
-
# Option 3: Manual uvicorn
|
| 44 |
-
uvicorn server.main:app --host 0.0.0.0 --port 8000
|
| 45 |
-
```
|
| 46 |
-
|
| 47 |
-
### 3. Test API
|
| 48 |
-
- Health Check: http://localhost:8000/health
|
| 49 |
-
- API Docs: http://localhost:8000/docs
|
| 50 |
-
- Test Threats: http://localhost:8000/api/threats?city=Delhi
|
| 51 |
-
|
| 52 |
-
## Directory Structure
|
| 53 |
-
```
|
| 54 |
-
fastapi/
|
| 55 |
-
βββ run.py # Main startup script
|
| 56 |
-
βββ start_fastapi.bat # Windows startup script
|
| 57 |
-
βββ requirements.txt # Python dependencies
|
| 58 |
-
βββ models/ # ML models directory
|
| 59 |
-
β βββ threat.pkl # β
NB-SVM threat classifier
|
| 60 |
-
β βββ sentiment.pkl # Additional model
|
| 61 |
-
β βββ model_info.txt # Model documentation
|
| 62 |
-
βββ server/ # Main application code
|
| 63 |
-
β βββ main.py # FastAPI app configuration
|
| 64 |
-
β βββ routes/
|
| 65 |
-
β β βββ api.py # β
API endpoints
|
| 66 |
-
β βββ utils/
|
| 67 |
-
β βββ model_loader.py # β
ML model management
|
| 68 |
-
β βββ solution.py # AI advice generation
|
| 69 |
-
βββ venv/ # Virtual environment
|
| 70 |
-
```
|
| 71 |
-
|
| 72 |
-
## Recent Fixes Applied
|
| 73 |
-
1. β
**Fixed Model Loading Paths** - Corrected relative paths for model files
|
| 74 |
-
2. β
**Robust Error Handling** - Server continues running even if optional models fail
|
| 75 |
-
3. β
**Optional Dependencies** - ONNX and transformers are now optional
|
| 76 |
-
4. β
**CORS Configuration** - Added support for both React (3000) and Node.js (3001)
|
| 77 |
-
5. β
**Proper Startup Script** - Fixed directory and import issues
|
| 78 |
-
|
| 79 |
-
## Integration Status
|
| 80 |
-
- β
**Frontend Integration** - API endpoints accessible from React frontend
|
| 81 |
-
- β
**Node.js Backend** - CORS configured for authentication backend
|
| 82 |
-
- β
**ML Pipeline** - Threat classification working with existing model
|
| 83 |
-
- β
**News API** - Real-time news fetching operational
|
| 84 |
-
|
| 85 |
-
## Performance
|
| 86 |
-
- **Startup Time**: ~2-3 seconds
|
| 87 |
-
- **Response Time**: ~2-5 seconds per threat query
|
| 88 |
-
- **Memory Usage**: ~50-100MB
|
| 89 |
-
- **Timeout Protection**: 5-8 seconds with fallback data
|
| 90 |
-
|
| 91 |
-
## Next Steps
|
| 92 |
-
1. **Optional**: Add OpenRouter API key for enhanced AI advice
|
| 93 |
-
2. **Optional**: Add ONNX model for improved threat detection
|
| 94 |
-
3. **Optional**: Implement caching for better performance
|
| 95 |
-
4. **Optional**: Add more sophisticated threat categorization
|
| 96 |
-
|
| 97 |
-
## Troubleshooting
|
| 98 |
-
- If server fails to start, check `pip install -r requirements.txt`
|
| 99 |
-
- If models fail to load, they will use fallback threat detection
|
| 100 |
-
- API will return mock data if external services are unavailable
|
| 101 |
-
- Check logs for detailed error information
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|