JaeSwift's picture
Update app.py
ff8147f verified
raw
history blame
2.14 kB
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;
}
"""
# Aztro API URL
AZTRO_API_URL = "https://aztro.sameerkumar.website"
# Horoscope Function with correct API usage
def get_horoscope(sign):
try:
# Send a POST request with the sign and day as part of the URL query parameters
response = requests.post(f"{AZTRO_API_URL}?sign={sign}&day=today")
# Debugging statements to inspect response
print(f"Status Code: {response.status_code}") # Log status code
print(f"Response Text: {response.text}") # Log response text
# Raise an error for non-200 status codes
response.raise_for_status()
data = response.json()
# Return the horoscope description if available
return f"<div class='card'>{data.get('description', 'No horoscope available for today.')}</div>"
except requests.exceptions.RequestException as e:
print(f"Request Exception: {e}") # Log any exceptions
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')