desinez commited on
Commit
7dc3c93
·
1 Parent(s): 83e3158

updating frontend

Browse files
Files changed (1) hide show
  1. frontend/app.py +246 -190
frontend/app.py CHANGED
@@ -2,6 +2,7 @@ import dash
2
  from dash import dcc, html, Input, Output, State, dash_table
3
  import dash_bootstrap_components as dbc
4
  import pandas as pd
 
5
  import base64
6
  import io
7
  import os
@@ -10,17 +11,17 @@ import os
10
  from backend.main import storage
11
  from backend.PvDeepSetNet.src.DeepSets import run_prediction
12
 
13
- # 1. Initialize App with a high-contrast dark theme and FontAwesome icons
14
  app = dash.Dash(
15
  __name__,
16
- external_stylesheets=[dbc.themes.SLATE, dbc.icons.FONT_AWESOME],
17
- title="PvRecNet | Diagnostic Companion",
18
  suppress_callback_exceptions=True,
19
  requests_pathname_prefix="/",
20
  routes_pathname_prefix="/"
21
  )
22
 
23
- # --- COMPONENT STYLING DICTIONARIES ---
24
  SIDEBAR_STYLE = {
25
  "position": "fixed",
26
  "top": 0,
@@ -28,8 +29,6 @@ SIDEBAR_STYLE = {
28
  "bottom": 0,
29
  "width": "20rem",
30
  "padding": "3rem 1.5rem",
31
- "background-color": "#1e293b", # Dark Slate Blue
32
- "borderRight": "1px solid rgba(45, 212, 191, 0.1)",
33
  "zIndex": 100
34
  }
35
 
@@ -39,197 +38,244 @@ CONTENT_STYLE = {
39
  "padding": "3rem 1rem",
40
  }
41
 
42
- # --- UNIFIED LAYOUT TEMPLATE ---
43
  sidebar = html.Div(
44
  [
45
  html.Div([
46
- html.H2("PvRecNet", className="display-6 font-weight-bold mb-0", style={"color": "#2dd4bf", "letterSpacing": "-1px"}),
47
- html.P("Malaria Recurrence Platform", className="small text-muted text-uppercase tracking-wider mt-1"),
48
  ], className="mb-5"),
49
 
50
- html.Hr(style={"borderTop": "1px solid rgba(248, 250, 252, 0.1)", "marginBottom": "2rem"}),
51
 
52
  dbc.Nav(
53
  [
54
- dbc.NavLink([html.I(className="fas fa-microscope me-3"), "Analytical Hub"], href="/", active="exact", className="py-3 px-4 mb-2 rounded"),
55
- dbc.NavLink([html.I(className="fas fa-book-medical me-3"), "Guidelines"], href="/help", active="exact", className="py-3 px-4 mb-2 rounded"),
56
- dbc.NavLink([html.I(className="fas fa-flask me-3"), "pvAmpSeq Protocol"], href="https://pubmed.ncbi.nlm.nih.gov/40492072/", target="_blank", className="py-3 px-4 mb-2 rounded"),
57
  ],
58
  vertical=True,
59
  pills=True,
60
  className="flex-column"
61
  ),
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  html.Div(
64
  html.Small("System Context: Operational (2026)", className="text-muted"),
65
- style={"position": "absolute", "bottom": "2rem", "left": "1.5rem"}
66
  )
67
  ],
 
68
  style=SIDEBAR_STYLE,
69
  )
70
 
71
  app.layout = html.Div([
72
  dcc.Location(id='url', refresh=False),
 
73
  sidebar,
74
  dcc.Store(id='dataset-id-store', storage_type='session'),
75
  html.Div(id='page-content', style=CONTENT_STYLE)
76
- ])
77
 
78
 
79
- # --- PAGE 1: RE-STYLED HELP & GUIDELINES PAGE ---
80
  def render_help_page():
81
  return dbc.Container([
 
 
 
82
  html.Div([
83
- html.H1("System Guidelines & Documentation", className="display-5 font-weight-bold", style={"color": "#2dd4bf"}),
84
- html.P([
85
- "PvRecNet utilizes a Deep Learning architecture to accurately differentiate between ",
86
- html.B("Recrudescence, Relapse, and Reinfection"),
87
- " from complex genetic datasets."
88
- ], className="lead text-muted mb-5"),
89
- ]),
 
 
90
 
91
- dbc.Row([
92
- dbc.Col([
93
- dbc.Card([
94
- dbc.CardHeader(html.H5("Data Specifications", className="mb-0 text-info"), style={"background": "#1e293b"}),
95
- dbc.CardBody([
96
- html.P("Your uploaded dataset must contain these exact case-sensitive column properties:"),
97
- html.Div([
98
- dbc.Badge("patient_id", color="secondary", className="me-2 mb-2 p-2"),
99
- dbc.Badge("episode", color="secondary", className="me-2 mb-2 p-2"),
100
- dbc.Badge("marker", color="secondary", className="me-2 mb-2 p-2"),
101
- dbc.Badge("allele", color="secondary", className="me-2 mb-2 p-2"),
102
- dbc.Badge("region", color="secondary", className="me-2 mb-2 p-2"),
103
- ], className="my-3"),
104
- html.Small("Note: 'marker' refers to genetic loci; 'allele' mapped to haplotype sequences.", className="text-muted d-block mt-2")
105
- ])
106
- ], className="border-0 bg-dark shadow-sm rounded mb-4")
107
- ], md=6),
108
-
109
- dbc.Col([
110
- dbc.Card([
111
- dbc.CardHeader(html.H5("Scope & Constraints", className="mb-0 text-warning"), style={"background": "#1e293b"}),
112
- dbc.CardBody([
113
- html.Ul([
114
- html.Li("Bound by Pv3Rs baseline probabilistic training distributions."),
115
- html.Li("Configured specifically for paired-episode sample auditing."),
116
- html.Li("Trained on clinical amplicon sequencing parameters.")
117
- ], className="text-muted pl-3")
118
- ])
119
- ], className="border-0 bg-dark shadow-sm rounded mb-4")
120
- ], md=6)
121
- ]),
122
 
123
- dbc.Card([
124
- dbc.CardBody([
125
- dbc.Row([
126
- dbc.Col([
127
- html.H4("Practice Workspace", className="mb-2 text-white"),
128
- html.P("Download our validation configuration matrix template to evaluate platform layout structures locally.", className="text-muted mb-0")
129
- ], md=8),
130
- dbc.Col([
131
- dbc.Button(
132
- [html.I(className="fas fa-file-download me-2"), "Download Sample CSV"],
133
- id="download-sample-btn",
134
- color="success",
135
- className="w-100 h-100 py-3 font-weight-bold"
136
- ),
137
- dcc.Download(id="download-sample-csv"),
138
- ], md=4, className="d-flex align-items-center")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  ])
140
- ])
141
- ], color="light", outline=True, className="mt-4 border-start border-success border-4 bg-dark shadow-sm")
 
142
  ], fluid=True)
143
 
144
 
145
- # --- PAGE 2: MAIN WORKBENCH DASHBOARD ---
146
  def render_main_app():
147
  return dbc.Container([
148
- html.Div([
149
- html.H1("Analytical Workbench", className="display-5 font-weight-bold mb-1"),
150
- html.P("Upload evaluation matrices to pass to the Deep Learning prediction runner.", className="text-muted mb-5"),
151
  ]),
152
 
153
- dbc.Row([
154
- # Control / Upload Column
155
- dbc.Col([
156
- dbc.Card([
157
- dbc.CardHeader([
158
- html.I(className="fas fa-cloud-upload-alt me-2 text-teal"),
159
- html.B("1. INPUT MATRIX")
160
- ], style={"background": "#1e293b", "color": "#2dd4bf"}),
161
- dbc.CardBody([
162
- dcc.Upload(
163
- id='upload-data',
164
- children=html.Div([
165
- html.I(className="fas fa-file-csv display-6 d-block mb-2 text-muted"),
166
- 'Drag & Drop Matrix or ', html.Span('Browse Files', style={"color": "#2dd4bf", "textDecoration": "underline"})
167
- ]),
168
- style={
169
- 'width': '100%', 'height': '140px', 'lineHeight': '24px',
170
- 'borderWidth': '2px', 'borderStyle': 'dashed', 'borderRadius': '12px',
171
- 'textAlign': 'center', 'background': '#0f172a', 'paddingTop': '30px',
172
- 'borderColor': 'rgba(45, 212, 191, 0.2)', 'cursor': 'pointer'
173
- }
174
- ),
175
- html.Div(id='upload-status', className="mt-3"),
176
- dbc.Button(
177
- [html.I(className="fas fa-bolt me-2"), "Run Pipeline Prediction"],
178
- id="predict-btn", disabled=True, className="w-100 mt-4 py-2 font-weight-bold shadow-sm",
179
- style={"backgroundColor": "#2dd4bf", "border": "none", "color": "#0f172a"}
180
- )
181
  ])
182
- ], className="border-0 shadow rounded mb-4 bg-dark"),
183
- ], md=4),
184
-
185
- # Data Preview Workbench Column
186
- dbc.Col([
187
- dbc.Card([
188
- dbc.CardHeader([
189
- html.I(className="fas fa-table me-2"),
190
- html.B("2. GENOMIC AUDIT BENCH")
191
- ], style={"background": "#1e293b"}),
192
- dbc.CardBody(
193
- dcc.Loading(dash_table.DataTable(
194
- id='preview-table',
195
- columns=[],
196
- data=[],
197
- export_format='csv',
198
- editable=True,
199
- filter_action="native",
200
- sort_action="native",
201
- page_size=7,
202
- style_table={'height': '350px', 'overflowY': 'auto'},
203
- style_header={'backgroundColor': '#1e293b', 'color': '#2dd4bf', 'fontWeight': 'bold', 'border': '1px solid #334155'},
204
- style_cell={'backgroundColor': '#0f172a', 'color': '#cbd5e1', 'textAlign': 'left', 'border': '1px solid #334155', 'padding': '12px'}
205
- ), type="dot")
206
- )
207
- ], className="border-0 shadow rounded mb-4 bg-dark"),
208
- ], md=8),
209
- ]),
210
-
211
- # Results Section Layout Row
212
- dbc.Row([
213
- dbc.Col(
214
- dbc.Card([
215
- dbc.CardHeader([
216
- html.I(className="fas fa-chart-pie me-2 text-teal"),
217
- html.B("3. INTERPRETATIVE PREDICTIONS")
218
- ], style={"background": "#1e293b", "color": "#2dd4bf"}),
219
- dbc.CardBody(
220
- dcc.Loading(
221
- html.Div(id="prediction-output", className="p-3 text-center text-muted"),
222
- type="graph"
223
- )
224
- )
225
- ], className="border-0 shadow rounded mb-5 bg-dark"),
226
- width=12
227
- )
228
  ])
229
  ], fluid=True)
230
 
231
 
232
- # --- ROUTER ROUTING LOGIC CALLBACK ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
  @app.callback(
234
  Output('page-content', 'children'),
235
  Input('url', 'pathname')
@@ -241,7 +287,17 @@ def display_page(pathname):
241
  return render_main_app()
242
 
243
 
244
- # --- SAMPLE TEMPLATE DOWNLOAD CONTROLLER ---
 
 
 
 
 
 
 
 
 
 
245
  @app.callback(
246
  Output("download-sample-csv", "data"),
247
  Input("download-sample-btn", "n_clicks"),
@@ -262,7 +318,7 @@ def download_sample_data(n_clicks):
262
  return dcc.send_data_frame(sample_df.to_csv, "pvrecnet_sample_data.csv", index=False)
263
 
264
 
265
- # --- IN-MEMORY DATA UPLOAD PIPELINE CALLBACK ---
266
  @app.callback(
267
  [Output('dataset-id-store', 'data'), Output('upload-status', 'children'), Output('predict-btn', 'disabled'),
268
  Output('preview-table', 'data'), Output('preview-table', 'columns')],
@@ -275,52 +331,50 @@ def handle_upload(contents, filename):
275
  df = pd.read_csv(io.BytesIO(decoded))
276
  cols = [{"name": i, "id": i, "editable": True} for i in df.columns]
277
 
278
- # Save raw binary stream into global runtime application space
279
  dataset_id = "ds_001"
280
  storage[dataset_id] = decoded
281
 
282
- status = dbc.Alert([
283
- html.I(className="fas fa-check-circle me-2"), f"Loaded: {filename}"
284
- ], color="success", className="mt-2 py-2 text-center rounded")
285
-
286
  return dataset_id, status, False, df.to_dict('records'), cols
287
  except Exception as e:
288
- error_status = dbc.Alert([
289
- html.I(className="fas fa-exclamation-triangle me-2"), f"Parse Failure: {str(e)}"
290
- ], color="danger", className="mt-2 py-2 text-center rounded")
291
- return None, error_status, True, [], []
292
 
293
 
294
- # --- DEEP SETS WORKFLOW MATHEMATICAL INFERENCE PIPELINE ---
295
  @app.callback(
296
  Output('prediction-output', 'children'),
297
  Input('predict-btn', 'n_clicks'),
298
- State('dataset-id-store', 'data'),
299
  prevent_initial_call=True
300
  )
301
- def run_predict(n_clicks, dataset_id):
302
  try:
303
- # Pull transactional context instantly from in-memory cache
304
  file_bytes = storage.get(dataset_id)
305
  if not file_bytes:
306
- return dbc.Alert("Error: Target matrix could not be resolved from working memory.", color="danger")
307
 
308
  df = pd.read_csv(io.BytesIO(file_bytes))
309
-
310
- # Invoke DeepSets Machine Learning core package natively
311
  model_output = run_prediction(df)
312
 
313
  fig1 = model_output.get('donut_plot')
314
  fig2 = model_output.get('distribution_plot')
315
 
316
- # Format Plotly layout backgrounds to blend natively with dark dashboard cards
 
317
  for fig in [fig1, fig2]:
318
  if fig:
319
- fig.update_layout(
320
- paper_bgcolor='rgba(0,0,0,0)',
321
- plot_bgcolor='rgba(0,0,0,0)',
322
- font_color='#cbd5e1'
323
- )
 
 
 
 
 
 
324
 
325
  df_res = pd.DataFrame(model_output['results_table'])
326
  prob_cols = ['C_marg', 'L_marg', 'I_marg']
@@ -329,32 +383,34 @@ def run_predict(n_clicks, dataset_id):
329
  if col in df_res.columns:
330
  df_res[col] = df_res[col].map(lambda x: f"{x:.4f}" if pd.notnull(x) else x)
331
 
 
 
 
 
 
 
332
  table = dash_table.DataTable(
333
  data=df_res.to_dict('records'),
334
  columns=[{"name": i, "id": i} for i in df_res.columns],
335
  export_format='csv',
336
- page_size=10,
337
- style_header={'backgroundColor': '#1e293b', 'color': '#2dd4bf', 'fontWeight': 'bold'},
338
- style_cell={'backgroundColor': '#0f172a', 'color': '#cbd5e1', 'textAlign': 'left', 'border': '1px solid #334155', 'padding': '10px'}
 
339
  )
340
 
341
  return html.Div([
342
  dbc.Row([
343
  dbc.Col([
344
- html.Div(dcc.Graph(figure=fig1, config={'displayModeBar': False}) if fig1 else html.Div(), className="mb-4"),
345
- html.Div(dcc.Graph(figure=fig2, config={'displayModeBar': False}) if fig2 else html.Div())
346
- ], md=5, className="border-end", style={"borderColor": "rgba(248,250,252,0.1) !important"}),
347
- dbc.Col([
348
- html.H5("Classification Breakdown Matrix", className="text-teal mb-3", style={"color": "#2dd4bf"}),
349
- table
350
- ], md=7, className="ps-4")
351
  ])
352
- ], className="text-start")
353
-
354
  except Exception as e:
355
- return dbc.Alert([
356
- html.I(className="fas fa-radiation me-2"), f"Pipeline Engine Exception: {str(e)}"
357
- ], color="danger", className="text-start")
358
 
359
 
360
  if __name__ == '__main__':
 
2
  from dash import dcc, html, Input, Output, State, dash_table
3
  import dash_bootstrap_components as dbc
4
  import pandas as pd
5
+ import json
6
  import base64
7
  import io
8
  import os
 
11
  from backend.main import storage
12
  from backend.PvDeepSetNet.src.DeepSets import run_prediction
13
 
14
+ # Initialize App with basic styling and FontAwesome icons
15
  app = dash.Dash(
16
  __name__,
17
+ external_stylesheets=[dbc.themes.FLATLY, dbc.icons.FONT_AWESOME],
18
+ title="PvRecNet",
19
  suppress_callback_exceptions=True,
20
  requests_pathname_prefix="/",
21
  routes_pathname_prefix="/"
22
  )
23
 
24
+ # --- BASE SIDEBAR CONTAINER STYLE ---
25
  SIDEBAR_STYLE = {
26
  "position": "fixed",
27
  "top": 0,
 
29
  "bottom": 0,
30
  "width": "20rem",
31
  "padding": "3rem 1.5rem",
 
 
32
  "zIndex": 100
33
  }
34
 
 
38
  "padding": "3rem 1rem",
39
  }
40
 
41
+ # --- APPLICABLE COMPONENTS TEMPLATE ---
42
  sidebar = html.Div(
43
  [
44
  html.Div([
45
+ html.H2("PvRecNet", className="display-6 font-weight-bold mb-0", style={"color": "#2dd4bf"}),
46
+ html.P("Malaria Recurrence Platform", className="small text-muted mt-1"),
47
  ], className="mb-5"),
48
 
49
+ html.Hr(style={"marginBottom": "2rem"}),
50
 
51
  dbc.Nav(
52
  [
53
+ dbc.NavLink([html.I(className="fas fa-home me-3"), "Dashboard"], href="/", active="exact", className="py-3 px-4 mb-2 rounded"),
54
+ dbc.NavLink([html.I(className="fas fa-book me-3"), "Guidelines"], href="/help", active="exact", className="py-3 px-4 mb-2 rounded"),
 
55
  ],
56
  vertical=True,
57
  pills=True,
58
  className="flex-column"
59
  ),
60
 
61
+ # Theme Switch Component Setup
62
+ html.Div([
63
+ html.Hr(style={"marginBottom": "1.5rem"}),
64
+ html.Label([html.I(className="fas fa-adjust me-2"), "Interface Theme"], className="small text-muted d-block mb-2"),
65
+ dbc.RadioItems(
66
+ id="theme-toggle",
67
+ options=[
68
+ {"label": " Dark Mode", "value": "dark"},
69
+ {"label": " Light Mode", "value": "light"},
70
+ ],
71
+ value="dark",
72
+ inline=True,
73
+ className="text-muted small"
74
+ )
75
+ ], style={"position": "absolute", "bottom": "4rem", "left": "1.5rem", "width": "80%"}),
76
+
77
  html.Div(
78
  html.Small("System Context: Operational (2026)", className="text-muted"),
79
+ style={"position": "absolute", "bottom": "1.5rem", "left": "1.5rem"}
80
  )
81
  ],
82
+ id="sidebar-panel",
83
  style=SIDEBAR_STYLE,
84
  )
85
 
86
  app.layout = html.Div([
87
  dcc.Location(id='url', refresh=False),
88
+ dcc.Store(id='theme-store', storage_type='session', data='dark'),
89
  sidebar,
90
  dcc.Store(id='dataset-id-store', storage_type='session'),
91
  html.Div(id='page-content', style=CONTENT_STYLE)
92
+ ], id="main-container")
93
 
94
 
95
+ # --- PAGE 1: ORIGINAL HELP & GUIDELINES PAGE ---
96
  def render_help_page():
97
  return dbc.Container([
98
+ # Back Button
99
+ dbc.Button("← Back to System", href="/", color="link", className="mt-4 p-0 text-decoration-none text-info"),
100
+
101
  html.Div([
102
+ # Header Section
103
+ html.Div([
104
+ html.H1("System Guidelines & Documentation", className="display-5 text-primary"),
105
+ html.P([
106
+ "PvRecNet is a deep learning-based model for ",
107
+ html.B(html.I("Plasmodium vivax")),
108
+ " recurrence classification."
109
+ ], className="lead"),
110
+ ], className="mb-5"),
111
 
112
+ # Visual Appeal: Use Cards for Sections
113
+ dbc.Row([
114
+ # Section: Description
115
+ dbc.Col([
116
+ html.H5("Model Description", className="text-info"),
117
+ html.P([
118
+ "Our architecture differentiates between ",
119
+ html.B("Recrudescence, Relapse, and Reinfection"),
120
+ ". It is trained on probabilistic outputs from ",
121
+ html.A("Pv3Rs", href="https://github.com/aimeertaylor/Pv3Rs", target="_blank"),
122
+ " to ensure robust genomic classification."
123
+ ]),
124
+ ], md=6),
125
+
126
+ # Section: Data Requirements
127
+ dbc.Col([
128
+ html.H5("Data Requirements", className="text-info"),
129
+ html.P("Your dataset must contain these exact columns:"),
130
+ html.Div([
131
+ dbc.Badge("patient_id", color="primary", className="me-1"),
132
+ dbc.Badge("episode", color="primary", className="me-1"),
133
+ dbc.Badge("marker", color="primary", className="me-1"),
134
+ dbc.Badge("allele", color="primary", className="me-1"),
135
+ dbc.Badge("region", color="primary", className="me-1"),
136
+ ], className="mb-3"),
137
+ html.Small("Note: marker = loci, allele = haplotype, region = country.", className="text-muted")
138
+ ], md=6),
139
+ ], className="mb-4"),
 
 
 
140
 
141
+ html.Hr(),
142
+
143
+ # Section: Limitations
144
+ html.H4("⚠️ Scope & Limitations", className="mt-4 text-warning"),
145
+ html.Ul([
146
+ html.Li([html.B("Dependency on Pv3Rs: "), "Since the model is trained on the probabilistic outputs of Pv3Rs, its accuracy is bounded by Pv3Rs. Systematic errors in Pv3Rs may be replicated."]),
147
+ html.Li([html.B("Data Requirements: "), "Currently works only with amplicon sequencing datasets containing multiple markers and alleles."]),
148
+ html.Li([html.B("Episode Constraints: "), "Designed specifically for paired-episode classifications; it does not address scenarios with more than two episodes per individual as a single classification."]),
149
+ html.Li([html.B("Generalization: "), "The model may not generalize well to genetic markers or alleles unobserved during training."]),
150
+ html.Li([html.B("Protocol Dependent: "), "Trained specifically on ", html.A("pvAmpSeq", href="https://pubmed.ncbi.nlm.nih.gov/40492072/", target="_blank"), "; it only generalizes when using the same markers and allele names specified in that protocol."]),
151
+ ], className="text-secondary"),
152
+
153
+ # Sample Dataset Section
154
+ dbc.Card([
155
+ dbc.CardBody([
156
+ dbc.Row([
157
+ dbc.Col([
158
+ html.H4("Practice with Sample Data", className="card-title text-dark"),
159
+ html.P("Download our demonstration file to see how the markers and episodes should be formatted.", className="text-dark"),
160
+ ], md=8),
161
+ dbc.Col([
162
+ dbc.Button(
163
+ "📥 Download Sample CSV",
164
+ id="download-sample-btn",
165
+ color="success",
166
+ className="w-100 mt-2"
167
+ ),
168
+ dcc.Download(id="download-sample-csv"),
169
+ ], md=4),
170
+ ])
171
  ])
172
+ ], color="light", className="mt-5 border-start border-success border-4"),
173
+
174
+ ], className="p-5 bg-white shadow-sm rounded-3 mb-5")
175
  ], fluid=True)
176
 
177
 
178
+ # --- PAGE 2: ORIGINAL MAIN SYSTEM LAYOUT (With Updated Styling) ---
179
  def render_main_app():
180
  return dbc.Container([
181
+ dbc.Row([
182
+ dbc.Col(html.H1("PvRecNet", className="my-4", style={"color":'#2dd4bf'}), width=10),
183
+ dbc.Col(html.A("Help & Guidelines", href="/help", className="text-muted", style={"marginTop": "30px", "display": "block"}), width=2)
184
  ]),
185
 
186
+ dbc.Tabs(id="main-tabs", active_tab="tab-intro", children=[
187
+ # Tab 0: Welcome / Landing
188
+ dbc.Tab(label="Welcome", tab_id="tab-intro", active_label_style={"color": '#2dd4bf', "fontWeight": "bold"}, children=[
189
+ dbc.Container([
190
+ dbc.Row([
191
+ dbc.Col([
192
+ html.Div([
193
+ html.H2("Welcome to PvRecNet", className="display-5 mt-5", style={"color":'#2dd4bf'}),
194
+ html.P("Deep Learning support for Malaria Recurrence Classification.", className="lead"),
195
+ html.P([
196
+ "Please see our ",
197
+ html.A("Help Page", href="/help", style={"fontWeight": "bold", "color": "#2dd4bf"}),
198
+ " to understand exactly how the system works and how to format your data."
199
+ ]),
200
+ html.Hr(),
201
+ dbc.Button("Get Started →", id="get-started-btn", color="primary", size="lg", className="mt-3 shadow")
202
+ ], className="p-5 border rounded-3 text-center card-panel-box")
203
+ ], md=8, className="offset-md-2")
 
 
 
 
 
 
 
 
 
 
204
  ])
205
+ ], fluid=True)
206
+ ]),
207
+
208
+ # Tab 1: Prediction Workflow
209
+ dbc.Tab(label="Prediction Workflow", tab_id="tab-predict", active_label_style={"color": '#2dd4bf', "fontWeight": "bold"}, children=[
210
+ dbc.Row([
211
+ dbc.Col([
212
+ dbc.Card([
213
+ dbc.CardHeader(html.B("Step 1: Upload Data")),
214
+ dbc.CardBody([
215
+ dcc.Upload(id='upload-data', children=html.Div(['Drag/Drop or Select CSV']),
216
+ style={'width': '100%', 'height': '60px', 'lineHeight': '60px', 'borderWidth': '1px', 'borderStyle': 'dashed', 'borderRadius': '5px', 'textAlign': 'center'}),
217
+ html.Div(id='upload-status', className="mt-2"),
218
+ html.Hr(),
219
+ # Fixed text contrast to dark navy text (#0f172a) on light teal background (#2dd4bf)
220
+ dbc.Button("Run Deep Sets Prediction", id="predict-btn", disabled=True, className="w-100 font-weight-bold",
221
+ style={"backgroundColor": "#2dd4bf", "borderColor": "#2dd4bf", "color": "#0f172a"})
222
+ ])
223
+ ], className="card-panel-box")
224
+ ], md=4),
225
+ dbc.Col([
226
+ dbc.Card([
227
+ dbc.CardHeader(html.B("Step 2: Data Workbench")),
228
+ dbc.CardBody(dcc.Loading(dash_table.DataTable(
229
+ id='preview-table', columns=[], data=[], export_format='csv', editable=True,
230
+ filter_action="native", sort_action="native", page_size=10,
231
+ style_table={'height': '350px', 'overflowY': 'auto'},
232
+ ), type="dot"))
233
+ ], className="card-panel-box")
234
+ ], md=8)
235
+ ], className="mt-4"),
236
+ dbc.Row(dbc.Col(dbc.Card([dbc.CardHeader(html.B("Step 3: Model Results")), dbc.CardBody(dcc.Loading(id="prediction-output", type="graph"))], className="mt-4 mb-5 card-panel-box"), width=12))
237
+ ]),
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  ])
239
  ], fluid=True)
240
 
241
 
242
+ # --- THEME STORE STATE ROUTER ---
243
+ @app.callback(
244
+ Output('theme-store', 'data'),
245
+ Input('theme-toggle', 'value')
246
+ )
247
+ def save_theme_preference(theme_val):
248
+ return theme_val
249
+
250
+
251
+ # --- MAIN LAYOUT RESPONSIVE STYLE CONFIGURATOR ---
252
+ @app.callback(
253
+ [Output('main-container', 'style'),
254
+ Output('sidebar-panel', 'style'),
255
+ Output('preview-table', 'style_header'),
256
+ Output('preview-table', 'style_cell')],
257
+ Input('theme-store', 'data')
258
+ )
259
+ def apply_theme_parameters(theme):
260
+ if theme == 'light':
261
+ bg_main, color_main, bg_sidebar, border_sidebar = "#f8fafc", "#0f172a", "#e2e8f0", "1px solid #cbd5e1"
262
+ header_table, cell_table = '#cbd5e1', '#ffffff'
263
+ text_table, border_table = '#0f172a', '#94a3b8'
264
+ else: # Dark Theme Configuration
265
+ bg_main, color_main, bg_sidebar, border_sidebar = "#0f172a", "#f8fafc", "#1e293b", "1px solid rgba(45, 212, 191, 0.1)"
266
+ header_table, cell_table = '#1e293b', '#0f172a'
267
+ text_table, border_table = '#f8fafc', '#334155'
268
+
269
+ container_css = {"background": bg_main, "color": color_main, "minHeight": "100vh", "transition": "all 0.3s ease"}
270
+ sidebar_css = {**SIDEBAR_STYLE, "background-color": bg_sidebar, "borderRight": border_sidebar, "transition": "all 0.3s ease"}
271
+
272
+ th_style = {'backgroundColor': header_table, 'color': '#2dd4bf', 'fontWeight': 'bold', 'border': f'1px solid {border_table}'}
273
+ td_style = {'backgroundColor': cell_table, 'color': text_table, 'textAlign': 'left', 'border': f'1px solid {border_table}', 'padding': '10px'}
274
+
275
+ return container_css, sidebar_css, th_style, td_style
276
+
277
+
278
+ # --- CORE PAGES ROUTER CALLBACK ---
279
  @app.callback(
280
  Output('page-content', 'children'),
281
  Input('url', 'pathname')
 
287
  return render_main_app()
288
 
289
 
290
+ # --- NAVIGATION CALLBACK ---
291
+ @app.callback(
292
+ Output("main-tabs", "active_tab"),
293
+ Input("get-started-btn", "n_clicks"),
294
+ prevent_initial_call=True
295
+ )
296
+ def navigate_to_predict(n_clicks):
297
+ return "tab-predict" if n_clicks else "tab-intro"
298
+
299
+
300
+ # --- SAMPLE TEMPLATE CONTROLLER ---
301
  @app.callback(
302
  Output("download-sample-csv", "data"),
303
  Input("download-sample-btn", "n_clicks"),
 
318
  return dcc.send_data_frame(sample_df.to_csv, "pvrecnet_sample_data.csv", index=False)
319
 
320
 
321
+ # --- FUNCTIONAL DATA UPLOAD STORAGE INTERFACE ---
322
  @app.callback(
323
  [Output('dataset-id-store', 'data'), Output('upload-status', 'children'), Output('predict-btn', 'disabled'),
324
  Output('preview-table', 'data'), Output('preview-table', 'columns')],
 
331
  df = pd.read_csv(io.BytesIO(decoded))
332
  cols = [{"name": i, "id": i, "editable": True} for i in df.columns]
333
 
334
+ # Save raw dataframe binary directly into memory store context
335
  dataset_id = "ds_001"
336
  storage[dataset_id] = decoded
337
 
338
+ status = dbc.Alert(f"Ready: {filename}", color="success", className="mt-2")
 
 
 
339
  return dataset_id, status, False, df.to_dict('records'), cols
340
  except Exception as e:
341
+ return None, dbc.Alert(f"Error parsing file: {str(e)}", color="danger"), True, [], []
 
 
 
342
 
343
 
344
+ # --- ANALYTICAL WORKFLOW EXECUTOR AND PLOTLY GRAPH CONFIGURATOR ---
345
  @app.callback(
346
  Output('prediction-output', 'children'),
347
  Input('predict-btn', 'n_clicks'),
348
+ [State('dataset-id-store', 'data'), State('theme-store', 'data')],
349
  prevent_initial_call=True
350
  )
351
+ def run_predict(n_clicks, dataset_id, theme):
352
  try:
 
353
  file_bytes = storage.get(dataset_id)
354
  if not file_bytes:
355
+ return dbc.Alert("Error: Dataset context could not be located in application memory storage.", color="danger")
356
 
357
  df = pd.read_csv(io.BytesIO(file_bytes))
 
 
358
  model_output = run_prediction(df)
359
 
360
  fig1 = model_output.get('donut_plot')
361
  fig2 = model_output.get('distribution_plot')
362
 
363
+ # Establish responsive typography/background layouts for dynamic plots injection
364
+ chart_text = '#f8fafc' if theme == 'dark' else '#0f172a'
365
  for fig in [fig1, fig2]:
366
  if fig:
367
+ # Forces explicit responsive layout structure inside dash core component wrapper trees
368
+ if hasattr(fig, 'update_layout'):
369
+ fig.update_layout(
370
+ paper_bgcolor='rgba(0,0,0,0)',
371
+ plot_bgcolor='rgba(0,0,0,0)',
372
+ font_color=chart_text
373
+ )
374
+ elif isinstance(fig, dict) and 'layout' in fig:
375
+ fig['layout']['paper_bgcolor'] = 'rgba(0,0,0,0)'
376
+ fig['layout']['plot_bgcolor'] = 'rgba(0,0,0,0)'
377
+ fig['layout']['font'] = {'color': chart_text}
378
 
379
  df_res = pd.DataFrame(model_output['results_table'])
380
  prob_cols = ['C_marg', 'L_marg', 'I_marg']
 
383
  if col in df_res.columns:
384
  df_res[col] = df_res[col].map(lambda x: f"{x:.4f}" if pd.notnull(x) else x)
385
 
386
+ # Style context tables matching selected dashboard background themes
387
+ cell_bg = '#0f172a' if theme == 'dark' else '#ffffff'
388
+ cell_text = '#cbd5e1' if theme == 'dark' else '#0f172a'
389
+ hdr_bg = '#1e293b' if theme == 'dark' else '#cbd5e1'
390
+ border_clr = '#334155' if theme == 'dark' else '#94a3b8'
391
+
392
  table = dash_table.DataTable(
393
  data=df_res.to_dict('records'),
394
  columns=[{"name": i, "id": i} for i in df_res.columns],
395
  export_format='csv',
396
+ page_size=10,
397
+ style_table={'height': '400px', 'overflowY': 'auto'},
398
+ style_header={'backgroundColor': hdr_bg, 'color': '#2dd4bf', 'fontWeight': 'bold', 'border': f'1px solid {border_clr}'},
399
+ style_cell={'backgroundColor': cell_bg, 'color': cell_text, 'textAlign': 'left', 'border': f'1px solid {border_clr}'}
400
  )
401
 
402
  return html.Div([
403
  dbc.Row([
404
  dbc.Col([
405
+ dcc.Graph(figure=fig1, config={'displayModeBar': False}) if fig1 else html.Div("Donut Plot Unavailable", className="text-muted small"),
406
+ html.Hr(style={"borderColor": "rgba(248,250,252,0.1)"}),
407
+ dcc.Graph(figure=fig2, config={'displayModeBar': False}) if fig2 else html.Div("Distribution Plot Unavailable", className="text-muted small")
408
+ ], md=5),
409
+ dbc.Col(table, md=7)
 
 
410
  ])
411
+ ])
 
412
  except Exception as e:
413
+ return dbc.Alert(f"Prediction Pipeline Error: {str(e)}", color="danger")
 
 
414
 
415
 
416
  if __name__ == '__main__':