Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| import numpy as np | |
| import requests | |
| # Helper Functions | |
| def get_solar_data(location): | |
| """Mock solar irradiance data based on location.""" | |
| solar_irradiance = {'USA': 5.5, 'India': 5.8, 'Germany': 3.2} # kWh/m²/day | |
| return solar_irradiance.get(location, 4.0) # Default value | |
| def design_system(data, energy_needs, preference, location): | |
| """Design a renewable energy system based on user inputs.""" | |
| solar_data = get_solar_data(location) | |
| if preference == "solar": | |
| solar_energy = data[data['Type_of_Renewable_Energy'] == 'Solar'] | |
| if not solar_energy.empty: | |
| recommended = solar_energy.iloc[0] | |
| panels_needed = np.ceil(energy_needs / (recommended['Energy_Production_MWh'] / 365)) | |
| return (f"Use {panels_needed} Solar systems with an installed capacity of {recommended['Installed_Capacity_MW']} MW.\n" | |
| f"Initial Investment: ${recommended['Initial_Investment_USD']}\nGHG Emission Reduction: {recommended['GHG_Emission_Reduction_tCO2e']} tCO2e/year.") | |
| elif preference == "wind": | |
| wind_energy = data[data['Type_of_Renewable_Energy'] == 'Wind'] | |
| if not wind_energy.empty: | |
| recommended = wind_energy.iloc[0] | |
| turbines_needed = np.ceil(energy_needs / (recommended['Energy_Production_MWh'] / 365)) | |
| return (f"Use {turbines_needed} Wind turbines with an installed capacity of {recommended['Installed_Capacity_MW']} MW.\n" | |
| f"Initial Investment: ${recommended['Initial_Investment_USD']}\nGHG Emission Reduction: {recommended['GHG_Emission_Reduction_tCO2e']} tCO2e/year.") | |
| return "Hybrid or other systems recommendation coming soon!" | |
| def generate_explanation(system_design, api_key): | |
| """Generate a detailed explanation using the Groq API.""" | |
| headers = {"Authorization": f"Bearer {api_key}"} | |
| payload = {"prompt": f"Explain the following renewable energy system design: {system_design}", "max_tokens": 150} | |
| response = requests.post("https://api.groq.com/v1/chat/completions", headers=headers, json=payload) | |
| if response.status_code == 200: | |
| return response.json().get('choices')[0]['text'] | |
| else: | |
| return "Error generating explanation. Please check your API key and try again." | |
| # Streamlit App | |
| st.title("Renewable Energy System Designer") | |
| # File Upload | |
| uploaded_file = st.file_uploader("Upload your dataset (CSV file)", type="csv") | |
| if uploaded_file: | |
| data = pd.read_csv(uploaded_file) | |
| st.write("Dataset Preview:", data.head()) | |
| # User Inputs | |
| location = st.text_input("Enter your location (e.g., USA):") | |
| energy_needs = st.number_input("Enter your daily energy needs in MWh:", min_value=0.0, step=0.1) | |
| preference = st.selectbox("Select your preference:", ["solar", "wind"]) | |
| # API Key | |
| api_key = st.text_input("Enter your Groq API key:") | |
| if st.button("Generate System Design"): | |
| if data is not None and location and energy_needs > 0 and api_key: | |
| system_design = design_system(data, energy_needs, preference, location) | |
| explanation = generate_explanation(system_design, api_key) | |
| st.subheader("Recommended System Design") | |
| st.write(system_design) | |
| st.subheader("Explanation") | |
| st.write(explanation) | |
| else: | |
| st.error("Please fill in all inputs and upload a valid dataset!") | |