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