Update src/streamlit_app.py
Browse files- src/streamlit_app.py +25 -35
src/streamlit_app.py
CHANGED
|
@@ -16,7 +16,7 @@ st.set_page_config(
|
|
| 16 |
# Absolute path handling for Docker/HF environment
|
| 17 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 18 |
|
| 19 |
-
# 2. Ultra-Stable CSS: Container Locking &
|
| 20 |
st.markdown("""
|
| 21 |
<style>
|
| 22 |
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;600;700;800&display=swap');
|
|
@@ -27,7 +27,7 @@ st.markdown("""
|
|
| 27 |
font-family: 'Plus Jakarta Sans', sans-serif;
|
| 28 |
}
|
| 29 |
|
| 30 |
-
/*
|
| 31 |
[data-testid="stSidebar"] {
|
| 32 |
background-color: #0f172a !important;
|
| 33 |
border-right: 1px solid #1e293b;
|
|
@@ -35,16 +35,11 @@ st.markdown("""
|
|
| 35 |
max-width: 260px !important;
|
| 36 |
}
|
| 37 |
|
| 38 |
-
/*
|
| 39 |
-
|
| 40 |
-
min-height:
|
| 41 |
-
max-height: 300px;
|
| 42 |
-
display: flex;
|
| 43 |
-
align-items: center;
|
| 44 |
-
justify-content: center;
|
| 45 |
background-color: rgba(15, 23, 42, 0.4);
|
| 46 |
-
border-radius:
|
| 47 |
-
border: 1px solid #1e293b;
|
| 48 |
overflow: hidden;
|
| 49 |
}
|
| 50 |
|
|
@@ -53,11 +48,11 @@ st.markdown("""
|
|
| 53 |
backdrop-filter: blur(16px);
|
| 54 |
border: 1px solid rgba(16, 185, 129, 0.2);
|
| 55 |
border-radius: 1rem;
|
| 56 |
-
padding:
|
| 57 |
text-align: center;
|
| 58 |
min-height: 100px;
|
| 59 |
}
|
| 60 |
-
.metric-card h2 { color: #10b981; font-size:
|
| 61 |
|
| 62 |
/* HIGH-VISIBILITY PRIMARY ACTION BUTTON */
|
| 63 |
div[class="stButton"] > button {
|
|
@@ -73,10 +68,6 @@ st.markdown("""
|
|
| 73 |
box-shadow: 0 0 20px rgba(16, 185, 129, 0.4);
|
| 74 |
transition: transform 0.2s ease;
|
| 75 |
}
|
| 76 |
-
div[class="stButton"] > button:hover {
|
| 77 |
-
transform: translateY(-2px);
|
| 78 |
-
box-shadow: 0 0 40px rgba(16, 185, 129, 0.6);
|
| 79 |
-
}
|
| 80 |
</style>
|
| 81 |
""", unsafe_allow_html=True)
|
| 82 |
|
|
@@ -115,19 +106,18 @@ def predict_disease(image):
|
|
| 115 |
st.markdown("""
|
| 116 |
<div style="padding-top: 1rem; margin-bottom: 2rem;">
|
| 117 |
<div style="color: #10b981; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.1em; margin-bottom: 0.5rem;">AI DIAGNOSTICS</div>
|
| 118 |
-
<h1 style="font-size: 2.
|
| 119 |
-
<p style="color: #94a3b8; font-size:
|
| 120 |
</div>
|
| 121 |
""", unsafe_allow_html=True)
|
| 122 |
|
| 123 |
-
# Fixed Metric Display
|
| 124 |
m1, m2 = st.columns(2)
|
| 125 |
with m1: st.markdown('<div class="metric-card"><h3>Species Library</h3><h2>38</h2></div>', unsafe_allow_html=True)
|
| 126 |
with m2: st.markdown('<div class="metric-card"><h3>CNN Accuracy</h3><h2>96.5%</h2></div>', unsafe_allow_html=True)
|
| 127 |
|
| 128 |
st.markdown("<br>", unsafe_allow_html=True)
|
| 129 |
|
| 130 |
-
# 5. Fixed
|
| 131 |
st.markdown("### Clinical Specimen Selection")
|
| 132 |
samples = [
|
| 133 |
("Apple Rot", "apple_black rot.jpeg"),
|
|
@@ -139,37 +129,37 @@ samples = [
|
|
| 139 |
if 'active_img' not in st.session_state:
|
| 140 |
st.session_state.active_img = None
|
| 141 |
|
| 142 |
-
# Stable
|
| 143 |
-
|
| 144 |
-
for i in
|
| 145 |
name, filename = samples[i]
|
| 146 |
img_path = os.path.join(BASE_DIR, filename)
|
| 147 |
-
with
|
| 148 |
if os.path.exists(img_path):
|
| 149 |
-
st.image(Image.open(img_path), width=
|
| 150 |
if st.button(f"Analyze {name}", key=f"btn_{i}"):
|
| 151 |
st.session_state.active_img = Image.open(img_path)
|
| 152 |
|
| 153 |
-
|
| 154 |
-
|
|
|
|
| 155 |
name, filename = samples[i]
|
| 156 |
img_path = os.path.join(BASE_DIR, filename)
|
| 157 |
-
with
|
| 158 |
if os.path.exists(img_path):
|
| 159 |
-
st.image(Image.open(img_path), width=
|
| 160 |
if st.button(f"Analyze {name}", key=f"btn_{i}"):
|
| 161 |
st.session_state.active_img = Image.open(img_path)
|
| 162 |
|
| 163 |
st.divider()
|
| 164 |
|
| 165 |
-
# 6.
|
| 166 |
col_up, col_res = st.columns([1.2, 1])
|
| 167 |
with col_up:
|
| 168 |
-
# RIGID CONTAINER height is now the primary UI anchor
|
| 169 |
if st.session_state.active_img:
|
| 170 |
-
st.image(st.session_state.active_img, width=320)
|
| 171 |
else:
|
| 172 |
-
st.markdown('<div style="border: 2px dashed #1e293b; border-radius: 1rem; height: 300px; display: flex; align-items: center; justify-content: center; background: rgba(15, 23, 42, 0.4); color: #64748b; text-align: center; padding: 20px;">Select a clinical specimen above to begin
|
| 173 |
|
| 174 |
with col_res:
|
| 175 |
if st.session_state.active_img and model:
|
|
@@ -187,7 +177,7 @@ with col_res:
|
|
| 187 |
|
| 188 |
# Footer
|
| 189 |
st.markdown("""
|
| 190 |
-
<div style="margin-top: 3rem; padding: 2rem; border-top: 1px solid #1e293b; text-align: center; color: #475569; font-size: 0.65rem; text-transform: uppercase;
|
| 191 |
SYSTEMS ENGINEER: RMUTUA | PRECISION AGRO-PATHOLOGY
|
| 192 |
</div>
|
| 193 |
""", unsafe_allow_html=True)
|
|
|
|
| 16 |
# Absolute path handling for Docker/HF environment
|
| 17 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 18 |
|
| 19 |
+
# 2. Ultra-Stable CSS: Rigid Container Locking & Jitter Fixes
|
| 20 |
st.markdown("""
|
| 21 |
<style>
|
| 22 |
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;600;700;800&display=swap');
|
|
|
|
| 27 |
font-family: 'Plus Jakarta Sans', sans-serif;
|
| 28 |
}
|
| 29 |
|
| 30 |
+
/* SIDEBAR LOCK: Strict width prevents horizontal jitter */
|
| 31 |
[data-testid="stSidebar"] {
|
| 32 |
background-color: #0f172a !important;
|
| 33 |
border-right: 1px solid #1e293b;
|
|
|
|
| 35 |
max-width: 260px !important;
|
| 36 |
}
|
| 37 |
|
| 38 |
+
/* IMAGE CONTAINER LOCK: Reserves height to prevent shaking */
|
| 39 |
+
[data-testid="stImage"] {
|
| 40 |
+
min-height: 200px;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
background-color: rgba(15, 23, 42, 0.4);
|
| 42 |
+
border-radius: 0.8rem;
|
|
|
|
| 43 |
overflow: hidden;
|
| 44 |
}
|
| 45 |
|
|
|
|
| 48 |
backdrop-filter: blur(16px);
|
| 49 |
border: 1px solid rgba(16, 185, 129, 0.2);
|
| 50 |
border-radius: 1rem;
|
| 51 |
+
padding: 1.5rem;
|
| 52 |
text-align: center;
|
| 53 |
min-height: 100px;
|
| 54 |
}
|
| 55 |
+
.metric-card h2 { color: #10b981; font-size: 2rem; font-weight: 800; margin: 0; }
|
| 56 |
|
| 57 |
/* HIGH-VISIBILITY PRIMARY ACTION BUTTON */
|
| 58 |
div[class="stButton"] > button {
|
|
|
|
| 68 |
box-shadow: 0 0 20px rgba(16, 185, 129, 0.4);
|
| 69 |
transition: transform 0.2s ease;
|
| 70 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
</style>
|
| 72 |
""", unsafe_allow_html=True)
|
| 73 |
|
|
|
|
| 106 |
st.markdown("""
|
| 107 |
<div style="padding-top: 1rem; margin-bottom: 2rem;">
|
| 108 |
<div style="color: #10b981; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.1em; margin-bottom: 0.5rem;">AI DIAGNOSTICS</div>
|
| 109 |
+
<h1 style="font-size: 2.8rem; font-weight: 800; color: #f8fafc; margin: 0; letter-spacing: -0.04em;">Precision Plant <span style="color: #10b981;">Pathology</span></h1>
|
| 110 |
+
<p style="color: #94a3b8; font-size: 1rem;">Diagnostic identification system for botanical pathogens.</p>
|
| 111 |
</div>
|
| 112 |
""", unsafe_allow_html=True)
|
| 113 |
|
|
|
|
| 114 |
m1, m2 = st.columns(2)
|
| 115 |
with m1: st.markdown('<div class="metric-card"><h3>Species Library</h3><h2>38</h2></div>', unsafe_allow_html=True)
|
| 116 |
with m2: st.markdown('<div class="metric-card"><h3>CNN Accuracy</h3><h2>96.5%</h2></div>', unsafe_allow_html=True)
|
| 117 |
|
| 118 |
st.markdown("<br>", unsafe_allow_html=True)
|
| 119 |
|
| 120 |
+
# 5. Fixed 2-Row, 2-Column Clinical Specimen Grid
|
| 121 |
st.markdown("### Clinical Specimen Selection")
|
| 122 |
samples = [
|
| 123 |
("Apple Rot", "apple_black rot.jpeg"),
|
|
|
|
| 129 |
if 'active_img' not in st.session_state:
|
| 130 |
st.session_state.active_img = None
|
| 131 |
|
| 132 |
+
# Stable Row 1 (Specimens 1 & 2)
|
| 133 |
+
r1_col1, r1_col2 = st.columns(2)
|
| 134 |
+
for i, col in enumerate([r1_col1, r1_col2]):
|
| 135 |
name, filename = samples[i]
|
| 136 |
img_path = os.path.join(BASE_DIR, filename)
|
| 137 |
+
with col:
|
| 138 |
if os.path.exists(img_path):
|
| 139 |
+
st.image(Image.open(img_path), width=130) # Fixed size
|
| 140 |
if st.button(f"Analyze {name}", key=f"btn_{i}"):
|
| 141 |
st.session_state.active_img = Image.open(img_path)
|
| 142 |
|
| 143 |
+
# Stable Row 2 (Specimens 3 & 4)
|
| 144 |
+
r2_col1, r2_col2 = st.columns(2)
|
| 145 |
+
for i, col in enumerate([r2_col1, r2_col2], start=2):
|
| 146 |
name, filename = samples[i]
|
| 147 |
img_path = os.path.join(BASE_DIR, filename)
|
| 148 |
+
with col:
|
| 149 |
if os.path.exists(img_path):
|
| 150 |
+
st.image(Image.open(img_path), width=130) # Fixed size
|
| 151 |
if st.button(f"Analyze {name}", key=f"btn_{i}"):
|
| 152 |
st.session_state.active_img = Image.open(img_path)
|
| 153 |
|
| 154 |
st.divider()
|
| 155 |
|
| 156 |
+
# 6. Analysis Hub (No Uploader Section)
|
| 157 |
col_up, col_res = st.columns([1.2, 1])
|
| 158 |
with col_up:
|
|
|
|
| 159 |
if st.session_state.active_img:
|
| 160 |
+
st.image(st.session_state.active_img, width=320) # Rigid display width
|
| 161 |
else:
|
| 162 |
+
st.markdown('<div style="border: 2px dashed #1e293b; border-radius: 1rem; height: 300px; display: flex; align-items: center; justify-content: center; background: rgba(15, 23, 42, 0.4); color: #64748b; text-align: center; padding: 20px;">Select a clinical specimen above to begin analysis</div>', unsafe_allow_html=True)
|
| 163 |
|
| 164 |
with col_res:
|
| 165 |
if st.session_state.active_img and model:
|
|
|
|
| 177 |
|
| 178 |
# Footer
|
| 179 |
st.markdown("""
|
| 180 |
+
<div style="margin-top: 3rem; padding: 2rem; border-top: 1px solid #1e293b; text-align: center; color: #475569; font-size: 0.65rem; text-transform: uppercase;">
|
| 181 |
SYSTEMS ENGINEER: RMUTUA | PRECISION AGRO-PATHOLOGY
|
| 182 |
</div>
|
| 183 |
""", unsafe_allow_html=True)
|