| import gradio as gr |
| import pandas as pd |
| import os |
| from datetime import datetime |
|
|
| DB_FILE = "medical_db.csv" |
|
|
| |
| 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 |
|
|
| |
| 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 |
|
|
| |
| 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) |
|
|
| |
| demo.queue() |
| demo.launch() |