File size: 1,953 Bytes
bce4d63
7bda51e
bce4d63
98fe266
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0415e3c
98fe266
1770c82
ff8147f
98fe266
7bda51e
98fe266
 
 
 
7bda51e
98fe266
 
 
 
 
7bda51e
98fe266
 
7bda51e
98fe266
 
7bda51e
98fe266
 
 
bce4d63
b8ba622
98fe266
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
import gradio as gr
import requests

# RapidAPI Credentials and API Endpoint
API_KEY = "2e427e3d07mshba1bdb10cb6eb30p12d12fjsn215dd7746115"  # Replace with your actual API key
API_HOST = "horoscopes-ai.p.rapidapi.com"
API_URL_TEMPLATE = "https://horoscopes-ai.p.rapidapi.com/get_horoscope/{sign}/{period}/general/en"

# Function to Fetch Horoscope
def get_horoscope(sign, period="today"):
    # Construct the URL based on the selected sign and period
    url = API_URL_TEMPLATE.format(sign=sign, period=period)
    
    headers = {
        "x-rapidapi-key": API_KEY,
        "x-rapidapi-host": API_HOST
    }
    
    # Send GET request to the API
    try:
        response = requests.get(url, headers=headers)
        response.raise_for_status()
        
        # Parse JSON response and retrieve the horoscope text
        data = response.json()
        horoscope_text = data.get("general", ["No horoscope available"])[0]
        return horoscope_text
    except requests.exceptions.RequestException as e:
        return f"Error retrieving horoscope: {e}"

# Gradio Interface Setup
with gr.Blocks() as demo:
    gr.Markdown("<center><h1>Daily Horoscope by Enemy AI</h1></center>")
    gr.Markdown("Select your zodiac sign and period to receive your personalized horoscope.")
    
    sign_dropdown = gr.Dropdown(label="Select Your Zodiac Sign", choices=[
        "aries", "taurus", "gemini", "cancer", "leo", "virgo", 
        "libra", "scorpio", "sagittarius", "capricorn", "aquarius", "pisces"
    ])
    period_dropdown = gr.Dropdown(label="Select Period", choices=["today", "tomorrow", "yesterday"], value="today")
    horoscope_output = gr.Textbox(label="Your Horoscope")
    
    # Button to trigger the API call
    btn_get_horoscope = gr.Button("Get Horoscope")
    btn_get_horoscope.click(fn=get_horoscope, inputs=[sign_dropdown, period_dropdown], outputs=horoscope_output)

if __name__ == "__main__":
    demo.launch(server_name="0.0.0.0")