Spaces:
Sleeping
Sleeping
File size: 968 Bytes
c93d817 3bc79cb c93d817 3bc79cb c93d817 3bc79cb c93d817 3bc79cb c93d817 3bc79cb c93d817 987b491 c93d817 |
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 |
import gradio as gr
from datetime import datetime, timedelta
# Age Calculation Function
def calculate_age(dob):
dob = datetime.strptime(dob, "%Y-%m-%d")
now = datetime.now()
delta = now - dob
years = delta.days // 365
months = (delta.days % 365) // 30
days = (delta.days % 365) % 30
hours, remainder = divmod(delta.seconds, 3600)
minutes, seconds = divmod(remainder, 60)
result = (
f"You are {years} years, {months} months, and {days} days old.\n"
f"Or approximately {delta.days * 24 + hours} hours, {minutes} minutes, and {seconds} seconds old."
)
return result
# Gradio Interface
demo = gr.Interface(
fn=calculate_age,
inputs=gr.Textbox(placeholder="YYYY-MM-DD", label="Enter your Date of Birth"),
outputs="text",
title="Age Calculator",
description="Enter your Date of Birth (YYYY-MM-DD) and find out your age in years, months, days, hours, minutes, and seconds!"
)
demo.launch() |