import pandas as pd import requests import gradio as gr import os # Constants API_URL = 'https://api.electricitymap.org/v3/power-breakdown/latest' API_TOKEN = os.getenv('ELECTRICITYMAP_API_TOKEN') # Define the data for Shell offices, including Chennai Shell Center data = { "Office": ["Shell Centre", "Shell House", "Shell Technology Center", "Shell India Markets Pvt Ltd", "Shell Australia", "Shell Canada", "Shell Argentina", "Shell Nigeria", "Shell China", "Shell Russia", "Shell Germany", "Shell Netherlands", "Shell South Africa", "Shell Mexico", "Shell Brazil", "Shell Chennai Center"], "Location": ["London, United Kingdom", "Singapore", "Houston, Texas, USA", "Bengaluru, India", "Perth, Australia", "Calgary, Alberta, Canada", "Buenos Aires, Argentina", "Lagos, Nigeria", "Beijing, China", "Moscow, Russia", "Hamburg, Germany", "The Hague, Netherlands", "Cape Town, South Africa", "Mexico City, Mexico", "Rio de Janeiro, Brazil", "Chennai, India"], "Latitude": [51.5074, 1.3521, 29.7604, 12.9716, -31.9505, 51.0447, -34.6037, 6.5244, 39.9042, 55.7558, 53.5511, 52.0705, -33.9249, 19.4326, -22.9068, 12.95], "Longitude": [-0.1278, 103.8198, -95.3698, 77.5946, 115.8605, -114.0719, -58.3816, 3.3792, 116.4074, 37.6173, 9.9937, 4.3007, 18.4241, -99.1332, -43.1729, 80.20] } df = pd.DataFrame(data) # Function to make API request def get_power_breakdown(lat, lon): headers = {'auth-token': API_TOKEN} params = {'lat': lat, 'lon': lon} response = requests.get(API_URL, headers=headers, params=params) if response.status_code == 200: return response.json().get('fossilFreePercentage', 'N/A') else: return 'Error' # Define the function to fetch fossil-free percentage for all Shell offices def fetch_fossil_free_percentages(): results = [] for index, row in df.iterrows(): lat, lon = row["Latitude"], row["Longitude"] fossil_free_percentage = get_power_breakdown(lat, lon) results.append({ "Office": row["Office"], "Location": row["Location"], "Latitude": row["Latitude"], "Longitude": row["Longitude"], "Fossil-Free Percentage": fossil_free_percentage }) return pd.DataFrame(results) # Define Gradio interface def show_fossil_free_table(): result_df = fetch_fossil_free_percentages() return result_df gr_interface = gr.Interface(fn=show_fossil_free_table, inputs=None, outputs="dataframe", title="Fossil-Free Percentage for Shell Offices Globally", description="Click the button below to see the latest fossil-free energy usage percentages for Shell offices globally.") gr_interface.launch()