FajarHidaa commited on
Commit
3174026
·
verified ·
1 Parent(s): fdc19fc

Delete src/ui/components.py

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