code-strom / README.md
suryateja008's picture
Update README.md
c2d7b89 verified
---
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
[![Hugging Face Spaces](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/suryatejabatchu008/code-strom)
[![FastAPI](https://img.shields.io/badge/FastAPI-0.104.1-009688.svg?style=flat&logo=FastAPI&logoColor=white)](https://fastapi.tiangolo.com)
[![Python](https://img.shields.io/badge/python-3.10+-blue.svg)](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)