Spaces:
Sleeping
Sleeping
Delete src
Browse files- src/streamlit_app.py +0 -179
src/streamlit_app.py
DELETED
|
@@ -1,179 +0,0 @@
|
|
| 1 |
-
from flask import Flask, render_template, request, jsonify, session, redirect, url_for
|
| 2 |
-
from datetime import datetime, timedelta
|
| 3 |
-
import json
|
| 4 |
-
import os
|
| 5 |
-
import uuid
|
| 6 |
-
|
| 7 |
-
app = Flask(__name__)
|
| 8 |
-
app.secret_key = 'your-secret-key-here'
|
| 9 |
-
app.config['SESSION_TYPE'] = 'filesystem'
|
| 10 |
-
|
| 11 |
-
# Sample data for Indian museums
|
| 12 |
-
MUSEUMS = {
|
| 13 |
-
"national_museum": {
|
| 14 |
-
"id": "national_museum",
|
| 15 |
-
"name": "National Museum, New Delhi",
|
| 16 |
-
"location": "New Delhi",
|
| 17 |
-
"description": "One of India's largest museums with over 200,000 artifacts",
|
| 18 |
-
"price": 50,
|
| 19 |
-
"image": "https://images.unsplash.com/photo-1591386768477-84ff7c578a13?w=400",
|
| 20 |
-
"languages": ["Hindi", "English", "Tamil", "Bengali"],
|
| 21 |
-
"timings": "10:00 AM - 6:00 PM",
|
| 22 |
-
"closed_on": "Monday"
|
| 23 |
-
},
|
| 24 |
-
"indian_museum": {
|
| 25 |
-
"id": "indian_museum",
|
| 26 |
-
"name": "Indian Museum, Kolkata",
|
| 27 |
-
"location": "Kolkata",
|
| 28 |
-
"description": "Oldest and largest museum in India",
|
| 29 |
-
"price": 20,
|
| 30 |
-
"image": "https://images.unsplash.com/photo-1591386768477-84ff7c578a13?w=400",
|
| 31 |
-
"languages": ["Hindi", "English", "Bengali"],
|
| 32 |
-
"timings": "10:00 AM - 5:00 PM",
|
| 33 |
-
"closed_on": "Monday"
|
| 34 |
-
},
|
| 35 |
-
"chhatrapati_museum": {
|
| 36 |
-
"id": "chhatrapati_museum",
|
| 37 |
-
"name": "Chhatrapati Shivaji Maharaj Vastu Sangrahalaya, Mumbai",
|
| 38 |
-
"location": "Mumbai",
|
| 39 |
-
"description": "Renowned museum with Indo-Saracenic architecture",
|
| 40 |
-
"price": 100,
|
| 41 |
-
"image": "https://images.unsplash.com/photo-1591386768477-84ff7c578a13?w=400",
|
| 42 |
-
"languages": ["Hindi", "English", "Marathi"],
|
| 43 |
-
"timings": "10:15 AM - 6:00 PM",
|
| 44 |
-
"closed_on": "Monday"
|
| 45 |
-
},
|
| 46 |
-
"salar_jung": {
|
| 47 |
-
"id": "salar_jung",
|
| 48 |
-
"name": "Salar Jung Museum, Hyderabad",
|
| 49 |
-
"location": "Hyderabad",
|
| 50 |
-
"description": "Third largest museum in India with one-man collections",
|
| 51 |
-
"price": 20,
|
| 52 |
-
"image": "https://images.unsplash.com/photo-1591386768477-84ff7c578a13?w=400",
|
| 53 |
-
"languages": ["Hindi", "English", "Telugu", "Urdu"],
|
| 54 |
-
"timings": "10:00 AM - 5:00 PM",
|
| 55 |
-
"closed_on": "Friday"
|
| 56 |
-
}
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
# Available time slots
|
| 60 |
-
TIME_SLOTS = [
|
| 61 |
-
"10:00 AM - 11:00 AM",
|
| 62 |
-
"11:00 AM - 12:00 PM",
|
| 63 |
-
"12:00 PM - 01:00 PM",
|
| 64 |
-
"02:00 PM - 03:00 PM",
|
| 65 |
-
"03:00 PM - 04:00 PM",
|
| 66 |
-
"04:00 PM - 05:00 PM"
|
| 67 |
-
]
|
| 68 |
-
|
| 69 |
-
# Store bookings (in production, use a database)
|
| 70 |
-
bookings = {}
|
| 71 |
-
|
| 72 |
-
@app.route('/')
|
| 73 |
-
def home():
|
| 74 |
-
return render_template('index.html')
|
| 75 |
-
|
| 76 |
-
@app.route('/museums')
|
| 77 |
-
def museums():
|
| 78 |
-
return render_template('museums.html', museums=MUSEUMS)
|
| 79 |
-
|
| 80 |
-
@app.route('/museum/<museum_id>')
|
| 81 |
-
def museum_detail(museum_id):
|
| 82 |
-
museum = MUSEUMS.get(museum_id)
|
| 83 |
-
if not museum:
|
| 84 |
-
return redirect(url_for('museums'))
|
| 85 |
-
return render_template('booking.html', museum=museum, time_slots=TIME_SLOTS)
|
| 86 |
-
|
| 87 |
-
@app.route('/api/book', methods=['POST'])
|
| 88 |
-
def book_ticket():
|
| 89 |
-
try:
|
| 90 |
-
data = request.get_json()
|
| 91 |
-
|
| 92 |
-
# Validate required fields
|
| 93 |
-
required_fields = ['museum_id', 'visit_date', 'time_slot', 'visitors', 'name', 'email', 'phone']
|
| 94 |
-
for field in required_fields:
|
| 95 |
-
if field not in data or not data[field]:
|
| 96 |
-
return jsonify({'success': False, 'error': f'Missing field: {field}'})
|
| 97 |
-
|
| 98 |
-
museum_id = data['museum_id']
|
| 99 |
-
if museum_id not in MUSEUMS:
|
| 100 |
-
return jsonify({'success': False, 'error': 'Invalid museum'})
|
| 101 |
-
|
| 102 |
-
# Generate booking ID
|
| 103 |
-
booking_id = str(uuid.uuid4())[:8].upper()
|
| 104 |
-
|
| 105 |
-
# Calculate total amount
|
| 106 |
-
museum = MUSEUMS[museum_id]
|
| 107 |
-
total_amount = museum['price'] * int(data['visitors'])
|
| 108 |
-
|
| 109 |
-
# Create booking record
|
| 110 |
-
booking = {
|
| 111 |
-
'booking_id': booking_id,
|
| 112 |
-
'museum_id': museum_id,
|
| 113 |
-
'museum_name': museum['name'],
|
| 114 |
-
'visit_date': data['visit_date'],
|
| 115 |
-
'time_slot': data['time_slot'],
|
| 116 |
-
'visitors': int(data['visitors']),
|
| 117 |
-
'total_amount': total_amount,
|
| 118 |
-
'customer_name': data['name'],
|
| 119 |
-
'customer_email': data['email'],
|
| 120 |
-
'customer_phone': data['phone'],
|
| 121 |
-
'language': data.get('language', 'English'),
|
| 122 |
-
'booking_date': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
| 123 |
-
'status': 'confirmed'
|
| 124 |
-
}
|
| 125 |
-
|
| 126 |
-
# Store booking
|
| 127 |
-
bookings[booking_id] = booking
|
| 128 |
-
|
| 129 |
-
return jsonify({
|
| 130 |
-
'success': True,
|
| 131 |
-
'booking_id': booking_id,
|
| 132 |
-
'booking': booking
|
| 133 |
-
})
|
| 134 |
-
|
| 135 |
-
except Exception as e:
|
| 136 |
-
return jsonify({'success': False, 'error': str(e)})
|
| 137 |
-
|
| 138 |
-
@app.route('/booking/<booking_id>')
|
| 139 |
-
def booking_confirmation(booking_id):
|
| 140 |
-
booking = bookings.get(booking_id)
|
| 141 |
-
if not booking:
|
| 142 |
-
return redirect(url_for('home'))
|
| 143 |
-
return render_template('confirmation.html', booking=booking)
|
| 144 |
-
|
| 145 |
-
@app.route('/api/check-availability', methods=['POST'])
|
| 146 |
-
def check_availability():
|
| 147 |
-
data = request.get_json()
|
| 148 |
-
museum_id = data.get('museum_id')
|
| 149 |
-
visit_date = data.get('visit_date')
|
| 150 |
-
time_slot = data.get('time_slot')
|
| 151 |
-
|
| 152 |
-
# Simple availability check (in production, check against actual bookings)
|
| 153 |
-
# For demo, assume all slots are available
|
| 154 |
-
available = True
|
| 155 |
-
capacity = 50 # Maximum visitors per slot
|
| 156 |
-
|
| 157 |
-
# Count existing bookings for this slot
|
| 158 |
-
booked_count = sum(
|
| 159 |
-
1 for booking in bookings.values()
|
| 160 |
-
if (booking['museum_id'] == museum_id and
|
| 161 |
-
booking['visit_date'] == visit_date and
|
| 162 |
-
booking['time_slot'] == time_slot)
|
| 163 |
-
)
|
| 164 |
-
|
| 165 |
-
available_slots = capacity - booked_count
|
| 166 |
-
|
| 167 |
-
return jsonify({
|
| 168 |
-
'available': available_slots > 0,
|
| 169 |
-
'available_slots': available_slots,
|
| 170 |
-
'capacity': capacity
|
| 171 |
-
})
|
| 172 |
-
|
| 173 |
-
@app.route('/api/museums')
|
| 174 |
-
def get_museums():
|
| 175 |
-
return jsonify(MUSEUMS)
|
| 176 |
-
|
| 177 |
-
if __name__ == '__main__':
|
| 178 |
-
app.run(debug=True, host='0.0.0.0', port=7860)
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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