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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
import seaborn as sns
|
| 5 |
+
from groq import Groq
|
| 6 |
+
import numpy as np
|
| 7 |
+
|
| 8 |
+
st.markdown(
|
| 9 |
+
"""
|
| 10 |
+
<style>
|
| 11 |
+
/* General app styling */
|
| 12 |
+
.stApp {
|
| 13 |
+
background-image: url("https://wallpapercave.com/wp/wp7335231.jpg");
|
| 14 |
+
background-size: cover;
|
| 15 |
+
background-position: center;
|
| 16 |
+
background-attachment: fixed;
|
| 17 |
+
color: white !important;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
/* Universal text color override */
|
| 21 |
+
body, div, p, span, label, h1, h2, h3, h4, h5, h6 {
|
| 22 |
+
color: white !important;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
/* Task option buttons styling */
|
| 26 |
+
.stButton > button {
|
| 27 |
+
background-color: green !important;
|
| 28 |
+
color: white !important;
|
| 29 |
+
border: none !important;
|
| 30 |
+
border-radius: 5px !important;
|
| 31 |
+
font-size: 16px !important;
|
| 32 |
+
font-weight: bold !important;
|
| 33 |
+
padding: 10px 20px !important;
|
| 34 |
+
}
|
| 35 |
+
.stButton > button:hover {
|
| 36 |
+
background-color: darkgreen !important;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
/* Sidebar styling */
|
| 40 |
+
[data-testid="stSidebar"] {
|
| 41 |
+
background-color: black !important;
|
| 42 |
+
color: white !important;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
/* Sidebar title */
|
| 46 |
+
[data-testid="stSidebar"] h1, [data-testid="stSidebar"] label {
|
| 47 |
+
color: white !important;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
/* Sidebar option buttons */
|
| 51 |
+
[data-testid="stSidebar"] .stRadio > div > label {
|
| 52 |
+
color: white !important;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/* Input parameter blocks (dropdowns, select boxes) text color */
|
| 56 |
+
.stSelectbox, .stDropdown, .stMultiselect {
|
| 57 |
+
color: black !important;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
.stTextInput input, .stTextArea textarea {
|
| 61 |
+
color: black !important;
|
| 62 |
+
background-color: white !important;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
/* Slider styling */
|
| 66 |
+
.stSlider .st-br {
|
| 67 |
+
background-color: black !important;
|
| 68 |
+
border-radius: 5px !important;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
/* Ensure sidebar is visible and black on mobile devices */
|
| 72 |
+
@media only screen and (max-width: 768px) {
|
| 73 |
+
/* Sidebar background */
|
| 74 |
+
[data-testid="stSidebar"] {
|
| 75 |
+
background-color: black !important;
|
| 76 |
+
display: block !important;
|
| 77 |
+
position: fixed !important;
|
| 78 |
+
width: 250px !important;
|
| 79 |
+
height: 100vh !important;
|
| 80 |
+
overflow-y: auto !important;
|
| 81 |
+
z-index: 1000 !important;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
/* Adjust the main content to avoid overlap with the sidebar */
|
| 85 |
+
.css-12oz5g7 {
|
| 86 |
+
margin-left: 260px !important; /* Make space for the fixed sidebar */
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
/* Ensure input text is black on mobile */
|
| 90 |
+
.stSelectbox div, .stDropdown div, .stMultiselect div {
|
| 91 |
+
color: black !important;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
.stTextInput input, .stTextArea textarea {
|
| 95 |
+
color: black !important;
|
| 96 |
+
background-color: white !important;
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
</style>
|
| 100 |
+
""", unsafe_allow_html=True
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
# Initialize the Groq client with the API key from Streamlit's secrets
|
| 106 |
+
GROQ_API_KEY = "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"
|
| 107 |
+
# Function to interact with the Groq API
|
| 108 |
+
def get_groq_response(user_input, model="llama-3.3-70b-versatile"):
|
| 109 |
+
chat_completion = client.chat.completions.create(
|
| 110 |
+
messages=[{"role": "user", "content": user_input}],
|
| 111 |
+
model=model
|
| 112 |
+
)
|
| 113 |
+
return chat_completion.choices[0].message.content
|
| 114 |
+
# Function to recommend panel type, power, and battery
|
| 115 |
+
def recommend_panel_and_battery():
|
| 116 |
+
st.title("π Solar Panel and Battery Recommendation")
|
| 117 |
+
st.markdown("""
|
| 118 |
+
Enter your home or office power requirements to get recommendations for the most suitable solar panel type, required power, and battery capacity.
|
| 119 |
+
""")
|
| 120 |
+
|
| 121 |
+
# Input Parameters
|
| 122 |
+
st.header("π Power Requirements")
|
| 123 |
+
rooms = st.number_input("Number of Rooms", value=2, step=1)
|
| 124 |
+
fans = st.number_input("Number of Fans", value=4, step=1)
|
| 125 |
+
lights = st.number_input("Number of Lights", value=8, step=1)
|
| 126 |
+
appliances_power = st.number_input("Other Appliances Power Consumption (Watts)", value=500, step=50)
|
| 127 |
+
|
| 128 |
+
# Calculate Total Power Requirement
|
| 129 |
+
fan_power = fans * 70 # Average power consumption per fan: 70W
|
| 130 |
+
light_power = lights * 10 # Average power consumption per light: 10W
|
| 131 |
+
total_power = rooms * (fan_power + light_power) + appliances_power # Total power in watts
|
| 132 |
+
total_power_kw = total_power / 1000 # Convert to kilowatts
|
| 133 |
+
|
| 134 |
+
st.write(f"**Total Power Requirement**: {total_power_kw:.2f} kW")
|
| 135 |
+
|
| 136 |
+
# Recommend Solar Panel Type and Power
|
| 137 |
+
st.header("π§ Recommended Solar Panel")
|
| 138 |
+
if total_power_kw <= 1:
|
| 139 |
+
panel_type = "Monocrystalline"
|
| 140 |
+
panel_area = 10 # Assume 10 mΒ² for small systems
|
| 141 |
+
elif total_power_kw <= 3:
|
| 142 |
+
panel_type = "Polycrystalline"
|
| 143 |
+
panel_area = 30 # Assume 30 mΒ² for medium systems
|
| 144 |
+
else:
|
| 145 |
+
panel_type = "Thin-Film"
|
| 146 |
+
panel_area = 50 # Assume 50 mΒ² for larger systems
|
| 147 |
+
|
| 148 |
+
st.write(f"**Recommended Solar Panel Type**: {panel_type}")
|
| 149 |
+
st.write(f"**Estimated Panel Area**: {panel_area} mΒ²")
|
| 150 |
+
|
| 151 |
+
# Recommend Battery Capacity
|
| 152 |
+
st.header("π Recommended Battery Capacity")
|
| 153 |
+
battery_hours = 6 # Assume 6 hours of backup required
|
| 154 |
+
battery_capacity = total_power_kw * battery_hours
|
| 155 |
+
st.write(f"**Recommended Battery Capacity**: {battery_capacity:.2f} kWh")
|
| 156 |
+
|
| 157 |
+
# Function to calculate solar energy
|
| 158 |
+
def calculate_solar_energy():
|
| 159 |
+
st.title("π Solar Energy System Design and Analysis")
|
| 160 |
+
st.markdown("""
|
| 161 |
+
This application helps in designing and analyzing solar energy systems.
|
| 162 |
+
Provide system specifications and site details to calculate potential power generation and energy storage.
|
| 163 |
+
""")
|
| 164 |
+
|
| 165 |
+
# Input Parameters
|
| 166 |
+
st.header("π§ Design Parameters")
|
| 167 |
+
panel_type = st.selectbox("Select Solar Panel Type", ["Monocrystalline", "Polycrystalline", "Thin-Film"])
|
| 168 |
+
|
| 169 |
+
panel_efficiency = st.number_input("Panel Efficiency (%)", value=18.0, step=0.1)
|
| 170 |
+
st.markdown("""
|
| 171 |
+
**Formula**: Panel Efficiency (%) = (Panel Power (kW) / Panel Area (mΒ²)) x 100
|
| 172 |
+
Panel efficiency refers to the percentage of sunlight converted into usable electricity by the panel.
|
| 173 |
+
""")
|
| 174 |
+
|
| 175 |
+
battery_capacity = st.number_input("Battery Storage Capacity (kWh)", value=10.0, step=0.5)
|
| 176 |
+
st.markdown("""
|
| 177 |
+
**Formula**: Battery Storage Capacity (kWh) = Energy Stored (kWh)
|
| 178 |
+
This is the total energy a battery can store for later use.
|
| 179 |
+
""")
|
| 180 |
+
|
| 181 |
+
battery_efficiency = st.number_input("Battery Efficiency (%)", value=90.0, step=0.5)
|
| 182 |
+
st.markdown("""
|
| 183 |
+
**Formula**: Battery Efficiency (%) = (Energy Discharged / Energy Charged) x 100
|
| 184 |
+
This refers to how efficiently energy can be discharged from the battery compared to how much energy was charged.
|
| 185 |
+
""")
|
| 186 |
+
|
| 187 |
+
tilt_angle = st.slider("Optimal Tilt Angle (Degrees)", min_value=0, max_value=45, value=30)
|
| 188 |
+
st.markdown("""
|
| 189 |
+
**Tilt Angle** refers to the angle at which solar panels are installed to maximize energy absorption.
|
| 190 |
+
""")
|
| 191 |
+
|
| 192 |
+
solar_insolation = st.number_input("Solar Insolation (kWh/mΒ²/day)", value=5.5, step=0.1)
|
| 193 |
+
st.markdown("""
|
| 194 |
+
**Solar Insolation** is the amount of solar energy received per unit area per day. This varies depending on geographic location.
|
| 195 |
+
""")
|
| 196 |
+
|
| 197 |
+
area = st.number_input("Total Panel Area (mΒ²)", value=50.0, step=1.0)
|
| 198 |
+
st.markdown("""
|
| 199 |
+
**Panel Area** refers to the total surface area of the solar panels installed.
|
| 200 |
+
""")
|
| 201 |
+
|
| 202 |
+
degradation_rate = st.number_input("Panel Degradation Rate (% per year)", value=0.5, step=0.1)
|
| 203 |
+
st.markdown("""
|
| 204 |
+
**Degradation Rate** refers to the percentage by which the panel's efficiency decreases over time.
|
| 205 |
+
""")
|
| 206 |
+
|
| 207 |
+
dust_loss = st.slider("Dust Loss Factor (%)", min_value=0, max_value=10, value=5)
|
| 208 |
+
st.markdown("""
|
| 209 |
+
**Dust Loss** is the percentage reduction in panel efficiency due to dust accumulation.
|
| 210 |
+
""")
|
| 211 |
+
|
| 212 |
+
shading_loss = st.slider("Shading Loss Factor (%)", min_value=0, max_value=10, value=3)
|
| 213 |
+
st.markdown("""
|
| 214 |
+
**Shading Loss** is the percentage reduction in energy generation due to partial shading of the panels.
|
| 215 |
+
""")
|
| 216 |
+
|
| 217 |
+
if st.button("Calculate Solar Energy"):
|
| 218 |
+
# Calculations
|
| 219 |
+
effective_area = area * (1 - (dust_loss + shading_loss) / 100)
|
| 220 |
+
daily_energy = solar_insolation * effective_area * (panel_efficiency / 100)
|
| 221 |
+
annual_energy = daily_energy * 365 * (1 - degradation_rate / 100)
|
| 222 |
+
battery_energy = battery_capacity * (battery_efficiency / 100)
|
| 223 |
+
|
| 224 |
+
st.header("β¨ Calculated Results")
|
| 225 |
+
st.write(f"Daily Energy Generation: {daily_energy:.2f} kWh")
|
| 226 |
+
st.write(f"Annual Energy Generation (First Year): {annual_energy:.2f} kWh")
|
| 227 |
+
st.write(f"Battery Storage Capacity: {battery_energy:.2f} kWh")
|
| 228 |
+
|
| 229 |
+
# Explanation for results using Groq
|
| 230 |
+
explanation_input = f"Explain the solar energy system results based on the following values: Daily Energy Generation = {daily_energy:.2f} kWh, Annual Energy Generation = {annual_energy:.2f} kWh, Battery Storage = {battery_energy:.2f} kWh."
|
| 231 |
+
explanation = get_groq_response(explanation_input)
|
| 232 |
+
st.markdown(f"### Detailed Explanation: {explanation}")
|
| 233 |
+
|
| 234 |
+
# Visualization: Seasonal Power Generation
|
| 235 |
+
months = np.arange(1, 13)
|
| 236 |
+
seasonal_insolation = np.array([
|
| 237 |
+
solar_insolation * (1 + 0.1 * np.sin((month - 1) * np.pi / 6)) for month in months
|
| 238 |
+
])
|
| 239 |
+
monthly_energy = seasonal_insolation * effective_area * (panel_efficiency / 100) * 30
|
| 240 |
+
|
| 241 |
+
fig, ax = plt.subplots()
|
| 242 |
+
ax.plot(months, monthly_energy, label='Monthly Energy Generation (kWh)', color='orange')
|
| 243 |
+
ax.set_xlabel('Month')
|
| 244 |
+
ax.set_ylabel('Energy (kWh)')
|
| 245 |
+
ax.set_title('Seasonal Power Generation')
|
| 246 |
+
ax.legend()
|
| 247 |
+
st.pyplot(fig)
|
| 248 |
+
|
| 249 |
+
# Visualization: Battery Storage Performance
|
| 250 |
+
time = np.linspace(0, 24, 100)
|
| 251 |
+
usage_pattern = battery_energy * (1 - 0.05 * np.sin(time * np.pi / 12))
|
| 252 |
+
|
| 253 |
+
fig2, ax2 = plt.subplots()
|
| 254 |
+
ax2.plot(time, usage_pattern, label='Battery Performance (kWh)', color='blue')
|
| 255 |
+
ax2.set_xlabel('Time (Hours)')
|
| 256 |
+
ax2.set_ylabel('Energy Stored (kWh)')
|
| 257 |
+
ax2.set_title('Battery Storage Over a Day')
|
| 258 |
+
ax2.legend()
|
| 259 |
+
st.pyplot(fig2)
|
| 260 |
+
# Function to generate system design for deep-sea tidal energy systems
|
| 261 |
+
def generate_system_design():
|
| 262 |
+
st.title("βοΈ Deep-Sea Tidal Energy System Design")
|
| 263 |
+
st.markdown("""
|
| 264 |
+
This application helps design deep-sea tidal energy systems using cutting-edge materials and advanced design techniques.
|
| 265 |
+
You will input various parameters related to materials, depth, and tidal velocity, and we will generate optimized system designs.
|
| 266 |
+
""")
|
| 267 |
+
|
| 268 |
+
# Inputs for system design
|
| 269 |
+
st.header("π Input Parameters")
|
| 270 |
+
material = st.selectbox("π οΈ Select Material for System Components",
|
| 271 |
+
["Titanium Alloys (e.g., Ti-6Al-4V)",
|
| 272 |
+
"Fiber-Reinforced Polymers (FRP)",
|
| 273 |
+
"Cermets",
|
| 274 |
+
"Advanced Coatings"])
|
| 275 |
+
depth = st.number_input("π Enter Depth (meters)", min_value=100, max_value=5000, step=100)
|
| 276 |
+
tidal_velocity = st.number_input("π¨ Enter Tidal Velocity (m/s)", min_value=0.1, max_value=10.0, step=0.1)
|
| 277 |
+
biofouling_control = st.selectbox("π± Select Biofouling Control Strategy",
|
| 278 |
+
["Fluoropolymers",
|
| 279 |
+
"Ultrasonic Cleaning Systems",
|
| 280 |
+
"Biocidal Coatings",
|
| 281 |
+
"Self-Cleaning Coatings",
|
| 282 |
+
"Electrochemical Anti-Fouling",
|
| 283 |
+
"Mechanical Cleaning Systems"])
|
| 284 |
+
|
| 285 |
+
location = st.selectbox("π Select Location for Tidal System", ["Tropical Ocean", "Temperate Ocean", "Polar Ocean"])
|
| 286 |
+
if location == "Tropical Ocean":
|
| 287 |
+
water_temperature = st.slider("π‘οΈ Water Temperature (Β°C)", min_value=25, max_value=30, value=28)
|
| 288 |
+
salinity = st.slider("π Salinity (ppt)", min_value=30, max_value=40, value=35)
|
| 289 |
+
tidal_pattern = st.selectbox("π Tidal Pattern", ["Semi-diurnal", "Diurnal"])
|
| 290 |
+
elif location == "Temperate Ocean":
|
| 291 |
+
water_temperature = st.slider("π‘οΈ Water Temperature (Β°C)", min_value=10, max_value=20, value=15)
|
| 292 |
+
salinity = st.slider("π Salinity (ppt)", min_value=20, max_value=30, value=25)
|
| 293 |
+
tidal_pattern = st.selectbox("π Tidal Pattern", ["Mixed", "Semi-diurnal"])
|
| 294 |
+
else:
|
| 295 |
+
water_temperature = st.slider("π‘οΈ Water Temperature (Β°C)", min_value=-2, max_value=10, value=5)
|
| 296 |
+
salinity = st.slider("π Salinity (ppt)", min_value=30, max_value=40, value=35)
|
| 297 |
+
tidal_pattern = st.selectbox("π Tidal Pattern", ["Diurnal", "Mixed"])
|
| 298 |
+
|
| 299 |
+
environmental_sensitivity = st.selectbox("π Select Environmental Sensitivity",
|
| 300 |
+
["Protected Ecosystem", "Unprotected Ecosystem"])
|
| 301 |
+
|
| 302 |
+
if st.button("π Generate System Design"):
|
| 303 |
+
user_input = f"Design a deep-sea tidal energy system for the following parameters: Material: {material}, Depth: {depth}m, Tidal Velocity: {tidal_velocity}m/s, Biofouling Control: {biofouling_control}, Location: {location}, Water Temperature: {water_temperature}Β°C, Salinity: {salinity}ppt, Tidal Pattern: {tidal_pattern}, Environmental Sensitivity: {environmental_sensitivity}."
|
| 304 |
+
system_design = get_groq_response(user_input)
|
| 305 |
+
st.header("β¨ Generated System Design")
|
| 306 |
+
st.write(system_design)
|
| 307 |
+
|
| 308 |
+
# Adding Visualization: A simple line chart to visualize input parameters
|
| 309 |
+
input_params = ['Depth', 'Tidal Velocity', 'Water Temp', 'Salinity']
|
| 310 |
+
input_values = [depth, tidal_velocity, water_temperature, salinity]
|
| 311 |
+
|
| 312 |
+
# Plotting a line chart for input parameters
|
| 313 |
+
fig2, ax2 = plt.subplots()
|
| 314 |
+
ax2.plot(input_params, input_values, marker='o', color='purple')
|
| 315 |
+
ax2.set_title('Tidal Energy System Design Inputs')
|
| 316 |
+
ax2.set_ylabel('Value')
|
| 317 |
+
st.pyplot(fig2)
|
| 318 |
+
|
| 319 |
+
# Function to calculate power generation for tidal plants
|
| 320 |
+
def calculate_power_generation():
|
| 321 |
+
st.title("β‘ Power Generation Calculation for Tidal Plant")
|
| 322 |
+
st.markdown("""
|
| 323 |
+
This application calculates the potential power generation of a tidal plant.
|
| 324 |
+
Formula used:
|
| 325 |
+
|
| 326 |
+
P = 1/2 * Ο * A * v^3 * Cβ
|
| 327 |
+
Where:
|
| 328 |
+
- P: Power (Watts)
|
| 329 |
+
- Ο: Water density (kg/mΒ³), typically 1025 kg/mΒ³ for seawater
|
| 330 |
+
- A: Area swept by turbine blades (mΒ²)
|
| 331 |
+
- v: Tidal current velocity (m/s)
|
| 332 |
+
- Cβ: Efficiency coefficient (dimensionless)
|
| 333 |
+
""")
|
| 334 |
+
|
| 335 |
+
# Input parameters
|
| 336 |
+
water_density = st.number_input("π§ Enter Water Density (kg/mΒ³)", value=1025, step=1)
|
| 337 |
+
swept_area = st.number_input("βοΈ Enter Swept Area of Turbine Blades (mΒ²)", value=1000, step=10)
|
| 338 |
+
velocity = st.number_input("π¨ Enter Tidal Current Velocity (m/s)", value=2.0, step=0.1)
|
| 339 |
+
efficiency = st.number_input("β‘ Enter Efficiency Coefficient (0 to 1)", value=0.4, step=0.01)
|
| 340 |
+
|
| 341 |
+
if st.button("π’ Calculate Power"):
|
| 342 |
+
power = 0.5 * water_density * swept_area * (velocity ** 3) * efficiency
|
| 343 |
+
st.header("β¨ Calculated Power Output")
|
| 344 |
+
st.write(f"The potential power generation is {power:.2f} Watts.")
|
| 345 |
+
|
| 346 |
+
# Adding Visualization: Displaying power as a curve chart
|
| 347 |
+
velocities = np.linspace(0, velocity, 100)
|
| 348 |
+
powers = 0.5 * water_density * swept_area * (velocities ** 3) * efficiency
|
| 349 |
+
|
| 350 |
+
fig3, ax3 = plt.subplots()
|
| 351 |
+
ax3.plot(velocities, powers, color='green')
|
| 352 |
+
ax3.set_title('Power Generation Curve')
|
| 353 |
+
ax3.set_xlabel('Tidal Current Velocity (m/s)')
|
| 354 |
+
ax3.set_ylabel('Power (Watts)')
|
| 355 |
+
st.pyplot(fig3)
|
| 356 |
+
|
| 357 |
+
# Function to generate corrosion-resistant coating suggestions
|
| 358 |
+
def generate_coating_suggestions():
|
| 359 |
+
st.title("π‘οΈ Corrosion-Resistant Coating Suggestions for Deep-Sea Tidal Energy Systems")
|
| 360 |
+
st.markdown("""
|
| 361 |
+
This application helps suggest the most suitable corrosion-resistant coatings for deep-sea tidal energy systems.
|
| 362 |
+
Input various environmental conditions and system material, and we will recommend the best coating to ensure system longevity.
|
| 363 |
+
""")
|
| 364 |
+
|
| 365 |
+
# Inputs for Environmental Conditions and Material Type
|
| 366 |
+
st.header("π Input Environmental Conditions and Material Type")
|
| 367 |
+
salinity = st.slider("π Salinity (ppt)", min_value=20, max_value=40, value=35, step=1)
|
| 368 |
+
temperature = st.slider("π‘οΈ Temperature (Β°C)", min_value=-10, max_value=40, value=20, step=1)
|
| 369 |
+
wave_force = st.slider("π¨ Wave and Current Forces (0: Low, 10: High)", min_value=0, max_value=10, value=5)
|
| 370 |
+
uv_exposure = st.slider("βοΈ UV Exposure (0: Low, 10: High)", min_value=0, max_value=10, value=5)
|
| 371 |
+
material_type = st.selectbox("π οΈ Select Material Type",
|
| 372 |
+
["Titanium Alloys (e.g., Ti-6Al-4V)",
|
| 373 |
+
"Stainless Steel",
|
| 374 |
+
"Aluminum Alloys",
|
| 375 |
+
"Fiber-Reinforced Polymers (FRP)",
|
| 376 |
+
"Other"])
|
| 377 |
+
|
| 378 |
+
if st.button("π Suggest Coating"):
|
| 379 |
+
user_input = f"Suggest a corrosion-resistant coating for a deep-sea tidal energy system with the following parameters: Salinity: {salinity}ppt, Temperature: {temperature}Β°C, Wave and Current Forces: {wave_force}/10, UV Exposure: {uv_exposure}/10, Material Type: {material_type}."
|
| 380 |
+
coating_suggestion = get_groq_response(user_input)
|
| 381 |
+
st.header("β¨ Recommended Corrosion-Resistant Coating")
|
| 382 |
+
st.write(coating_suggestion)
|
| 383 |
+
|
| 384 |
+
# Adding Visualization: A simple bar chart of the factors for better understanding
|
| 385 |
+
factors = ["Salinity", "Temperature", "Wave and Current Forces", "UV Exposure"]
|
| 386 |
+
values = [salinity, temperature, wave_force, uv_exposure]
|
| 387 |
+
|
| 388 |
+
# Plotting a bar chart for input factors
|
| 389 |
+
fig, ax = plt.subplots()
|
| 390 |
+
ax.bar(factors, values, color='skyblue')
|
| 391 |
+
ax.set_xlabel('Factors')
|
| 392 |
+
ax.set_ylabel('Value')
|
| 393 |
+
ax.set_title('Corrosion-Resistant Coating Factors')
|
| 394 |
+
ax.set_xticklabels(factors, rotation=45, ha='right') # Avoid overlap by rotating the labels
|
| 395 |
+
st.pyplot(fig)
|
| 396 |
+
|
| 397 |
+
# Wind power calculation function
|
| 398 |
+
def calculate_power(wind_speed, blade_length, efficiency):
|
| 399 |
+
air_density = 1.225 # kg/m^3
|
| 400 |
+
swept_area = np.pi * (blade_length ** 2)
|
| 401 |
+
power = 0.5 * air_density * swept_area * (wind_speed ** 3) * (efficiency / 100)
|
| 402 |
+
return power / 1000 # Convert to kW
|
| 403 |
+
|
| 404 |
+
# Function to plot wind profile
|
| 405 |
+
def plot_wind_profile(heights, wind_speeds):
|
| 406 |
+
df = pd.DataFrame({'Height': heights, 'Wind Speed': wind_speeds})
|
| 407 |
+
fig = px.line(
|
| 408 |
+
df,
|
| 409 |
+
x='Wind Speed',
|
| 410 |
+
y='Height',
|
| 411 |
+
markers=True,
|
| 412 |
+
line_shape='linear',
|
| 413 |
+
title="Wind Profile Analysis"
|
| 414 |
+
)
|
| 415 |
+
fig.update_traces(
|
| 416 |
+
line=dict(color='#0000FF', dash='solid'),
|
| 417 |
+
marker=dict(size=10, symbol='circle')
|
| 418 |
+
)
|
| 419 |
+
fig.update_layout(
|
| 420 |
+
xaxis_title="Wind Speed (m/s)",
|
| 421 |
+
yaxis_title="Height (m)"
|
| 422 |
+
)
|
| 423 |
+
st.plotly_chart(fig)
|
| 424 |
+
|
| 425 |
+
# Wind power calculator UI
|
| 426 |
+
def wind_power_calculator():
|
| 427 |
+
st.subheader("Wind Power Calculator")
|
| 428 |
+
st.markdown("""
|
| 429 |
+
Calculate wind power output based on key inputs:
|
| 430 |
+
- **Wind Speed** (m/s)
|
| 431 |
+
- **Blade Length** (m)
|
| 432 |
+
- **Efficiency** (%)
|
| 433 |
+
""")
|
| 434 |
+
|
| 435 |
+
# Inputs for calculation
|
| 436 |
+
wind_speed = st.number_input("Wind Speed (m/s)", min_value=0, max_value=30, value=12)
|
| 437 |
+
blade_length = st.number_input("Blade Length (m)", min_value=1, max_value=100, value=50)
|
| 438 |
+
efficiency = st.number_input("Efficiency (%)", min_value=1, max_value=100, value=85)
|
| 439 |
+
|
| 440 |
+
# Calculate and display power output
|
| 441 |
+
power_output = calculate_power(wind_speed, blade_length, efficiency)
|
| 442 |
+
st.write(f"**Calculated Power Output:** {power_output:.2f} kW")
|
| 443 |
+
|
| 444 |
+
# Plot power vs wind speed
|
| 445 |
+
wind_speeds = np.linspace(0, 30, 100)
|
| 446 |
+
powers = [calculate_power(ws, blade_length, efficiency) for ws in wind_speeds]
|
| 447 |
+
|
| 448 |
+
# Using seaborn for better aesthetics
|
| 449 |
+
sns.set(style="whitegrid")
|
| 450 |
+
fig, ax = plt.subplots(figsize=(10, 6))
|
| 451 |
+
sns.lineplot(x=wind_speeds, y=powers, ax=ax, label=f"Blade: {blade_length}m, Eff: {efficiency}%")
|
| 452 |
+
ax.set_title("Power Output vs Wind Speed", fontsize=16)
|
| 453 |
+
ax.set_xlabel("Wind Speed (m/s)", fontsize=12)
|
| 454 |
+
ax.set_ylabel("Power Output (kW)", fontsize=12)
|
| 455 |
+
ax.legend(fontsize=10)
|
| 456 |
+
st.pyplot(fig)
|
| 457 |
+
def turbine_recommendation_system():
|
| 458 |
+
"""
|
| 459 |
+
Single function to manage the Hydro-River Turbine Recommendation System, including API setup, querying,
|
| 460 |
+
and Streamlit UI interaction.
|
| 461 |
+
"""
|
| 462 |
+
|
| 463 |
+
# Example Preloaded Text (Simulating PDF Content)
|
| 464 |
+
PRELOADED_TEXT = """
|
| 465 |
+
Hydropower turbines are categorized based on head and flow rate. For a head range of 10β20 meters, Kaplan turbines are suitable,
|
| 466 |
+
whereas Pelton turbines work best for heads above 50 meters. Flow rates also play a significant role; high-flow, low-head applications
|
| 467 |
+
favor Francis turbines. Additional factors to consider when choosing a turbine include the specific design and efficiency, as well as
|
| 468 |
+
site-specific conditions such as environmental impact, cost, and operational requirements.
|
| 469 |
+
"""
|
| 470 |
+
|
| 471 |
+
# Step 2: Query System
|
| 472 |
+
def query_system(user_input):
|
| 473 |
+
# Use Groq API for response
|
| 474 |
+
response = client.chat.completions.create(
|
| 475 |
+
messages=[{"role": "user", "content": user_input}],
|
| 476 |
+
model="llama-3.3-70b-versatile",
|
| 477 |
+
)
|
| 478 |
+
return response.choices[0].message.content
|
| 479 |
+
|
| 480 |
+
# Step 3: Turbine Suggestion Logic
|
| 481 |
+
def turbine_suggestion(head, flow_rate, turbine_design, efficiency, site_conditions):
|
| 482 |
+
query = f"I have a head of {head} meters and a flow rate of {flow_rate} L/s. What turbine should I use?"
|
| 483 |
+
response = query_system(query)
|
| 484 |
+
|
| 485 |
+
# Add additional turbine specifications to the response
|
| 486 |
+
additional_info = (
|
| 487 |
+
f"\n\nπ To make a more informed decision, consider additional factors such as the specific design and efficiency of the turbines."
|
| 488 |
+
f"\nβοΈ Selected Design: {turbine_design}"
|
| 489 |
+
f"\nβοΈ Efficiency: {efficiency}"
|
| 490 |
+
f"\nβοΈ Site Conditions: {site_conditions}"
|
| 491 |
+
"\nπ Site-specific conditions like environmental impact, cost, and operational requirements also play a significant role."
|
| 492 |
+
)
|
| 493 |
+
|
| 494 |
+
return response + additional_info
|
| 495 |
+
|
| 496 |
+
# Step 4: Streamlit UI
|
| 497 |
+
st.title("βοΈ Hydro-River Turbine Recommendation System")
|
| 498 |
+
st.write(
|
| 499 |
+
"π Welcome to the Turbine Recommendation System! π\n\n"
|
| 500 |
+
"π‘ Select the **head**, **flow rate**, and other factors like **turbine design**, **efficiency**, and **site conditions** "
|
| 501 |
+
"to receive expert turbine recommendations tailored to your parameters.\n"
|
| 502 |
+
"π οΈ Powered by AI."
|
| 503 |
+
)
|
| 504 |
+
|
| 505 |
+
# Dropdown inputs for the user
|
| 506 |
+
head_options = [10, 20, 30, 40, 50, 100]
|
| 507 |
+
flow_rate_options = [100, 200, 300, 400, 500, 1000]
|
| 508 |
+
turbine_design_options = ["Kaplan", "Pelton", "Francis", "Mixed Design"]
|
| 509 |
+
efficiency_options = ["High", "Medium", "Low"]
|
| 510 |
+
site_conditions_options = ["Environmental Impact", "Cost", "Operational Requirements", "All of the Above"]
|
| 511 |
+
|
| 512 |
+
head = st.selectbox("π§ Select Head (meters)", head_options)
|
| 513 |
+
flow_rate = st.selectbox("π Select Flow Rate (L/s)", flow_rate_options)
|
| 514 |
+
turbine_design = st.selectbox("π§ Select Turbine Design", turbine_design_options)
|
| 515 |
+
efficiency = st.selectbox("β‘ Select Efficiency Level", efficiency_options)
|
| 516 |
+
site_conditions = st.selectbox("π Select Site Conditions", site_conditions_options)
|
| 517 |
+
|
| 518 |
+
if st.button('Get Turbine Suggestion'):
|
| 519 |
+
result = turbine_suggestion(head, flow_rate, turbine_design, efficiency, site_conditions)
|
| 520 |
+
st.subheader("Recommended Turbine:")
|
| 521 |
+
st.write(result)
|
| 522 |
+
|
| 523 |
+
|
| 524 |
+
import streamlit as st
|
| 525 |
+
|
| 526 |
+
import streamlit as st
|
| 527 |
+
|
| 528 |
+
# Main function
|
| 529 |
+
def main():
|
| 530 |
+
st.sidebar.title("πππ BluePlanet Energy")
|
| 531 |
+
|
| 532 |
+
# Add a detailed description to the main screen
|
| 533 |
+
st.title("π BluePlanet Energy Application")
|
| 534 |
+
st.write("""
|
| 535 |
+
This **Renewable Energy System Application** is designed to assist engineers, researchers, and enthusiasts
|
| 536 |
+
in evaluating and designing renewable energy systems. Whether you're working with solar, tidal, wind, or hydro energy,
|
| 537 |
+
this tool can provide insights and recommendations to optimize energy production and system performance.""")
|
| 538 |
+
|
| 539 |
+
# Add options to the sidebar for selecting tasks
|
| 540 |
+
option = st.sidebar.radio(
|
| 541 |
+
"Choose Task",
|
| 542 |
+
["Solar Energy Calculation", "Recommend Solar Panel and Battery", "Tidal System Design",
|
| 543 |
+
"Tidal Power Calculation", "Coating Suggestions for Tidal System", "Wind Power Calculator",
|
| 544 |
+
"Hydro-River Turbine Recommendation"]
|
| 545 |
+
)
|
| 546 |
+
|
| 547 |
+
# Perform task based on the selected option
|
| 548 |
+
if option == "Solar Energy Calculation":
|
| 549 |
+
calculate_solar_energy()
|
| 550 |
+
elif option == "Recommend Solar Panel and Battery":
|
| 551 |
+
recommend_panel_and_battery()
|
| 552 |
+
elif option == "Tidal System Design":
|
| 553 |
+
generate_system_design()
|
| 554 |
+
elif option == "Tidal Power Calculation":
|
| 555 |
+
calculate_power_generation()
|
| 556 |
+
elif option == "Coating Suggestions for Tidal System":
|
| 557 |
+
generate_coating_suggestions()
|
| 558 |
+
elif option == "Wind Power Calculator":
|
| 559 |
+
wind_power_calculator()
|
| 560 |
+
elif option == "Hydro-River Turbine Recommendation":
|
| 561 |
+
turbine_recommendation_system()
|
| 562 |
+
|
| 563 |
+
if __name__ == "__main__":
|
| 564 |
+
main()
|