Spaces:
Sleeping
Sleeping
Download app.py from Jay9115/Deep_fake_Model_load: direct link, hf CLI and curl.
- Browser
- Download file 5.04 kB
-
https://huggingface.co/spaces/Jay9115/Deep_fake_Model_load/resolve/main/app.py
- Command line
-
hf download hf://spaces/Jay9115/Deep_fake_Model_load/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Jay9115/Deep_fake_Model_load/resolve/main/app.py
5.04 kB
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| import os | |
| import logging | |
| from dotenv import load_dotenv | |
| from routes.predict import router as predict_router | |
| from routes.xceptionnet import router as xceptionnet_router | |
| from routes.mesonet import router as mesonet_router | |
| from routes.gradcam_analysis import router as gradcam_router | |
| from routes.health import router as health_router | |
| from utils.supabase_client import initialize_supabase, validate_supabase_config, get_supabase_manager | |
| # Load environment variables | |
| load_dotenv() | |
| # Configure logging | |
| logging.basicConfig(level=logging.INFO) | |
| logger = logging.getLogger(__name__) | |
| app = FastAPI(title="Deepfake Detection API") | |
| # Configure CORS | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # Initialize Supabase on startup | |
| async def startup_event(): | |
| """Initialize services on startup""" | |
| logger.info("๐ Starting Deepfake Detection API...") | |
| # Validate Supabase configuration | |
| config_status = validate_supabase_config() | |
| if config_status["valid"]: | |
| logger.info("โ Supabase configuration is valid") | |
| # Initialize Supabase | |
| supabase_ok = initialize_supabase() | |
| if supabase_ok: | |
| logger.info("โ Supabase initialization successful") | |
| else: | |
| logger.warning("โ ๏ธ Supabase initialization completed with warnings") | |
| else: | |
| logger.warning(f"โ ๏ธ Supabase configuration issues: {config_status['missing_vars']}") | |
| logger.info("๐ The API will work in local mode. Check your .env file for Supabase setup.") | |
| async def shutdown_event(): | |
| """Cleanup on shutdown""" | |
| logger.info("๐ Shutting down Deepfake Detection API...") | |
| # Configure upload folder | |
| UPLOAD_FOLDER = 'uploads' | |
| if not os.path.exists(UPLOAD_FOLDER): | |
| os.makedirs(UPLOAD_FOLDER) | |
| # Include routers | |
| app.include_router(health_router, prefix="/api", tags=["health"]) | |
| app.include_router(predict_router, prefix="/api", tags=["predict"]) | |
| app.include_router(xceptionnet_router, prefix="/api/xceptionnet", tags=["xceptionnet"]) | |
| app.include_router(mesonet_router, prefix="/api/mesonet", tags=["mesonet"]) | |
| app.include_router(gradcam_router, prefix="/api/gradcam", tags=["gradcam"]) | |
| async def index(): | |
| return { | |
| 'status': 'ok', | |
| 'message': 'Deepfake Detection API Backend is running', | |
| 'available_endpoints': { | |
| # Health & Status | |
| 'health_check': '/api/health', | |
| 'health_simple': '/api/health/simple', | |
| 'health_ready': '/api/health/ready', | |
| 'health_live': '/api/health/live', | |
| 'supabase_health': '/api/health/supabase', | |
| 'detection_stats': '/api/health/stats', | |
| 'storage_info': '/api/health/storage-info', | |
| # Prediction APIs | |
| 'combined_prediction': '/api/predict', | |
| 'xceptionnet_prediction': '/api/xceptionnet/predict', | |
| 'xceptionnet_info': '/api/xceptionnet/info', | |
| 'mesonet_prediction': '/api/mesonet/predict', | |
| 'mesonet_info': '/api/mesonet/info', | |
| # GradCAM Analysis | |
| 'gradcam_analysis': '/api/gradcam/analyze', | |
| 'gradcam_batch': '/api/gradcam/analyze-batch', | |
| 'gradcam_info': '/api/gradcam/model-info', | |
| 'gradcam_test': '/api/gradcam/test', | |
| # Data Management (Supabase) | |
| 'get_results': '/api/gradcam/results', | |
| 'get_statistics': '/api/gradcam/statistics', | |
| 'cleanup_old_data': '/api/gradcam/cleanup' | |
| }, | |
| 'usage': { | |
| 'prediction_apis': 'POST with file/image parameter', | |
| 'gradcam_analysis': 'POST with image parameter - returns prediction + PDF visualization', | |
| 'gradcam_batch': 'POST with images parameter - batch processing', | |
| 'data_retrieval': 'GET requests with optional query parameters', | |
| 'health_checks': 'GET requests for monitoring' | |
| }, | |
| 'storage_features': { | |
| 'supabase_integration': 'PDF reports stored in cloud storage', | |
| 'database_tracking': 'All analysis results saved to database', | |
| 'local_backup': 'Optional local file backup', | |
| 'batch_processing': 'Efficient multi-image analysis' | |
| }, | |
| 'new_features': { | |
| 'gradcam_visualization': 'Visual explanation of AI decisions', | |
| 'professional_pdf_reports': 'A4-sized comprehensive analysis reports', | |
| 'cloud_storage': 'Supabase integration for scalable storage', | |
| 'analytics_tracking': 'Database storage of all detection results', | |
| 'batch_processing': 'Process multiple images at once', | |
| 'memory_optimized': 'Server-friendly performance' | |
| } | |
| } | |
| if __name__ == "__main__": | |
| import uvicorn | |
| uvicorn.run(app, host="0.0.0.0", port=8000) |