astro / app.py
shyatri's picture
Update app.py
c6d8114 verified
import gradio as gr
from datetime import datetime
# -----------------
# Rule-based astrology logic
# -----------------
def get_zodiac_sign(date_str):
try:
date_obj = datetime.strptime(date_str, "%Y-%m-%d")
day, month = date_obj.day, date_obj.month
except:
return "Unknown"
if (month == 3 and day >= 21) or (month == 4 and day <= 19):
return "Aries โ™ˆ"
elif (month == 4 and day >= 20) or (month == 5 and day <= 20):
return "Taurus โ™‰"
elif (month == 5 and day >= 21) or (month == 6 and day <= 20):
return "Gemini โ™Š"
elif (month == 6 and day >= 21) or (month == 7 and day <= 22):
return "Cancer โ™‹"
elif (month == 7 and day >= 23) or (month == 8 and day <= 22):
return "Leo โ™Œ"
elif (month == 8 and day >= 23) or (month == 9 and day <= 22):
return "Virgo โ™"
elif (month == 9 and day >= 23) or (month == 10 and day <= 22):
return "Libra โ™Ž"
elif (month == 10 and day >= 23) or (month == 11 and day <= 21):
return "Scorpio โ™"
elif (month == 11 and day >= 22) or (month == 12 and day <= 21):
return "Sagittarius โ™"
elif (month == 12 and day >= 22) or (month == 1 and day <= 19):
return "Capricorn โ™‘"
elif (month == 1 and day >= 20) or (month == 2 and day <= 18):
return "Aquarius โ™’"
elif (month == 2 and day >= 19) or (month == 3 and day <= 20):
return "Pisces โ™“"
return "Unknown"
def generate_prediction(name, date, time, place):
zodiac = get_zodiac_sign(date)
return f"โœจ Hello {name}, based on your birth details, your zodiac sign is {zodiac}. " \
f"You are likely to find new opportunities around {place}. Trust your instincts and stay positive!"
def answer_question(name, date, time, place, question):
q = question.lower()
zodiac = get_zodiac_sign(date)
if "career" in q:
return f"๐ŸŒŸ {name}, as a {zodiac}, your career stars indicate steady growth. Hard work will pay off soon!"
elif "love" in q or "relationship" in q:
return f"๐Ÿ’– {name}, love energies are strong for {zodiac}. Be open to new connections."
elif "health" in q:
return f"๐Ÿ’ช {name}, {zodiac} energy suggests you focus on balance. Prioritize rest and self-care."
else:
return f"๐Ÿ”ฎ The universe whispers patience, {name}. As a {zodiac}, trust the timing of your journey."
# -----------------
# Gradio UI
# -----------------
with gr.Blocks(theme="default") as demo:
gr.Markdown("## โœจ AI Astrologer ๐Ÿ”ฎ")
gr.Markdown("Enter your birth details and receive astrology-based insights.")
with gr.Row():
name = gr.Textbox(label="Name")
date = gr.Textbox(label="Birth Date (YYYY-MM-DD)")
time = gr.Textbox(label="Birth Time (HH:MM)", placeholder="Optional")
place = gr.Textbox(label="Birth Place")
prediction_btn = gr.Button("Get Prediction")
prediction_output = gr.Textbox(label="Prediction")
prediction_btn.click(fn=generate_prediction,
inputs=[name, date, time, place],
outputs=prediction_output)
gr.Markdown("### โ“ Ask a Free Question")
question = gr.Textbox(label="Your Question")
answer_output = gr.Textbox(label="Astrology Answer")
ask_btn = gr.Button("Ask the Astrologer")
ask_btn.click(fn=answer_question,
inputs=[name, date, time, place, question],
outputs=answer_output)
demo.launch()