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()