JaeSwift commited on
Commit
0415e3c
·
verified ·
1 Parent(s): 1ce4bcd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -3,7 +3,7 @@ import requests
3
 
4
  PLACEHOLDER = """
5
  <center>
6
- <p>Daily Horoscope by Enemy AI</p>
7
  </center>
8
  """
9
 
@@ -30,19 +30,21 @@ h3 {
30
 
31
  ASTROSEEK_API_URL = "https://api.astroseek.com/horoscope/daily"
32
 
33
- # Horoscope Function
34
  def get_horoscope(sign):
35
- response = requests.get(f"{ASTROSEEK_API_URL}/{sign}")
36
- if response.status_code == 200:
 
37
  data = response.json()
38
- return data.get("horoscope", "No horoscope available for today.")
39
- else:
40
- return "Error retrieving horoscope. Please try again later."
41
 
 
42
  with gr.Blocks(theme="soft", css=CSS) as demo:
43
  gr.Markdown(PLACEHOLDER)
44
  gr.Markdown("### Get your daily horoscope.")
45
- horoscope_output = gr.HTML()
46
  sign_dropdown = gr.Dropdown(label="Select Your Zodiac Sign", choices=[
47
  "Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces"
48
  ])
 
3
 
4
  PLACEHOLDER = """
5
  <center>
6
+ <p><strong>Daily Horoscope by Enemy AI</strong></p>
7
  </center>
8
  """
9
 
 
30
 
31
  ASTROSEEK_API_URL = "https://api.astroseek.com/horoscope/daily"
32
 
33
+ # Horoscope Function with improved error handling
34
  def get_horoscope(sign):
35
+ try:
36
+ response = requests.get(f"{ASTROSEEK_API_URL}/{sign}")
37
+ response.raise_for_status() # Raises an error for HTTP codes 400+
38
  data = response.json()
39
+ return f"<div class='card'>{data.get('horoscope', 'No horoscope available for today.')}</div>"
40
+ except requests.exceptions.RequestException:
41
+ return "<div class='card'>Error retrieving horoscope. Please try again later.</div>"
42
 
43
+ # Gradio Interface
44
  with gr.Blocks(theme="soft", css=CSS) as demo:
45
  gr.Markdown(PLACEHOLDER)
46
  gr.Markdown("### Get your daily horoscope.")
47
+ horoscope_output = gr.HTML() # Retains the HTML formatting for horoscopes
48
  sign_dropdown = gr.Dropdown(label="Select Your Zodiac Sign", choices=[
49
  "Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces"
50
  ])