Spaces:
Sleeping
Sleeping
| title: Smart Parking System | |
| emoji: π | |
| colorFrom: blue | |
| colorTo: green | |
| sdk: docker | |
| pinned: false | |
| license: mit | |
| app_port: 7860 | |
| # π ΏοΈ Smart Parking System - AI-Powered Parking Slot Recommendation | |
| [](https://huggingface.co/spaces/suryatejabatchu008/code-strom) | |
| [](https://fastapi.tiangolo.com) | |
| [](https://www.python.org/downloads/) | |
| An intelligent parking management system that uses AI to recommend the best parking slots based on proximity, price, user feedback, and popularity. | |
| ## π Live Demo | |
| **API Endpoint:** https://suryatejabatchu008-code-strom.hf.space | |
| **Interactive Docs:** https://suryatejabatchu008-code-strom.hf.space/docs | |
| ## β¨ Features | |
| - π€ **AI-Powered Recommendations** - RandomForest ML model for optimal slot selection | |
| - π **Real-time Location** - GPS-based proximity scoring | |
| - β **User Feedback** - Integrated rating system (0-5 stars) | |
| - π³ **Razorpay Integration** - Secure payment processing | |
| - π **Smart Analytics** - Popularity and availability tracking | |
| - π **Live Database** - Real-time slot availability updates | |
| ## π― How It Works | |
| 1. **User sends GPS location** β System fetches nearby parking lots | |
| 2. **AI Model analyzes 5 features:** | |
| - Proximity (40% weight) | |
| - User Ratings (30% weight) | |
| - Popularity (20% weight) | |
| - Availability (10% weight) | |
| - Price Factor | |
| 3. **Returns top recommendations** β Sorted by weighted score | |
| 4. **Secure booking & payment** β Razorpay integration | |
| ## π‘ API Endpoints | |
| ### π Health Check | |
| ```bash | |
| curl https://suryatejabatchu008-code-strom.hf.space/ | |
| ``` | |
| ### π― Get Slot Recommendations | |
| ```bash | |
| curl -X POST "https://suryatejabatchu008-code-strom.hf.space/api/recommend-slots" \ | |
| -H "Content-Type: application/json" \ | |
| -d '{ | |
| "user_location": { | |
| "latitude": 16.4645659, | |
| "longitude": 80.5076208 | |
| }, | |
| "vehicle_type": "4-wheeler", | |
| "top_k": 5 | |
| }' | |
| ``` | |
| **Response:** | |
| ```json | |
| { | |
| "recommendations": [ | |
| { | |
| "slot_id": "A1-1", | |
| "db_slot_id": 1, | |
| "lot_name": "A1", | |
| "location": "SRM University AP Parking lot background", | |
| "distance_km": 0.15, | |
| "vehicle_type": "4-wheeler", | |
| "hourly_rate": 60.0, | |
| "avg_feedback": 4.5, | |
| "popularity_score": 0.75, | |
| "recommendation_score": 0.89, | |
| "coordinates": { | |
| "latitude": 16.4645659, | |
| "longitude": 80.5076208 | |
| } | |
| } | |
| ], | |
| "total_available": 1, | |
| "user_location": { | |
| "latitude": 16.4645659, | |
| "longitude": 80.5076208 | |
| } | |
| } | |
| ``` | |
| ### π³ Create Payment Order | |
| ```bash | |
| curl -X POST "https://suryatejabatchu008-code-strom.hf.space/api/payment/create-order" \ | |
| -H "Content-Type: application/json" \ | |
| -d '{ | |
| "booking_uid": "ABC12345", | |
| "amount": 120.00, | |
| "currency": "INR" | |
| }' | |
| ``` | |
| ### β Submit Feedback | |
| ```bash | |
| curl -X POST "https://suryatejabatchu008-code-strom.hf.space/api/feedback" \ | |
| -H "Content-Type: application/json" \ | |
| -d '{ | |
| "booking_uid": "ABC12345", | |
| "rating": 5, | |
| "comment": "Great parking experience!" | |
| }' | |
| ``` | |
| ### π Get Booking Details | |
| ```bash | |
| curl "https://suryatejabatchu008-code-strom.hf.space/api/booking/ABC12345" | |
| ``` | |
| ### π Retrain AI Model | |
| ```bash | |
| curl -X POST "https://suryatejabatchu008-code-strom.hf.space/api/retrain-model" | |
| ``` | |
| ## π§ͺ Testing with Python | |
| ```python | |
| import requests | |
| # Base URL | |
| BASE_URL = "https://suryatejabatchu008-code-strom.hf.space" | |
| # Get recommendations | |
| response = requests.post( | |
| f"{BASE_URL}/api/recommend-slots", | |
| json={ | |
| "user_location": { | |
| "latitude": 16.4645659, | |
| "longitude": 80.5076208 | |
| }, | |
| "vehicle_type": "4-wheeler", | |
| "top_k": 5 | |
| } | |
| ) | |
| recommendations = response.json() | |
| print(f"Found {len(recommendations['recommendations'])} slots") | |
| # Book a slot (first create booking via database API) | |
| booking_uid = "ABC12345" # From your database | |
| # Create payment | |
| payment_response = requests.post( | |
| f"{BASE_URL}/api/payment/create-order", | |
| json={ | |
| "booking_uid": booking_uid, | |
| "amount": 120.00, | |
| "currency": "INR" | |
| } | |
| ) | |
| payment_data = payment_response.json() | |
| print(f"Payment Order ID: {payment_data['order_id']}") | |
| ``` | |
| ## π Testing with JavaScript | |
| ```javascript | |
| // Get slot recommendations | |
| fetch('https://suryatejabatchu008-code-strom.hf.space/api/recommend-slots', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| }, | |
| body: JSON.stringify({ | |
| user_location: { | |
| latitude: 16.4645659, | |
| longitude: 80.5076208 | |
| }, | |
| vehicle_type: '4-wheeler', | |
| top_k: 5 | |
| }) | |
| }) | |
| .then(response => response.json()) | |
| .then(data => { | |
| console.log('Recommendations:', data.recommendations); | |
| console.log('Total available slots:', data.total_available); | |
| }) | |
| .catch(error => console.error('Error:', error)); | |
| ``` | |
| ## ποΈ Architecture | |
| ``` | |
| βββββββββββββββββββ | |
| β User Device β | |
| β (GPS Location) β | |
| ββββββββββ¬βββββββββ | |
| β | |
| βΌ | |
| βββββββββββββββββββββββββββββββββββββββ | |
| β FastAPI Backend (HF Space) β | |
| β βββββββββββββββββββββββββββββββ β | |
| β β AI Model (RandomForest) β β | |
| β β - Proximity Scoring β β | |
| β β - Feedback Analysis β β | |
| β β - Popularity Tracking β β | |
| β βββββββββββββββββββββββββββββββ β | |
| β β | |
| β βββββββββββββββββββββββββββββββ β | |
| β β Payment Service β β | |
| β β - Razorpay Integration β β | |
| β βββββββββββββββββββββββββββββββ β | |
| βββββββββββββ¬ββββββββββββββββββββββββββ | |
| β | |
| βΌ | |
| βββββββββββββββββββββββββββββββββββββββ | |
| β Database API (PHP Backend) β | |
| β - Parking Slots Management β | |
| β - Booking System β | |
| β - User Management β | |
| β - Payment Status Tracking β | |
| βββββββββββββββββββββββββββββββββββββββ | |
| ``` | |
| ## π οΈ Technology Stack | |
| - **Backend:** FastAPI (Python 3.10) | |
| - **AI/ML:** scikit-learn (RandomForest) | |
| - **Payment:** Razorpay API | |
| - **Database:** MySQL (via REST API) | |
| - **Deployment:** Docker on Hugging Face Spaces | |
| - **Web Server:** Uvicorn | |
| ## π AI Model Features | |
| The AI model uses 5 weighted features to recommend parking slots: | |
| | Feature | Weight | Description | | |
| |---------|--------|-------------| | |
| | **Proximity** | 40% | Distance from user's current location | | |
| | **Feedback** | 30% | Average user rating (0-5 stars) | | |
| | **Popularity** | 20% | Historical booking frequency | | |
| | **Availability** | 10% | Real-time slot availability | | |
| | **Price** | Factor | Hourly rate consideration | | |
| ## π Environment Variables | |
| The following environment variables are configured as Hugging Face Spaces secrets: | |
| ```bash | |
| RAZORPAY_KEY_ID=rzp_test_RYlqJbc24Sl6jz | |
| RAZORPAY_KEY_SECRET=bghQe0L7iort9vmqb6Jlf8Ec | |
| API_HOST=0.0.0.0 | |
| API_PORT=7860 | |
| ENVIRONMENT=production | |
| DEBUG=False | |
| ``` | |
| ## π± Current Deployment | |
| - **Parking Lots:** 1 (A1 at SRM University AP) | |
| - **Available Slots:** Real-time availability | |
| - **Payment Mode:** Test mode (Razorpay) | |
| - **Database:** https://aadarshsenapati.in/api/api.php | |
| ## π§ͺ Test Credentials | |
| For testing payments: | |
| - **Test Card:** 4111 1111 1111 1111 | |
| - **Expiry:** Any future date | |
| - **CVV:** Any 3 digits | |
| - **OTP:** 1234 (for test mode) | |
| ## π Performance Metrics | |
| - **Response Time:** < 500ms for recommendations | |
| - **AI Inference:** < 100ms | |
| - **Database Queries:** < 200ms | |
| - **Uptime:** 99.9% (Hugging Face Spaces) | |
| ## π Troubleshooting | |
| ### API Not Responding | |
| ```bash | |
| # Check status | |
| curl https://suryatejabatchu008-code-strom.hf.space/ | |
| # Expected response: | |
| # {"message": "Smart Parking API is running!", "status": "healthy"} | |
| ``` | |
| ### No Recommendations Returned | |
| - Check if slots are available in database | |
| - Verify GPS coordinates are valid | |
| - Ensure vehicle type matches available slots | |
| ### Payment Errors | |
| - Verify Razorpay credentials in Spaces secrets | |
| - Check if booking_uid exists | |
| - Ensure amount is > 0 | |
| ## π API Support | |
| For API issues or questions: | |
| - Check the [Interactive API Docs](https://suryatejabatchu008-code-strom.hf.space/docs) | |
| - View example requests in the `/docs` endpoint | |
| - Test endpoints directly in the Swagger UI | |
| ## π Updates & Maintenance | |
| The system automatically: | |
| - β Retrains AI model when feedback is submitted | |
| - β Updates slot availability in real-time | |
| - β Syncs with database every request | |
| - β Processes payments securely via Razorpay | |
| ## π License | |
| MIT License - Feel free to use this project for learning and development! | |
| ## π¨βπ» Developer | |
| Developed by **Surya Teja Batchu** ([@suryatejabatchu008](https://huggingface.co/suryatejabatchu008)) | |
| --- | |
| **π Deployed on Hugging Face Spaces** | |
| Visit: [https://suryatejabatchu008-code-strom.hf.space](https://suryatejabatchu008-code-strom.hf.space) | |
| Interactive Docs: [https://suryatejabatchu008-code-strom.hf.space/docs](https://suryatejabatchu008-code-strom.hf.space/docs) |