Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
def get_solar_data(api_key, latitude, longitude, system_capacity, tilt, azimuth, array_type, module_type, losses):
|
| 5 |
+
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}'
|
| 6 |
+
response = requests.get(url)
|
| 7 |
+
data = response.json()
|
| 8 |
+
return data
|
| 9 |
+
|
| 10 |
+
def evaluate_solar_panels(api_key, latitude, longitude, annual_energy_consumption, panels):
|
| 11 |
+
suitable_panels = []
|
| 12 |
+
|
| 13 |
+
for panel in panels:
|
| 14 |
+
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))
|
| 15 |
+
annual_energy = solar_data['outputs']['ac_annual']
|
| 16 |
+
|
| 17 |
+
if annual_energy >= annual_energy_consumption:
|
| 18 |
+
panel['annual_energy'] = annual_energy
|
| 19 |
+
suitable_panels.append(panel)
|
| 20 |
+
|
| 21 |
+
suitable_panels = sorted(suitable_panels, key=lambda x: x['cost'])
|
| 22 |
+
|
| 23 |
+
return suitable_panels
|
| 24 |
+
|
| 25 |
+
def solar_panel_evaluator(latitude, longitude, annual_energy_consumption):
|
| 26 |
+
api_key = '7jjEPVEpY5cnTvfB5CJweAPtauqkua4LpYUT0FEa'
|
| 27 |
+
|
| 28 |
+
panels = [
|
| 29 |
+
{
|
| 30 |
+
"image_url":"https://m.media-amazon.com/images/I/71Ihgr3NphL._SX425_.jpg",
|
| 31 |
+
"url":"https://www.amazon.de/EPP-Solar%C2%AE-Balcony-Hoymiles-HMS-800W-2T-Inverter/dp/B0CK4RFCLM/",
|
| 32 |
+
"system_capacity": 2.0,
|
| 33 |
+
"tilt": 0,
|
| 34 |
+
"azimuth": 180,
|
| 35 |
+
"array_type": 1,
|
| 36 |
+
"module_type": 0,
|
| 37 |
+
"losses": 14,
|
| 38 |
+
"cost": 449.00
|
| 39 |
+
},
|
| 40 |
+
{
|
| 41 |
+
"image_url":"https://m.media-amazon.com/images/I/71MzmX9rbSL._AC_SX569_.jpg",
|
| 42 |
+
"url":"https://www.amazon.de/PIANETA-Balcony-Station-Inverter-Throttle/dp/B0C9Q2L3MJ/",
|
| 43 |
+
"system_capacity": 0.83,
|
| 44 |
+
"tilt": 0,
|
| 45 |
+
"azimuth": 180,
|
| 46 |
+
"array_type": 1,
|
| 47 |
+
"module_type": 0,
|
| 48 |
+
"losses": 14,
|
| 49 |
+
"cost": 319.95
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"image_url":"https://m.media-amazon.com/images/I/71c7bVpYKuL._SX425_.jpg",
|
| 53 |
+
"url":"https://www.amazon.de/Portable-Monocrystalline-Charging-Controller-Waterproof/dp/B07JVJ47K3",
|
| 54 |
+
"system_capacity": 0.08,
|
| 55 |
+
"tilt": 0,
|
| 56 |
+
"azimuth": 180,
|
| 57 |
+
"array_type": 3,
|
| 58 |
+
"module_type": 0,
|
| 59 |
+
"losses": 14,
|
| 60 |
+
"cost": 69.77
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
"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",
|
| 64 |
+
"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",
|
| 65 |
+
"system_capacity": 15.12,
|
| 66 |
+
"tilt": 0,
|
| 67 |
+
"azimuth": 180,
|
| 68 |
+
"array_type": 0,
|
| 69 |
+
"module_type": 0,
|
| 70 |
+
"losses": 14,
|
| 71 |
+
"cost": 2209.90
|
| 72 |
+
}
|
| 73 |
+
]
|
| 74 |
+
|
| 75 |
+
suitable_panels = evaluate_solar_panels(api_key, latitude, longitude, annual_energy_consumption, panels)
|
| 76 |
+
|
| 77 |
+
if suitable_panels:
|
| 78 |
+
output_html = f"<h2>Suitable Solar Panels for Latitude {latitude}, Longitude {longitude}:</h2>"
|
| 79 |
+
output_html += "<div style='display: flex; flex-wrap: wrap;'>"
|
| 80 |
+
|
| 81 |
+
for panel in suitable_panels:
|
| 82 |
+
output_html += "<div style='border: 1px solid #ccc; border-radius: 8px; padding: 10px; margin: 10px; width: 300px;'>"
|
| 83 |
+
|
| 84 |
+
output_html += f"<img src='{panel['image_url']}' style='max-width: 100%; border-radius: 8px;'>"
|
| 85 |
+
|
| 86 |
+
output_html += "<div style='margin-top: 10px;'>"
|
| 87 |
+
output_html += f"<strong>System Capacity:</strong> {panel.get('system_capacity', 'N/A')} kW<br>"
|
| 88 |
+
output_html += f"<strong>Tilt:</strong> {panel.get('tilt', 'N/A')} degrees<br>"
|
| 89 |
+
output_html += f"<strong>Azimuth:</strong> {panel.get('azimuth', 'N/A')} degrees<br>"
|
| 90 |
+
output_html += f"<strong>Array Type:</strong> {panel.get('array_type', 'N/A')}<br>"
|
| 91 |
+
output_html += f"<strong>Module Type:</strong> {panel.get('module_type', 'N/A')}<br>"
|
| 92 |
+
output_html += f"<strong>Losses:</strong> {panel.get('losses', 'N/A')}%<br>"
|
| 93 |
+
output_html += f"<strong>Cost:</strong> ${panel.get('cost', 'N/A')}<br>"
|
| 94 |
+
output_html += f"<strong>Annual Energy Output:</strong> {panel.get('annual_energy', 'N/A'):.2f} kWh<br>"
|
| 95 |
+
output_html += f"<a href='{panel.get('url', '#')}' style='text-decoration: none; color: blue;' target='_blank'>View on Amazon</a>"
|
| 96 |
+
output_html += "</div>"
|
| 97 |
+
|
| 98 |
+
output_html += "</div>"
|
| 99 |
+
|
| 100 |
+
output_html += "</div>"
|
| 101 |
+
|
| 102 |
+
return output_html
|
| 103 |
+
else:
|
| 104 |
+
return "<p>No suitable solar panel setup found.</p>"
|
| 105 |
+
|
| 106 |
+
iface = gr.Interface(
|
| 107 |
+
fn=solar_panel_evaluator,
|
| 108 |
+
inputs=[
|
| 109 |
+
gr.Number(label="Latitude", minimum=-90, maximum=90, value=40.7128),
|
| 110 |
+
gr.Number(label="Longitude", minimum=-180, maximum=180, value=-74.0060),
|
| 111 |
+
gr.Number(label="Annual Energy Consumption (kWh)", minimum=0, maximum=200000000)
|
| 112 |
+
],
|
| 113 |
+
outputs=gr.HTML(),
|
| 114 |
+
title="Solar Panel Evaluator",
|
| 115 |
+
description="Find the best solar panels for your location based on energy needs and budget."
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
iface.launch()
|