import gradio as gr import requests PLACEHOLDER = """

Daily Horoscope by Enemy AI

""" CSS = """ .card { border: 1px solid black; border-radius: 10px; padding: 10px; text-align: center; box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.3); margin: 10px; } h3 { text-align: center; } .button-container { text-align: center; margin-top: 20px; } .result-container { margin-top: 20px; } """ ASTROSEEK_API_URL = "https://api.astroseek.com/horoscope/daily" # Horoscope Function with improved error handling def get_horoscope(sign): try: response = requests.get(f"{ASTROSEEK_API_URL}/{sign}") response.raise_for_status() # Raises an error for HTTP codes 400+ data = response.json() return f"
{data.get('horoscope', 'No horoscope available for today.')}
" except requests.exceptions.RequestException: return "
Error retrieving horoscope. Please try again later.
" # Gradio Interface with gr.Blocks(theme="soft", css=CSS) as demo: gr.Markdown(PLACEHOLDER) gr.Markdown("### Get your daily horoscope.") horoscope_output = gr.HTML() # Retains the HTML formatting for horoscopes sign_dropdown = gr.Dropdown(label="Select Your Zodiac Sign", choices=[ "Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces" ]) btn_get_horoscope = gr.Button("Get Horoscope") btn_get_horoscope.click(fn=get_horoscope, inputs=sign_dropdown, outputs=horoscope_output) if __name__ == "__main__": demo.launch(server_name='0.0.0.0')