Spaces:
Sleeping
Sleeping
File size: 9,772 Bytes
c2d7b89 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
---
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) |