File size: 3,599 Bytes
6f1b85d
 
 
 
 
 
 
ef5dfe1
6f1b85d
ef5dfe1
6f1b85d
 
ef5dfe1
 
6f1b85d
 
 
ef5dfe1
 
 
 
 
 
6f1b85d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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()