Spaces:
Sleeping
Sleeping
File size: 2,261 Bytes
d3e71c7 d26a0f7 d3e71c7 | 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 | 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)
|