maize_detection_webapp / src /streamlit_app.py
teta-htpp's picture
Update src/streamlit_app.py
c4f2a0b verified
Raw History Blame Contribute Delete
3.63 kB
import streamlit as st
import pandas as pd
import numpy as np
st.set_page_config(page_title="Maize Lens", layout="wide")
---------- SESSION STATE NAV ----------
if "page" not in st.session_state: st.session_state.page = "Home"
---------- STYLING ----------
st.markdown("""
<style>
body {background-color: #f5f7f2;}
.card {
padding: 20px;
border-radius: 20px;
background: linear-gradient(135deg, #ffffff, #f1f8e9);
box-shadow: 0 6px 15px rgba(0,0,0,0.08);
}
.metric {
font-size: 22px;
font-weight: bold;
color: #2e7d32;
}
.button {
background-color: #fdd835;
padding: 10px 20px;
border-radius: 10px;
text-align: center;
font-weight: bold;
}
.title {
font-size: 30px;
font-weight: bold;
color: #2e7d32;
}
</style>""", unsafe_allow_html=True)
---------- SIDEBAR ----------
st.sidebar.title("🌽 Maize Lens") page = st.sidebar.radio("Navigation", ["Home", "Dashboard", "Prediction"], index=["Home","Dashboard","Prediction"].index(st.session_state.page)) st.session_state.page = page
---------- HOME ----------
if page == "Home": st.markdown("<div class='title'>🌽 Maize Lens</div>", unsafe_allow_html=True) st.write("### See your maize future clearly")
st.image("https://images.unsplash.com/photo-1601597111158-2fceff292cdc", use_column_width=True)
if st.button("Get Started"):
st.session_state.page = "Dashboard"
st.rerun()
---------- DASHBOARD ----------
elif page == "Dashboard": st.markdown("<div class='title'>Dashboard</div>", unsafe_allow_html=True) st.write("Welcome back!")
col1, col2 = st.columns(2)
col3, col4 = st.columns(2)
with col1:
st.markdown("<div class='card'><div class='metric'>🌡️ 27°C</div><div>Temperature (7-day)</div></div>", unsafe_allow_html=True)
with col2:
st.markdown("<div class='card'><div class='metric'>🌧️ 15 mm</div><div>Rainfall (7-day)</div></div>", unsafe_allow_html=True)
with col3:
st.markdown("<div class='card'><div class='metric'>💧 75%</div><div>Humidity</div></div>", unsafe_allow_html=True)
with col4:
st.markdown("<div class='card'><div class='metric'>🦠 0.9 (High)</div><div>Fungal Index</div></div>", unsafe_allow_html=True)
st.markdown("### Disease Prediction")
st.markdown("""
<div class='card'>
<b>🌽 Northern Leaf Blight</b> - <span style='color:red;'>High Risk</span><br><br>
✔ Scout your field twice this week<br>
✔ Remove heavily infected leaves<br>
✔ Consult extension staff
</div>
""", unsafe_allow_html=True)
if st.button("See Full Report"):
st.info("Detailed analytics coming soon...")
---------- PREDICTION ----------
elif page == "Prediction": st.markdown("<div class='title'>Disease Prediction</div>", unsafe_allow_html=True)
col1, col2 = st.columns(2)
with col1:
temp = st.slider("Temperature (°C)", 10, 45, 27)
rainfall = st.slider("Rainfall (mm)", 0, 50, 15)
with col2:
humidity = st.slider("Humidity (%)", 30, 100, 75)
risk_score = (temp/45) + (humidity/100) + (rainfall/50)
st.markdown("### Prediction Result")
if risk_score > 2:
st.markdown("<div class='card'><b style='color:red;'>High Risk - Northern Leaf Blight</b></div>", unsafe_allow_html=True)
elif risk_score > 1.5:
st.markdown("<div class='card'><b style='color:orange;'>Moderate Risk</b></div>", unsafe_allow_html=True)
else:
st.markdown("<div class='card'><b style='color:green;'>Low Risk</b></div>", unsafe_allow_html=True)
# Graph
np.random.seed(42)
data = pd.DataFrame({
"Day": range(1, 8),
"Temperature": np.linspace(24, 32, 7),
"Humidity": np.linspace(70, 80, 7)
})
st.line_chart(data.set_index("Day"))