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("

Daily Horoscope by Enemy AI

") 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")