Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import math | |
| def emi_calculator(principal, rate, time): | |
| try: | |
| principal = float(principal) | |
| rate = float(rate) | |
| time = float(time) | |
| if principal <= 0 or rate <= 0 or time <= 0: | |
| return "β Please enter positive values only." | |
| rate = rate / (12 * 100) | |
| time = time * 12 | |
| emi = (principal * rate * pow(1 + rate, time)) / (pow(1 + rate, time) - 1) | |
| return f"β Your Monthly EMI is: βΉ{round(emi, 2)}" | |
| except: | |
| return "β οΈ Please enter valid numeric values." | |
| # πΈ New background with soft blur-glass style card | |
| custom_css = """ | |
| body { | |
| background: linear-gradient(135deg, #fce4ec, #f8bbd0); | |
| background-attachment: fixed; | |
| font-family: 'Segoe UI', sans-serif; | |
| margin: 0; | |
| padding: 0; | |
| } | |
| h1, h3 { | |
| color: #ad1457; | |
| text-align: center; | |
| margin-top: 10px; | |
| } | |
| .gradio-container { | |
| padding: 2rem; | |
| } | |
| .card { | |
| background: rgba(255, 255, 255, 0.6); | |
| backdrop-filter: blur(12px); | |
| border-radius: 16px; | |
| padding: 2rem; | |
| box-shadow: 0 8px 20px rgba(0, 0, 0, 0.05); | |
| max-width: 700px; | |
| margin: 0 auto; | |
| } | |
| textarea { | |
| background-color: #fff0f5 !important; | |
| border: 1px solid #f48fb1 !important; | |
| border-radius: 10px !important; | |
| } | |
| .gr-button { | |
| background-color: #ec407a !important; | |
| color: white !important; | |
| font-weight: bold !important; | |
| border-radius: 10px !important; | |
| padding: 0.75em 1.5em !important; | |
| } | |
| """ | |
| with gr.Blocks(css=custom_css, theme=gr.themes.Soft(primary_hue="pink")) as demo: | |
| gr.Markdown(""" | |
| <div class='card'> | |
| <h1>πΈ EMI Calculator πΈ</h1> | |
| <h3>Enter your details to calculate your monthly loan payments πΈ</h3> | |
| """) | |
| with gr.Row(): | |
| principal = gr.Textbox(label="π¦ Loan Amount (βΉ)", placeholder="e.g., 500000") | |
| rate = gr.Textbox(label="π Annual Interest Rate (%)", placeholder="e.g., 7.5") | |
| time = gr.Textbox(label="β³ Loan Duration (Years)", placeholder="e.g., 10") | |
| output = gr.Textbox(label="π Result", max_lines=1) | |
| gr.Button("Calculate EMI").click(fn=emi_calculator, inputs=[principal, rate, time], outputs=output) | |
| gr.Markdown("</div>") # closing .card | |
| demo.launch(share=True) | |