🔮 Ever wondered how long someone has lived—or might live—based on actuarial data?
In this tutorial, I demo a Birth & Expected Death Calculator web app, fully powered by Google Gemini large‑language model and a lightweight Flask backend.
📅 Age Calculator – Instant years, months, days lived
🧠 Life‑Expectancy Estimator – Gemini LLM suggests an expected lifespan using WHO datasets & country stats
PROMPT:
"""
"""
SOURCE CODE: https://github.com/yempallyvamshi/birth_death_calculator
Here is google gemini output:
Explanation and Features:
app.py (Flask Backend):
Handles the web server logic.
calculate_age function: Computes the age in years, months, days, hours, minutes, and seconds. It also calculates total days, hours, minutes, and seconds for the "running time" display.
get_zodiac_sign function: Determines the zodiac sign based on the birth month and day.
calculate_death_date function: This is the "funny" part! It generates a random death date based on a base age and a slight adjustment influenced by the zodiac sign. Remember, this is purely for entertainment and not a real prediction.
Routes (/ and /death_calculator): Render the respective HTML templates and pass the calculated data.
index.html (Age & Horoscope Page):
User Input: Collects Name, Date of Birth, and optional Time of Birth.
Age Display: Shows the calculated age with a real-time counter updated every second using JavaScript.
Horoscope:
Uses the __api_key (which the Canvas environment will automatically inject) to call the Gemini API from the client-side JavaScript.
Fetches a concise daily horoscope based on the user's zodiac sign.
Includes a loading spinner while the horoscope is being fetched.
Navigation: A button to link to the "Death Calculator" page, passing the necessary user data as URL parameters.
Styling: Uses Tailwind CSS for a modern, clean, and responsive design with a calming background.
death_calculator.html (Death Calculator Page):
Intense Theme: Uses a darker background, red accents, and a "Creepster" font for headings to create an "intense" and humorous atmosphere.
Death Date Display: Shows the calculated funny death date.
Countdown: A real-time countdown in years, months, days, hours, minutes, and seconds until the "predicted" death date, updated every second via JavaScript.
Disclaimer: Clearly states that the calculation is for fun.
Navigation: A button to go back to the main age calculator page.
Key Points for the Gemini API:
In index.html, the apiKey variable in the JavaScript fetchHoroscope function is left as an empty string (const apiKey = "";). When you run this in the Canvas environment, it will automatically inject the necessary API key for gemini-2.0-flash. If you were running this outside of Canvas and needed a real API key, you would replace "" with your actual API key (though this is not recommended for client-side code in a production environment).
0 Comments