FajarHidaa commited on
Commit
06e86d6
·
verified ·
1 Parent(s): b2ddeff

Delete src/ui/components.py

Browse files
Files changed (1) hide show
  1. src/ui/components.py +0 -345
src/ui/components.py DELETED
@@ -1,345 +0,0 @@
1
- """
2
- Human+ Reusable UI Components
3
- Prinsip refactor: gunakan Streamlit native sebanyak mungkin.
4
- HTML hanya untuk elemen dekoratif (hero logo, gradient) yang
5
- tidak ada padanan native-nya.
6
- """
7
-
8
- import streamlit as st
9
- from typing import Literal, Optional
10
- from ui.theme import COLORS, BIOMARKER_STATUS, PROTOCOL_SECTIONS
11
-
12
-
13
- # ════════════════════════════════════════════════
14
- # HERO & NAVIGATION
15
- # ════════════════════════════════════════════════
16
-
17
- def render_hero(
18
- subtitle: str = "Upload hasil lab Anda → Dapatkan rekomendasi IV drip & protocol personal"
19
- ):
20
- """
21
- Hero header — HTML dipertahankan hanya untuk gradient text logo
22
- yang tidak bisa dibuat dengan st.title() biasa.
23
- """
24
- st.markdown(
25
- """
26
- <div style="text-align:center; padding: 32px 0 8px;">
27
- <p style="
28
- font-size:0.72rem; font-weight:600;
29
- letter-spacing:0.2em; text-transform:uppercase;
30
- color:#4a4a6a; margin-bottom:6px;
31
- ">Human+ Bali · By Benjamin White</p>
32
- <h1 style="
33
- font-family:'DM Serif Display', Georgia, serif;
34
- font-size:2.6rem; font-weight:900; line-height:1;
35
- background: linear-gradient(135deg, #a78bfa, #38bdf8, #22d3ee);
36
- -webkit-background-clip: text; -webkit-text-fill-color: transparent;
37
- background-clip: text; margin:0 0 8px;
38
- ">Lab-to-Protocol</h1>
39
- </div>
40
- """,
41
- unsafe_allow_html=True,
42
- )
43
- st.caption(f"🧬 {subtitle}")
44
- st.write("")
45
-
46
-
47
- def render_step_indicator(current_step: int):
48
- """
49
- 3-step progress indicator menggunakan st.columns + native markdown.
50
- Tidak ada HTML kompleks — hanya emoji dan teks.
51
- """
52
- steps = ["📤 Upload", "🔬 Analisis", "📋 Protocol"]
53
- cols = st.columns(3)
54
-
55
- for i, (col, label) in enumerate(zip(cols, steps), 1):
56
- with col:
57
- if i < current_step:
58
- # Done
59
- st.markdown(
60
- f"<div style='text-align:center; color:#10b981; font-size:0.75rem; font-weight:700'>✓ {label}</div>",
61
- unsafe_allow_html=True,
62
- )
63
- elif i == current_step:
64
- # Active
65
- st.markdown(
66
- f"<div style='text-align:center; color:#8b5cf6; font-size:0.75rem; font-weight:700'>◉ {label}</div>",
67
- unsafe_allow_html=True,
68
- )
69
- else:
70
- # Pending
71
- st.markdown(
72
- f"<div style='text-align:center; color:#4a4a6a; font-size:0.75rem;'>○ {label}</div>",
73
- unsafe_allow_html=True,
74
- )
75
-
76
- st.divider()
77
-
78
-
79
- def render_trust_badges():
80
- """Trust badges menggunakan st.columns — tidak ada HTML."""
81
- col1, col2, col3, col4 = st.columns(4)
82
- badges = [
83
- ("🔒", "Stateless"),
84
- ("🗑️", "Tidak disimpan"),
85
- ("⚡", "Gemini AI"),
86
- ("🌿", "Human+ Bali"),
87
- ]
88
- for col, (icon, text) in zip([col1, col2, col3, col4], badges):
89
- with col:
90
- st.caption(f"{icon} {text}")
91
- st.write("")
92
-
93
-
94
- def render_section_label(text: str, icon: str = ""):
95
- """
96
- Section label menggunakan st.markdown dengan minimal styling —
97
- hanya border-left yang tidak ada padanan native.
98
- """
99
- prefix = f"{icon} " if icon else ""
100
- st.markdown(
101
- f"<p style='font-size:0.7rem; font-weight:700; letter-spacing:0.14em; "
102
- f"color:#8b8ba7; border-left:2px solid #8b5cf6; padding-left:8px; "
103
- f"margin:20px 0 10px;'>{prefix}{text}</p>",
104
- unsafe_allow_html=True,
105
- )
106
-
107
-
108
- # ════════════════════════════════════════════════
109
- # LOADING STATES
110
- # ════════════════════════════════════════════════
111
-
112
- ANALYSIS_STEPS = [
113
- "Membaca dokumen PDF",
114
- "Mengidentifikasi biomarker",
115
- "Mencocokkan dengan range Human+",
116
- "Menyusun temuan utama",
117
- ]
118
-
119
- PROTOCOL_STEPS = [
120
- "Mengambil knowledge base Human+",
121
- "Menyesuaikan dengan hasil lab Anda",
122
- "Menyusun rekomendasi IV drip",
123
- "Finalisasi protocol personal",
124
- ]
125
-
126
-
127
- def render_loading_steps(steps: list[str], current_index: int):
128
- """
129
- Loading steps menggunakan st.markdown per baris — lebih stabil
130
- dari satu blok HTML besar.
131
- """
132
- for i, step in enumerate(steps):
133
- if i < current_index:
134
- icon, color = "✓", "#10b981"
135
- elif i == current_index:
136
- icon, color = "◉", "#8b5cf6"
137
- else:
138
- icon, color = "○", "#4a4a6a"
139
-
140
- st.markdown(
141
- f"<p style='color:{color}; font-size:0.85rem; margin:4px 0;'>"
142
- f"{icon} &nbsp; {step}</p>",
143
- unsafe_allow_html=True,
144
- )
145
-
146
-
147
- def render_progress_bar(value: float, label: str = ""):
148
- """Native st.progress — tidak butuh HTML sama sekali."""
149
- if label:
150
- st.caption(label)
151
- st.progress(value)
152
-
153
-
154
- # ════════════════════════════════════════════════
155
- # BIOMARKER COMPONENTS
156
- # ════════════════════════════════════════════════
157
-
158
- StatusType = Literal["optimal", "warning", "danger", "neutral"]
159
-
160
- _STATUS_EMOJI = {
161
- "optimal": "🟢",
162
- "warning": "🟡",
163
- "danger": "🔴",
164
- "neutral": "⚪",
165
- }
166
-
167
- _STATUS_COLOR = {
168
- "optimal": "#10b981",
169
- "warning": "#f59e0b",
170
- "danger": "#ef4444",
171
- "neutral": "#6b7280",
172
- }
173
-
174
-
175
- def render_biomarker_row(
176
- name: str,
177
- value: str,
178
- unit: str,
179
- status: StatusType,
180
- reference: str = "",
181
- ):
182
- """
183
- Biomarker row menggunakan st.columns + st.metric.
184
- Jauh lebih stabil dari HTML div, metric punya built-in styling.
185
- Border kiri status tetap pakai satu baris HTML minimal.
186
- """
187
- color = _STATUS_COLOR.get(status, "#6b7280")
188
- emoji = _STATUS_EMOJI.get(status, "⚪")
189
-
190
- # Border kiri berwarna — satu-satunya HTML di sini
191
- st.markdown(
192
- f"<div style='border-left:3px solid {color}; padding-left:10px; margin:2px 0 0;'>",
193
- unsafe_allow_html=True,
194
- )
195
-
196
- col_name, col_val = st.columns([3, 1])
197
- with col_name:
198
- st.markdown(f"**{emoji} {name}**")
199
- if reference:
200
- st.caption(f"Target Human+: {reference}")
201
- with col_val:
202
- st.metric(
203
- label=unit,
204
- value=value,
205
- label_visibility="visible",
206
- )
207
-
208
- st.markdown("</div>", unsafe_allow_html=True)
209
- st.write("")
210
-
211
-
212
- def render_biomarker_summary_banner(optimal: int, warning: int, danger: int):
213
- """
214
- Summary count banner menggunakan st.columns + st.metric native.
215
- Tidak ada HTML sama sekali.
216
- """
217
- total = optimal + warning + danger
218
- st.caption(f"🔬 RINGKASAN BIOMARKER — {total} MARKER DIANALISIS")
219
-
220
- col1, col2, col3 = st.columns(3)
221
- with col1:
222
- st.metric(label="🔴 Perlu Perhatian", value=str(danger))
223
- with col2:
224
- st.metric(label="🟡 Sub-Optimal", value=str(warning))
225
- with col3:
226
- st.metric(label="🟢 Optimal", value=str(optimal))
227
-
228
- st.write("")
229
-
230
-
231
- def render_biomarker_chip(name: str, status: StatusType):
232
- """Inline chip menggunakan caption + emoji — tidak butuh HTML."""
233
- emoji = _STATUS_EMOJI.get(status, "⚪")
234
- st.caption(f"{emoji} {name}")
235
-
236
-
237
- # ════════════════════════════════════════════════
238
- # PROTOCOL COMPONENTS
239
- # ════════════════════════════════════════════════
240
-
241
- def render_protocol_section(
242
- section_key: str,
243
- content: str,
244
- custom_icon: str = "",
245
- custom_title: str = "",
246
- accent_color: str = "",
247
- ):
248
- """
249
- Protocol section menggunakan st.expander native sebagai container,
250
- dengan header yang jelas. Content di-render sebagai st.markdown biasa.
251
- """
252
- cfg = PROTOCOL_SECTIONS.get(section_key, {
253
- "icon": custom_icon or "📋",
254
- "title": custom_title or "Section",
255
- "color": accent_color or COLORS["accent_violet"],
256
- })
257
-
258
- icon = custom_icon or cfg["icon"]
259
- title = custom_title or cfg["title"]
260
-
261
- with st.expander(f"{icon} {title}", expanded=True):
262
- if content and content.strip():
263
- st.markdown(content)
264
- else:
265
- st.caption("Tidak ada data untuk section ini.")
266
-
267
-
268
- # ════════════════════════════════════════════════
269
- # ERROR & EMPTY STATES
270
- # ════════════════════════════════════════════════
271
-
272
- def render_error_state(
273
- title: str = "Terjadi Kesalahan",
274
- message: str = "Silakan coba lagi.",
275
- retry_label: str = "Coba Lagi",
276
- show_contact: bool = False,
277
- ):
278
- """Error state menggunakan st.error native — selalu render dengan benar."""
279
- st.error(f"**{title}**\n\n{message}", icon="⚠️")
280
- if show_contact:
281
- st.caption("Butuh bantuan? Hubungi [@bennywhitethatsright](https://instagram.com/bennywhitethatsright)")
282
-
283
-
284
- def render_empty_state(
285
- emoji: str = "🧬",
286
- title: str = "Belum ada data",
287
- message: str = "",
288
- ):
289
- """Empty state menggunakan st.info native."""
290
- st.info(f"{emoji} **{title}**\n\n{message}" if message else f"{emoji} **{title}**")
291
-
292
-
293
- # ═════════════════════════���══════════════════════
294
- # FOOTER
295
- # ════════════════════════════════════════════════
296
-
297
- def render_footer():
298
- """Footer menggunakan st.divider + st.caption native."""
299
- st.divider()
300
- st.caption(
301
- "**FROM INJURED → OPTIMIZED** \n"
302
- "Human+ Bali · Didirikan oleh Benjamin White · "
303
- "[@bennywhitethatsright](https://instagram.com/bennywhitethatsright) \n"
304
- "*Data Anda tidak disimpan. Aplikasi 100% stateless. "
305
- "Bukan pengganti konsultasi medis.*"
306
- )
307
-
308
-
309
- # ════════════════════════════════════════════════
310
- # UTILITY CARDS
311
- # ════════════════════════════════════════════════
312
-
313
- def render_info_card(title: str, body: str, icon: str = "ℹ️"):
314
- """
315
- Info card menggunakan st.info — native, selalu render.
316
- Body sebaiknya plain text, bukan HTML.
317
- """
318
- # Strip HTML tags sederhana dari body sebelum render
319
- import re
320
- clean_body = re.sub(r"<[^>]+>", "", body).strip()
321
- st.info(f"{icon} **{title}**\n\n{clean_body}")
322
-
323
-
324
- def render_success_banner(title: str, subtitle: str = ""):
325
- """Success banner menggunakan st.success native."""
326
- text = f"**{title}**"
327
- if subtitle:
328
- text += f"\n\n{subtitle}"
329
- st.success(text, icon="✅")
330
-
331
-
332
- def render_highlight_quote(text: str):
333
- """
334
- Motivational quote — satu-satunya komponen yang tetap pakai
335
- HTML minimal karena border-left gradient tidak ada di native Streamlit.
336
- """
337
- st.markdown(
338
- f"<blockquote style='"
339
- f"border-left:3px solid #8b5cf6; padding:12px 16px; margin:16px 0; "
340
- f"background:rgba(109,40,217,0.06); border-radius:0 8px 8px 0;'>"
341
- f"<em style='color:#c4c4e0;'>{text}</em><br>"
342
- f"<small style='color:#4a4a6a;'>— Benjamin White, Founder Human+ Bali</small>"
343
- f"</blockquote>",
344
- unsafe_allow_html=True,
345
- )