dindizz/shellofficesfossilfuelfreepowerusage
0
1import pandas as pd2import requests3import gradio as gr4import os5 6# Constants7API_URL = 'https://api.electricitymap.org/v3/power-breakdown/latest'8API_TOKEN = os.getenv('ELECTRICITYMAP_API_TOKEN')9 10# Define the data for Shell offices, including Chennai Shell Center11data = {12 "Office": ["Shell Centre", "Shell House", "Shell Technology Center", "Shell India Markets Pvt Ltd", 13 "Shell Australia", "Shell Canada", "Shell Argentina", "Shell Nigeria", "Shell China", 14 "Shell Russia", "Shell Germany", "Shell Netherlands", "Shell South Africa", "Shell Mexico", 15 "Shell Brazil", "Shell Chennai Center"],16 "Location": ["London, United Kingdom", "Singapore", "Houston, Texas, USA", "Bengaluru, India", 17 "Perth, Australia", "Calgary, Alberta, Canada", "Buenos Aires, Argentina", 18 "Lagos, Nigeria", "Beijing, China", "Moscow, Russia", "Hamburg, Germany", 19 "The Hague, Netherlands", "Cape Town, South Africa", "Mexico City, Mexico", 20 "Rio de Janeiro, Brazil", "Chennai, India"],21 "Latitude": [51.5074, 1.3521, 29.7604, 12.9716, -31.9505, 51.0447, -34.6037, 6.5244, 22 39.9042, 55.7558, 53.5511, 52.0705, -33.9249, 19.4326, -22.9068, 12.95],23 "Longitude": [-0.1278, 103.8198, -95.3698, 77.5946, 115.8605, -114.0719, -58.3816, 24 3.3792, 116.4074, 37.6173, 9.9937, 4.3007, 18.4241, -99.1332, -43.1729, 80.20]25}26 27df = pd.DataFrame(data)28 29# Function to make API request30def get_power_breakdown(lat, lon):31 headers = {'auth-token': API_TOKEN}32 params = {'lat': lat, 'lon': lon}33 response = requests.get(API_URL, headers=headers, params=params)34 if response.status_code == 200:35 return response.json().get('fossilFreePercentage', 'N/A')36 else:37 return 'Error'38 39# Define the function to fetch fossil-free percentage for all Shell offices40def fetch_fossil_free_percentages():41 results = []42 for index, row in df.iterrows():43 lat, lon = row["Latitude"], row["Longitude"]44 fossil_free_percentage = get_power_breakdown(lat, lon)45 results.append({46 "Office": row["Office"],47 "Location": row["Location"],48 "Latitude": row["Latitude"],49 "Longitude": row["Longitude"],50 "Fossil-Free Percentage": fossil_free_percentage51 })52 return pd.DataFrame(results)53 54# Define Gradio interface55def show_fossil_free_table():56 result_df = fetch_fossil_free_percentages()57 return result_df58 59gr_interface = gr.Interface(fn=show_fossil_free_table, 60 inputs=None, 61 outputs="dataframe", 62 title="Fossil-Free Percentage for Shell Offices Globally",63 description="Click the button below to see the latest fossil-free energy usage percentages for Shell offices globally.")64 65gr_interface.launch()66 