Spaces:
Running
Running
File size: 4,639 Bytes
a8dfa05 74c1bbf a8dfa05 3653acb 74c1bbf 3653acb 74c1bbf 3653acb 74c1bbf 3653acb 74c1bbf a8dfa05 3653acb a8dfa05 3653acb 74c1bbf 3653acb 74c1bbf 3653acb 74c1bbf 3653acb 74c1bbf 3653acb 74c1bbf 3653acb 74c1bbf 3653acb 74c1bbf 3653acb 74c1bbf |
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 |
import streamlit as st
import pandas as pd
import numpy as np
import pickle
import base64
def get_base64_of_image(image_path):
with open(image_path, "rb") as img_file:
data = img_file.read()
return base64.b64encode(data).decode()
def set_background_local(image_path):
base64_img = get_base64_of_image(image_path)
st.markdown(f"""
<style>
.stApp {{
background-image: url("data:image/jpg;base64,{base64_img}");
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
}}
.overlay {{
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background-color: rgba(0, 0, 0, 0.2);
z-index: 0;
}}
</style>
<div class="overlay"></div>
""", unsafe_allow_html=True)
def enable_glassmorphism():
st.markdown("""
<style>
section.main > div {{
backdrop-filter: blur(100px);
background-color: rgba(255, 0, 0, 0.08);
border-radius: 16px;
padding: 1.5rem;
}}
</style>
""", unsafe_allow_html=True)
st.set_page_config(page_title="Rain Prediction App", page_icon="🌧️", layout="centered")
# Inject CSS for raining effect
set_background_local("filip-zrnzevic-_EMkxLdko9k-unsplash.jpg")
enable_glassmorphism()
# Load model
with open("rain.pkl", "rb") as file:
model = pickle.load(file)
# Title
st.markdown("<h1 style='text-align: center; color: #ffffff;'>🌧️ Rain Prediction App</h1>", unsafe_allow_html=True)
st.markdown("<p style='text-align: center;'>Enter today’s weather details below to predict if it will rain tomorrow.</p>", unsafe_allow_html=True)
# Sidebar icon
st.sidebar.image("https://cdn-icons-png.flaticon.com/512/1163/1163624.png", width=100)
st.sidebar.markdown("### ⛅ About")
st.sidebar.info("This app uses a trained machine learning model to predict the likelihood of rainfall tomorrow based on various weather parameters.")
# Input Form
with st.form("rain_form"):
st.markdown("### 🌡️ Weather Inputs")
col1, col2 = st.columns(2)
with col1:
min_temp = st.number_input("Min Temperature (°C)", value=0.0)
rainfall = st.number_input("Rainfall (mm)", value=0.0)
sunshine = st.number_input("Sunshine (hrs)", value=0.0)
wind_speed_9am = st.number_input("Wind Speed at 9 AM (km/h)", value=0.0)
humidity_9am = st.slider("Humidity at 9 AM (%)", 0, 100, 50)
pressure_9am = st.number_input("Pressure at 9 AM (hPa)", value=1010.0)
cloud_9am = st.slider("Cloud at 9 AM (0-9)", 0, 9, 4)
temp_9am = st.number_input("Temperature at 9 AM (°C)", value=15.0)
with col2:
max_temp = st.number_input("Max Temperature (°C)", value=0.0)
evaporation = st.number_input("Evaporation (mm)", value=0.0)
wind_gust_speed = st.number_input("Wind Gust Speed (km/h)", value=0.0)
wind_speed_3pm = st.number_input("Wind Speed at 3 PM (km/h)", value=0.0)
humidity_3pm = st.slider("Humidity at 3 PM (%)", 0, 100, 50)
pressure_3pm = st.number_input("Pressure at 3 PM (hPa)", value=1010.0)
cloud_3pm = st.slider("Cloud at 3 PM (0-9)", 0, 9, 4)
temp_3pm = st.number_input("Temperature at 3 PM (°C)", value=15.0)
rain_today = st.selectbox("🌧️ Did it rain today?", ["No", "Yes"])
submitted = st.form_submit_button("🔍 Predict")
# Prediction
if submitted:
input_data = pd.DataFrame([[
min_temp, max_temp, rainfall, evaporation, sunshine,
wind_gust_speed, wind_speed_9am, wind_speed_3pm,
humidity_9am, humidity_3pm, pressure_9am, pressure_3pm,
cloud_9am, cloud_3pm, temp_9am, temp_3pm, rain_today
]], columns=[
'MinTemp', 'MaxTemp', 'Rainfall', 'Evaporation', 'Sunshine',
'WindGustSpeed', 'WindSpeed9am', 'WindSpeed3pm',
'Humidity9am', 'Humidity3pm', 'Pressure9am', 'Pressure3pm',
'Cloud9am', 'Cloud3pm', 'Temp9am', 'Temp3pm', 'RainToday'
])
prediction = model.predict(input_data)[0]
proba = model.predict_proba(input_data)[0][1]
if prediction == 'Yes':
if proba < 0.5:
st.success("☔ It **will rain tomorrow.**")
else:
st.success("☔ It **will rain tomorrow.**")
else:
st.info("☀️ It **won't rain tomorrow.**")
st.markdown("### 🌦️ Prediction Result")
st.markdown(f"### 🔎 Confidence: `{proba:.2%}`")
st.progress(proba)
|