File size: 1,681 Bytes
bce4d63
7bda51e
bce4d63
7bda51e
 
0415e3c
7bda51e
bce4d63
 
7bda51e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bce4d63
 
7bda51e
 
0415e3c
7bda51e
0415e3c
 
 
7bda51e
0415e3c
 
 
7bda51e
0415e3c
7bda51e
 
 
0415e3c
7bda51e
 
 
 
 
 
bce4d63
 
c00b9ed
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import gradio as gr
import requests

PLACEHOLDER = """
<center>
<p><strong>Daily Horoscope by Enemy AI</strong></p>
</center>
"""

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"<div class='card'>{data.get('horoscope', 'No horoscope available for today.')}</div>"
    except requests.exceptions.RequestException:
        return "<div class='card'>Error retrieving horoscope. Please try again later.</div>"

# 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')