Spaces:
Sleeping
Sleeping
File size: 13,318 Bytes
21d48cf 0e9b650 560b751 0e9b650 8be0a3c 0e9b650 8be0a3c 0e9b650 8be0a3c 560b751 0e9b650 8be0a3c 0e9b650 21d48cf 0e9b650 | 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 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | import streamlit as st
import os
import json
from datetime import datetime
import pandas as pd
try:
from openai import OpenAI
except ImportError:
st.error("OpenAI package not installed. Please add 'openai' to requirements.txt")
st.stop()
# Configure page
st.set_page_config(
page_title="π₯οΈ Smart Boat Insurance Calculator",
page_icon="π₯οΈ",
layout="wide",
initial_sidebar_state="expanded"
)
# Initialize OpenAI client
@st.cache_resource
def init_openai():
# Try multiple ways to get the API key
api_key = None
# Method 1: Try Streamlit secrets (for local development)
try:
if hasattr(st, 'secrets') and 'OPENAI_API_KEY' in st.secrets:
api_key = st.secrets['OPENAI_API_KEY']
except:
pass
# Method 2: Try environment variables (for Hugging Face Spaces)
if not api_key:
api_key = os.getenv('OPENAI_API_KEY')
# Method 3: Try Hugging Face Spaces secrets format
if not api_key:
try:
# Hugging Face Spaces may store secrets differently
api_key = os.environ.get('OPENAI_API_KEY')
except:
pass
if not api_key:
st.error("""
π OpenAI API key not found!
For Hugging Face Spaces:
1. Go to your Space Settings
2. Click on 'Repository secrets'
3. Add a new secret with:
- Name: OPENAI_API_KEY
- Value: your_openai_api_key_here
4. Restart your Space
Current environment variables available:
""" + str([k for k in os.environ.keys() if 'API' in k or 'KEY' in k]))
st.stop()
return OpenAI(api_key=api_key)
client = init_openai()
# Debug section (remove this after it works)
with st.expander("π§ Debug Info (remove after setup)", expanded=False):
st.write("Environment variables containing 'KEY' or 'API':")
debug_vars = {k: "***" + v[-4:] if v and len(v) > 4 else "Not set"
for k, v in os.environ.items()
if 'KEY' in k.upper() or 'API' in k.upper()}
st.json(debug_vars)
st.write("Streamlit secrets available:")
try:
secret_keys = list(st.secrets.keys()) if hasattr(st, 'secrets') else []
st.write(secret_keys)
except:
st.write("No secrets accessible via st.secrets")
# Custom CSS for better styling
st.markdown("""
<style>
.main-header {
background: linear-gradient(90deg, #1e3a8a 0%, #3b82f6 100%);
padding: 2rem;
border-radius: 10px;
margin-bottom: 2rem;
color: white;
text-align: center;
}
.tool-card {
background: #f8fafc;
padding: 1.5rem;
border-radius: 10px;
border-left: 4px solid #3b82f6;
margin: 1rem 0;
}
.result-card {
background: #ecfdf5;
padding: 1.5rem;
border-radius: 10px;
border: 1px solid #10b981;
margin: 1rem 0;
}
.warning-card {
background: #fef3c7;
padding: 1rem;
border-radius: 8px;
border: 1px solid #f59e0b;
margin: 1rem 0;
}
</style>
""", unsafe_allow_html=True)
# Header
st.markdown("""
<div class="main-header">
<h1>π₯οΈ Smart Boat Insurance Calculator</h1>
<p>Get instant premium estimates and state-specific legal requirements for your boat insurance</p>
</div>
""", unsafe_allow_html=True)
# Sidebar for navigation
st.sidebar.title("π§ Navigation")
tool_choice = st.sidebar.radio(
"Choose a tool:",
["π° Premium Calculator", "π State Legal Checklist", "π Compare Both"]
)
# Function to get premium estimate
def get_premium_estimate(boat_data):
prompt = f"""
As a boat insurance expert, provide a monthly premium estimate for a boat with these details:
Boat Type: {boat_data['type']}
Boat Age: {boat_data['age']} years
Boat Value: ${boat_data['value']:,}
Location: {boat_data['location']}
Primary Use: {boat_data['usage']}
Experience Level: {boat_data['experience']}
Safety Features: {boat_data['safety_features']}
Storage Location: {boat_data['storage']}
Annual Usage: {boat_data['annual_hours']} hours
Please provide:
1. A realistic monthly premium range (low-high)
2. Key factors affecting the price
3. Money-saving tips specific to this boat profile
4. Coverage recommendations
Format as JSON with keys: premium_low, premium_high, factors, tips, coverage_recommendations
"""
try:
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": prompt}],
temperature=0.3
)
return response.choices[0].message.content
except Exception as e:
return f"Error getting estimate: {str(e)}"
# Function to get state-specific checklist
def get_state_checklist(state, boat_type="General"):
prompt = f"""
As a boat insurance legal expert, provide a comprehensive checklist of boat insurance requirements and recommendations for {state}.
Boat Type: {boat_type}
Please provide:
1. Mandatory insurance requirements (if any)
2. Recommended coverage types
3. Minimum liability limits
4. Special state-specific considerations
5. Registration and documentation requirements
6. Penalty information for non-compliance
Format as a detailed checklist with clear action items.
"""
try:
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": prompt}],
temperature=0.2
)
return response.choices[0].message.content
except Exception as e:
return f"Error getting checklist: {str(e)}"
# Premium Calculator Tool
if tool_choice in ["π° Premium Calculator", "π Compare Both"]:
st.markdown('<div class="tool-card">', unsafe_allow_html=True)
st.header("π° Boat Insurance Premium Calculator")
st.write("Get an AI-powered estimate of your boat insurance costs")
col1, col2 = st.columns(2)
with col1:
st.subheader("Boat Details")
boat_type = st.selectbox(
"Boat Type",
["Sailboat", "Motorboat", "Yacht", "Pontoon", "Fishing Boat", "Jet Ski", "Speedboat", "Catamaran", "Other"]
)
boat_age = st.slider("Boat Age (years)", 0, 50, 10)
boat_value = st.number_input(
"Estimated Boat Value ($)",
min_value=1000,
max_value=10000000,
value=50000,
step=5000
)
location = st.selectbox(
"Primary Location",
["Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut",
"Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa",
"Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan",
"Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire",
"New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio",
"Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota",
"Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia",
"Wisconsin", "Wyoming"]
)
with col2:
st.subheader("Usage & Experience")
usage = st.selectbox(
"Primary Use",
["Recreational", "Fishing", "Racing", "Commercial", "Charter", "Liveaboard"]
)
experience = st.selectbox(
"Boating Experience",
["Beginner (0-2 years)", "Intermediate (3-10 years)", "Experienced (10+ years)", "Professional"]
)
safety_features = st.multiselect(
"Safety Features",
["GPS/Navigation System", "Life Jackets", "Fire Extinguisher", "Flares", "Radio/VHF",
"Anchor", "First Aid Kit", "Bilge Pump", "EPIRB", "Radar"]
)
storage = st.selectbox(
"Storage Location",
["Marina", "Home (Driveway)", "Storage Facility", "Dry Stack", "Mooring"]
)
annual_hours = st.slider("Annual Usage (hours)", 0, 500, 100)
if st.button("Calculate Premium Estimate", type="primary"):
with st.spinner("Calculating your premium estimate..."):
boat_data = {
'type': boat_type,
'age': boat_age,
'value': boat_value,
'location': location,
'usage': usage,
'experience': experience,
'safety_features': ', '.join(safety_features) if safety_features else 'None specified',
'storage': storage,
'annual_hours': annual_hours
}
result = get_premium_estimate(boat_data)
st.markdown('<div class="result-card">', unsafe_allow_html=True)
st.subheader("π Your Premium Estimate")
st.write(result)
st.markdown('</div>', unsafe_allow_html=True)
# Lead capture
st.markdown("---")
st.subheader("π§ Get Personalized Quotes from Top Insurers")
email = st.text_input("Enter your email for personalized quotes:")
phone = st.text_input("Phone number (optional):")
if st.button("Get My Quotes"):
st.success("Thank you! We'll send you personalized quotes from our partner insurers within 24 hours.")
# Here you would integrate with your CRM/email system
st.markdown('</div>', unsafe_allow_html=True)
# State Legal Checklist Tool
if tool_choice in ["π State Legal Checklist", "π Compare Both"]:
st.markdown('<div class="tool-card">', unsafe_allow_html=True)
st.header("π State-by-State Legal Requirements")
st.write("Get a customized checklist of insurance requirements for your state")
col1, col2 = st.columns(2)
with col1:
selected_state = st.selectbox(
"Select Your State",
["Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut",
"Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa",
"Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan",
"Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire",
"New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio",
"Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota",
"Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia",
"Wisconsin", "Wyoming"],
key="state_selector"
)
with col2:
checklist_boat_type = st.selectbox(
"Boat Type (for specific requirements)",
["General", "Sailboat", "Motorboat", "Yacht", "Pontoon", "Fishing Boat", "Jet Ski", "Commercial Vessel"],
key="checklist_boat_type"
)
if st.button("Generate Legal Checklist", type="primary"):
with st.spinner(f"Generating legal requirements for {selected_state}..."):
checklist = get_state_checklist(selected_state, checklist_boat_type)
st.markdown('<div class="result-card">', unsafe_allow_html=True)
st.subheader(f"π {selected_state} Boat Insurance Legal Checklist")
st.write(checklist)
st.markdown('</div>', unsafe_allow_html=True)
# Download option
if st.button("π Download Checklist as PDF"):
st.info("PDF download feature would be implemented here")
st.markdown('</div>', unsafe_allow_html=True)
# Additional features
st.markdown("---")
col1, col2, col3 = st.columns(3)
with col1:
st.markdown("""
### π― Why Choose Our Tool?
- AI-powered accurate estimates
- State-specific legal guidance
- Instant results
- Free to use
""")
with col2:
st.markdown("""
### π Need Help?
- Expert consultation available
- Compare multiple insurers
- Claims assistance
- 24/7 support
""")
with col3:
st.markdown("""
### π‘ Pro Tips
- Update coverage annually
- Bundle with auto insurance
- Take boating safety courses
- Install safety equipment
""")
# Footer with disclaimer
st.markdown("---")
st.markdown("""
<div class="warning-card">
<strong>β οΈ Important Disclaimer:</strong> This tool provides estimates for informational purposes only.
Actual premiums may vary based on additional factors. Always consult with licensed insurance agents
for official quotes and coverage details.
</div>
""", unsafe_allow_html=True)
st.markdown("""
<div style="text-align: center; padding: 2rem; color: #6b7280;">
<p>Made with β€οΈ for boat owners | Powered by AI | Β© 2025 Smart Boat Insurance</p>
</div>
""", unsafe_allow_html=True) |