File size: 7,908 Bytes
7bc9cd1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96a29a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e452cac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7bc9cd1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2225151
7bc9cd1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2225151
7bc9cd1
 
 
 
 
 
 
 
 
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
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()