Spaces:
Sleeping
Sleeping
import gradio as gr | |
import requests | |
def get_solar_data(api_key, latitude, longitude, system_capacity, tilt, azimuth, array_type, module_type, losses): | |
url = f'https://developer.nrel.gov/api/pvwatts/v6.json?api_key={api_key}&lat={latitude}&lon={longitude}&system_capacity={system_capacity}&azimuth={azimuth}&tilt={tilt}&array_type={array_type}&module_type={module_type}&losses={losses}' | |
response = requests.get(url) | |
data = response.json() | |
return data | |
def evaluate_solar_panels(api_key, latitude, longitude, annual_energy_consumption, panels): | |
suitable_panels = [] | |
for panel in panels: | |
solar_data = get_solar_data(api_key, latitude, longitude, panel['system_capacity'], panel.get('tilt', 0), panel.get('azimuth', 180), panel.get('array_type', 1), panel.get('module_type', 0), panel.get('losses', 14)) | |
annual_energy = solar_data['outputs']['ac_annual'] | |
if annual_energy >= annual_energy_consumption: | |
panel['annual_energy'] = annual_energy | |
suitable_panels.append(panel) | |
suitable_panels = sorted(suitable_panels, key=lambda x: x['cost']) | |
return suitable_panels | |
def solar_panel_evaluator(latitude, longitude, annual_energy_consumption): | |
api_key = '7jjEPVEpY5cnTvfB5CJweAPtauqkua4LpYUT0FEa' | |
panels = [ | |
{ | |
"image_url":"https://cwuzkkgiia.cloudimg.io/https://www.topregal.com/out/pictures/generated/product/1/1600_1100_100/210206_223307_SPM420-108_Solarpanel_12er-Paket.jpg?w=1600&h=1100&org_if_sml=1", | |
"url":"https://www.topregal.com/de/solartechnik/12-solarmodule-spm420-108-max-leistung-420-w-pro-modul-soloport.html", | |
"system_capacity": 5.04, | |
"tilt": 0, | |
"azimuth": 180, | |
"array_type": 0, | |
"module_type": 0, | |
"losses": 14, | |
"cost": 1499.90 | |
}, | |
{ | |
"image_url":"https://cwuzkkgiia.cloudimg.io/https://www.topregal.com/out/pictures/generated/product/1/1600_1100_100/212193_224517_SPM420-108_schwarz_Solarpanel_top-frontal-mit-Verpackung.jpg?w=1600&h=1100&org_if_sml=1", | |
"url":"https://www.topregal.com/de/solartechnik/36-solarmodule-spm420-108-schwarz-max-leistung-420-w-pro-modul-soloport.html", | |
"system_capacity": 15.12, | |
"tilt": 0, | |
"azimuth": 180, | |
"array_type": 0, | |
"module_type": 0, | |
"losses": 14, | |
"cost": 2899.90 | |
}, | |
{ | |
"image_url":"https://cwuzkkgiia.cloudimg.io/https://www.topregal.com/out/pictures/generated/product/1/1600_1100_100/100836_221221_Solarpanel_Gesamt-flex.jpg?w=1600&h=1100&org_if_sml=1", | |
"url":"https://www.topregal.com/de/solartechnik/solarmodul-fuer-cargobike-64-zellen-70-w.html", | |
"system_capacity": 0.07, | |
"tilt": 0, | |
"azimuth": 180, | |
"array_type": 0, | |
"module_type": 0, | |
"losses": 14, | |
"cost": 119.90 | |
}, | |
{ | |
"image_url":"https://media.elektroshopwagner.de/images/40/fa/9c/340318_0_0.jpg", | |
"url":"https://www.elektroshopwagner.de/product_info.php?info=p340318", | |
"system_capacity": 0.41, | |
"tilt": 30, | |
"azimuth": 180, | |
"array_type": 2, | |
"module_type": 0, | |
"losses": 14, | |
"cost": 699.00 | |
}, | |
{ | |
"image_url":"https://m.media-amazon.com/images/I/51W7OTj6+9L._AC_SX425_.jpg", | |
"url":"https://www.amazon.de/dp/B0B3RDKH1Z/", | |
"system_capacity": 0.4, | |
"tilt": 45, | |
"azimuth": 180, | |
"array_type": 3, | |
"module_type": 0, | |
"losses": 14, | |
"cost": 503.36 | |
}, | |
{ | |
"image_url":"https://m.media-amazon.com/images/I/71Ihgr3NphL._SX425_.jpg", | |
"url":"https://www.amazon.de/EPP-Solar%C2%AE-Balcony-Hoymiles-HMS-800W-2T-Inverter/dp/B0CK4RFCLM/", | |
"system_capacity": 2.0, | |
"tilt": 0, | |
"azimuth": 180, | |
"array_type": 1, | |
"module_type": 0, | |
"losses": 14, | |
"cost": 449.00 | |
}, | |
{ | |
"image_url":"https://m.media-amazon.com/images/I/71MzmX9rbSL._AC_SX569_.jpg", | |
"url":"https://www.amazon.de/PIANETA-Balcony-Station-Inverter-Throttle/dp/B0C9Q2L3MJ/", | |
"system_capacity": 0.83, | |
"tilt": 0, | |
"azimuth": 180, | |
"array_type": 1, | |
"module_type": 0, | |
"losses": 14, | |
"cost": 319.95 | |
}, | |
{ | |
"image_url":"https://m.media-amazon.com/images/I/71c7bVpYKuL._SX425_.jpg", | |
"url":"https://www.amazon.de/Portable-Monocrystalline-Charging-Controller-Waterproof/dp/B07JVJ47K3", | |
"system_capacity": 0.08, | |
"tilt": 0, | |
"azimuth": 180, | |
"array_type": 3, | |
"module_type": 0, | |
"losses": 14, | |
"cost": 69.77 | |
}, | |
{ | |
"image_url":"https://cwuzkkgiia.cloudimg.io/https://www.topregal.com/out/pictures/generated/product/1/1600_1100_100/211432_223307_SPM420-108_Solarpanel_top-frontal_mit_Verpackung.jpg?w=1600&h=1100&org_if_sml=1", | |
"url":"https://www.topregal.com/de/solartechnik/36-solarmodule-spm420-108-max-leistung-420-w-pro-modul-soloport.html?gmc=1&cur=0&gad_source=1&gclid=CjwKCAjw1K-zBhBIEiwAWeCOF4kI3I5NhMe-cWqb5vkPCBo6tiQzEf7XBsKdFD-dnh6YslCjfPXhwhoCasQQAvD_BwE", | |
"system_capacity": 15.12, | |
"tilt": 0, | |
"azimuth": 180, | |
"array_type": 0, | |
"module_type": 0, | |
"losses": 14, | |
"cost": 2209.90 | |
} | |
] | |
suitable_panels = evaluate_solar_panels(api_key, latitude, longitude, annual_energy_consumption, panels) | |
if suitable_panels: | |
output_html = f"<h2>Suitable Solar Panels for Latitude {latitude}, Longitude {longitude}:</h2>" | |
output_html += "<div style='display: flex; flex-wrap: wrap;'>" | |
for panel in suitable_panels: | |
output_html += "<div style='border: 1px solid #ccc; border-radius: 8px; padding: 10px; margin: 10px; width: 300px;'>" | |
output_html += f"<img src='{panel['image_url']}' style='max-width: 100%; border-radius: 8px;'>" | |
output_html += "<div style='margin-top: 10px;'>" | |
output_html += f"<strong>System Capacity:</strong> {panel.get('system_capacity', 'N/A')} kW<br>" | |
output_html += f"<strong>Tilt:</strong> {panel.get('tilt', 'N/A')} degrees<br>" | |
output_html += f"<strong>Azimuth:</strong> {panel.get('azimuth', 'N/A')} degrees<br>" | |
output_html += f"<strong>Array Type:</strong> {panel.get('array_type', 'N/A')}<br>" | |
output_html += f"<strong>Module Type:</strong> {panel.get('module_type', 'N/A')}<br>" | |
output_html += f"<strong>Losses:</strong> {panel.get('losses', 'N/A')}%<br>" | |
output_html += f"<strong>Cost:</strong> ${panel.get('cost', 'N/A')}<br>" | |
output_html += f"<strong>Annual Energy Output:</strong> {panel.get('annual_energy', 'N/A'):.2f} kWh<br>" | |
output_html += f"<a href='{panel.get('url', '#')}' style='text-decoration: none; color: blue;' target='_blank'>View</a>" | |
output_html += "</div>" | |
output_html += "</div>" | |
output_html += "</div>" | |
return output_html | |
else: | |
return "<p>No suitable solar panel setup found.</p>" | |
iface = gr.Interface( | |
fn=solar_panel_evaluator, | |
inputs=[ | |
gr.Number(label="Latitude", minimum=-90, maximum=90, value=40.7128), | |
gr.Number(label="Longitude", minimum=-180, maximum=180, value=-74.0060), | |
gr.Number(label="Annual Energy Consumption (kWh)", minimum=0, maximum=200000000,value=2000) | |
], | |
outputs=gr.HTML(), | |
title="Solar Panel Evaluator", | |
description="Find the best solar panels for your location based on energy needs and budget." | |
) | |
iface.launch() | |