File size: 3,659 Bytes
f00b194 5ca9e33 f00b194 7a675be 4eca991 7a675be 780288e 7a675be f00b194 780288e 7a675be 4eca991 5ca9e33 4eca991 5ca9e33 7a675be 5ca9e33 4eca991 9453ed3 f00b194 7a675be 4eca991 5ca9e33 4eca991 7a675be 4eca991 5ca9e33 9453ed3 7a675be 780288e 7a675be 5ca9e33 780288e 4eca991 91e1f1a 4eca991 7a675be 42d4c43 4eca991 2475abf 9453ed3 4eca991 91e1f1a 4eca991 91e1f1a 4eca991 cdff09b 4eca991 7a675be f00b194 4eca991 9453ed3 8d2d898 4eca991 9d1787c 4eca991 | 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 | import gradio as gr
import pandas as pd
import os
from datetime import datetime
DB_FILE = "medical_db.csv"
# --- DATABASE ---
def init_db():
if not os.path.exists(DB_FILE):
df = pd.DataFrame(columns=["Date", "Name", "Plan_Type", "Subscription", "Dependents", "Premium", "Income", "Currency"])
df.to_csv(DB_FILE, index=False)
def save_enrollment(name, plan_type, sub_plan, dependents, premium, income, currency):
init_db()
new_entry = {
"Date": datetime.now().strftime("%Y-%m-%d"),
"Name": name,
"Plan_Type": plan_type,
"Subscription": sub_plan,
"Dependents": dependents,
"Premium": premium,
"Income": income,
"Currency": currency
}
df = pd.read_csv(DB_FILE)
df = pd.concat([df, pd.DataFrame([new_entry])], ignore_index=True)
df.to_csv(DB_FILE, index=False)
return f"✅ Enrollment Successful for {name}!"
def search_db(name_query):
if not os.path.exists(DB_FILE):
return pd.DataFrame()
df = pd.read_csv(DB_FILE)
if not name_query:
return df
result = df[df['Name'].str.contains(name_query, case=False, na=False)]
return result
# --- LOGIC ---
CURRENCIES = {"USD ($)": 1.0, "EUR (€)": 0.92, "INR (₹)": 83.0, "GBP (£)": 0.79}
SUB_MULTIPLIERS = {"Normal": 1.0, "Medium": 1.5, "High": 2.2}
CATEGORY_MULT = {"Individual": 1.0, "Family": 1.8, "Senior Citizen": 2.0, "Student": 0.7}
def process_insurance(name, age, income, currency, plan_type, sub_plan, dependents, smoker, enroll):
if not name or income is None:
return "⚠️ Name and Income are required."
rate = CURRENCIES.get(currency, 1.0)
symbol = currency.split("(")[1].replace(")", "")
base = (1500 + (age * 15))
risk_m = 3.5 if smoker == "Yes" else 1.0
final_premium = (
base
* risk_m
* CATEGORY_MULT[plan_type]
* SUB_MULTIPLIERS[sub_plan]
* (1 + (dependents * 0.25))
* rate
)
report = f"""
## Quote for {name}
**Plan:** {sub_plan} {plan_type}
**Premium:** {symbol}{final_premium:,.2f}
"""
if enroll == "Yes":
msg = save_enrollment(name, plan_type, sub_plan, dependents,
f"{symbol}{final_premium:,.2f}", income, currency)
report += f"\n{msg}"
return report
# --- UI ---
with gr.Blocks() as demo:
gr.Markdown("# 🏥 MEDICAL INSURANCE SYSTEM")
with gr.Tabs():
with gr.TabItem("REGISTER & QUOTE"):
name = gr.Textbox(label="Name")
age = gr.Number(label="Age", value=25)
income = gr.Number(label="Income")
currency = gr.Dropdown(list(CURRENCIES.keys()), value="USD ($)", label="Currency")
plan = gr.Dropdown(list(CATEGORY_MULT.keys()), value="Individual", label="Plan Type")
sub = gr.Dropdown(list(SUB_MULTIPLIERS.keys()), value="Normal", label="Subscription")
dep = gr.Slider(0, 10, value=0, step=1, label="Dependents")
smoker = gr.Dropdown(["No", "Yes"], value="No", label="Smoker")
enroll = gr.Dropdown(["No", "Yes"], value="No", label="Enroll")
btn = gr.Button("Calculate")
output = gr.Markdown()
btn.click(process_insurance,
inputs=[name, age, income, currency, plan, sub, dep, smoker, enroll],
outputs=output)
with gr.TabItem("SEARCH"):
search = gr.Textbox(label="Search Name")
btn2 = gr.Button("Search")
table = gr.Dataframe()
btn2.click(search_db, inputs=search, outputs=table)
# IMPORTANT
demo.queue()
demo.launch() |