Spaces:
Sleeping
Sleeping
| import requests | |
| import gradio as gr | |
| import os | |
| import pandas as pd | |
| # Predefined data for Shell offices and their latitude and longitude | |
| locations = [ | |
| {"Office": "Shell Argentina", "Location": "Buenos Aires, Argentina", "Latitude": -34.6037, "Longitude": -58.3816}, | |
| {"Office": "Shell Australia", "Location": "Perth, Australia", "Latitude": -31.9505, "Longitude": 115.8605}, | |
| {"Office": "Shell Brazil", "Location": "Rio de Janeiro, Brazil", "Latitude": -22.9068, "Longitude": -43.1729}, | |
| {"Office": "Shell Canada", "Location": "Calgary, Alberta, Canada", "Latitude": 51.0447, "Longitude": -114.0719}, | |
| {"Office": "Shell China", "Location": "Beijing, China", "Latitude": 39.9042, "Longitude": 116.4074}, | |
| {"Office": "Shell India Markets Pvt Ltd", "Location": "Bengaluru, India", "Latitude": 12.9716, "Longitude": 77.5946}, | |
| {"Office": "Shell Chennai Center", "Location": "Chennai, India", "Latitude": 12.94, "Longitude": 80.21}, | |
| {"Office": "Shell Germany", "Location": "Hamburg, Germany", "Latitude": 53.5511, "Longitude": 9.9937}, | |
| {"Office": "Shell Netherlands", "Location": "The Hague, Netherlands", "Latitude": 52.0705, "Longitude": 4.3007}, | |
| {"Office": "Shell Mexico", "Location": "Mexico City, Mexico", "Latitude": 19.4326, "Longitude": -99.1332}, | |
| {"Office": "Shell Nigeria", "Location": "Lagos, Nigeria", "Latitude": 6.5244, "Longitude": 3.3792}, | |
| {"Office": "Shell Russia", "Location": "Moscow, Russia", "Latitude": 55.7558, "Longitude": 37.6173}, | |
| {"Office": "Shell Centre", "Location": "London, United Kingdom", "Latitude": 51.5074, "Longitude": -0.1278}, | |
| {"Office": "Shell House", "Location": "Singapore", "Latitude": 1.3521, "Longitude": 103.8198}, | |
| {"Office": "Shell South Africa", "Location": "Cape Town, South Africa", "Latitude": -33.9249, "Longitude": 18.4241}, | |
| {"Office": "Shell Technology Center", "Location": "Houston, Texas, USA", "Latitude": 29.7604, "Longitude": -95.3698} | |
| ] | |
| # Function to get carbon intensity for a specific latitude and longitude | |
| def get_carbon_intensity(lat, lon): | |
| api_token = os.getenv('API_TOKEN') # Get API token from environment variables | |
| url = f'https://api.electricitymap.org/v3/carbon-intensity/latest?lat={lat}&lon={lon}' | |
| headers = { | |
| 'auth-token': api_token | |
| } | |
| response = requests.get(url, headers=headers) | |
| if response.status_code == 200: | |
| data = response.json() | |
| carbon_intensity = data.get("carbonIntensity", "N/A") | |
| return carbon_intensity | |
| else: | |
| return f"Failed to retrieve data: {response.status_code}, {response.text}" | |
| # Function to handle multiple inputs | |
| def get_all_carbon_intensities(): | |
| results = [] | |
| for location in locations: | |
| lat = location["Latitude"] | |
| lon = location["Longitude"] | |
| carbon_intensity = get_carbon_intensity(lat, lon) | |
| location["Carbon Intensity"] = carbon_intensity | |
| results.append(location) | |
| df = pd.DataFrame(results) | |
| return df | |
| # Gradio interface | |
| with gr.Blocks() as iface: | |
| gr.Markdown("# Shell Offices Carbon Intensity") | |
| gr.Markdown("Get the latest carbon intensity for various Shell office locations globally.") | |
| output = gr.DataFrame() | |
| gr.Button("Get Carbon Intensities").click(get_all_carbon_intensities, outputs=output) | |
| gr.Markdown( | |
| """ | |
| ### Made by Venkataraghavan | |
| - Email: [venkat.srinivasan@gbs-alumni.com](mailto:venkat.srinivasan@gbs-alumni.com) | |
| - LinkedIn: [Venkataraghavan Srinivasan](https://www.linkedin.com/in/venkataraghavansrinivasan/) | |
| """ | |
| ) | |
| iface.launch() | |