Deployment ready: FastAPI + Dash setup
Browse files- backend/PvDeepSetNet/src/DeepSets/__pycache__/DeepSets_pipeline.cpython-310.pyc +0 -0
- backend/PvDeepSetNet/src/DeepSets/__pycache__/Model_result.cpython-310.pyc +0 -0
- backend/PvDeepSetNet/src/DeepSets/__pycache__/__init__.cpython-310.pyc +0 -0
- backend/PvDeepSetNet/src/DeepSets/pv_deepsets_weights20260402.pth +0 -3
- backend/__pycache__/main.cpython-310.pyc +0 -0
- backend/main.py +22 -7
- frontend/Dockerfile +29 -0
- frontend/app.py +23 -53
- requirements.txt +110 -6
backend/PvDeepSetNet/src/DeepSets/__pycache__/DeepSets_pipeline.cpython-310.pyc
CHANGED
|
Binary files a/backend/PvDeepSetNet/src/DeepSets/__pycache__/DeepSets_pipeline.cpython-310.pyc and b/backend/PvDeepSetNet/src/DeepSets/__pycache__/DeepSets_pipeline.cpython-310.pyc differ
|
|
|
backend/PvDeepSetNet/src/DeepSets/__pycache__/Model_result.cpython-310.pyc
CHANGED
|
Binary files a/backend/PvDeepSetNet/src/DeepSets/__pycache__/Model_result.cpython-310.pyc and b/backend/PvDeepSetNet/src/DeepSets/__pycache__/Model_result.cpython-310.pyc differ
|
|
|
backend/PvDeepSetNet/src/DeepSets/__pycache__/__init__.cpython-310.pyc
CHANGED
|
Binary files a/backend/PvDeepSetNet/src/DeepSets/__pycache__/__init__.cpython-310.pyc and b/backend/PvDeepSetNet/src/DeepSets/__pycache__/__init__.cpython-310.pyc differ
|
|
|
backend/PvDeepSetNet/src/DeepSets/pv_deepsets_weights20260402.pth
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:365518857580c3808b0bcc4b3c4a650064e8d972fa3ff27ffe565b420052a9a7
|
| 3 |
-
size 118509
|
|
|
|
|
|
|
|
|
|
|
|
backend/__pycache__/main.cpython-310.pyc
CHANGED
|
Binary files a/backend/__pycache__/main.cpython-310.pyc and b/backend/__pycache__/main.cpython-310.pyc differ
|
|
|
backend/main.py
CHANGED
|
@@ -1,19 +1,33 @@
|
|
| 1 |
from fastapi import FastAPI, UploadFile, File
|
|
|
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import io
|
| 4 |
import plotly.io as pio # For converting Plotly figures to JSON
|
| 5 |
-
from PvDeepSetNet.src.DeepSets import run_prediction # Your packaged model
|
| 6 |
import uvicorn
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
app = FastAPI()
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# Temporary storage for demonstration
|
| 11 |
storage = {}
|
| 12 |
|
| 13 |
@app.post("/upload-data")
|
| 14 |
async def upload_data(file: UploadFile = File(...)):
|
| 15 |
contents = await file.read()
|
| 16 |
-
dataset_id = "ds_001"
|
| 17 |
storage[dataset_id] = contents
|
| 18 |
return {"dataset_id": dataset_id}
|
| 19 |
|
|
@@ -29,25 +43,26 @@ async def predict(data: dict):
|
|
| 29 |
df = pd.read_csv(io.BytesIO(file_bytes))
|
| 30 |
|
| 31 |
# 2. Run the real PvDeepSetNet model
|
| 32 |
-
# Note: run_prediction now returns 3 items: table, text, and a plotly figure
|
| 33 |
model_output = run_prediction(df)
|
| 34 |
|
| 35 |
res_df = model_output['results_table']
|
| 36 |
-
# The figure object generated inside your model processing file
|
| 37 |
fig1 = model_output.get('donut_plot')
|
| 38 |
fig2 = model_output.get('distribution_plot')
|
| 39 |
|
| 40 |
# 3. Serialize the Plotly Figure to JSON
|
| 41 |
-
# This allows the plot to be sent over the internet as a string
|
| 42 |
plot_json1 = pio.to_json(fig1) if fig1 else None
|
| 43 |
plot_json2 = pio.to_json(fig2) if fig2 else None
|
| 44 |
-
|
| 45 |
|
| 46 |
return {
|
| 47 |
"results_table": res_df.to_dict('records'),
|
| 48 |
"plot_json1": plot_json1, # The serialized figure
|
| 49 |
-
"plot_json2": plot_json2
|
| 50 |
}
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
if __name__ == "__main__":
|
|
|
|
| 53 |
uvicorn.run(app, host="127.0.0.1", port=8000)
|
|
|
|
| 1 |
from fastapi import FastAPI, UploadFile, File
|
| 2 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
+
from starlette.middleware.wsgi import WSGIMiddleware
|
| 4 |
import pandas as pd
|
| 5 |
import io
|
| 6 |
import plotly.io as pio # For converting Plotly figures to JSON
|
|
|
|
| 7 |
import uvicorn
|
| 8 |
|
| 9 |
+
# 1. Update the import path to match your folder structure
|
| 10 |
+
from backend.PvDeepSetNet.src.DeepSets import run_prediction # Your packaged model
|
| 11 |
+
from frontend.app import app as dash_app # Import your Dash app instance
|
| 12 |
+
|
| 13 |
app = FastAPI()
|
| 14 |
|
| 15 |
+
# Optional but recommended: Add CORS middleware so frontend/backend communication is frictionless
|
| 16 |
+
app.add_middleware(
|
| 17 |
+
CORSMiddleware,
|
| 18 |
+
allow_origins=["*"],
|
| 19 |
+
allow_credentials=True,
|
| 20 |
+
allow_methods=["*"],
|
| 21 |
+
allow_headers=["*"],
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
# Temporary storage for demonstration
|
| 25 |
storage = {}
|
| 26 |
|
| 27 |
@app.post("/upload-data")
|
| 28 |
async def upload_data(file: UploadFile = File(...)):
|
| 29 |
contents = await file.read()
|
| 30 |
+
dataset_id = "ds_001" # In a real app, use: str(uuid.uuid4())
|
| 31 |
storage[dataset_id] = contents
|
| 32 |
return {"dataset_id": dataset_id}
|
| 33 |
|
|
|
|
| 43 |
df = pd.read_csv(io.BytesIO(file_bytes))
|
| 44 |
|
| 45 |
# 2. Run the real PvDeepSetNet model
|
|
|
|
| 46 |
model_output = run_prediction(df)
|
| 47 |
|
| 48 |
res_df = model_output['results_table']
|
|
|
|
| 49 |
fig1 = model_output.get('donut_plot')
|
| 50 |
fig2 = model_output.get('distribution_plot')
|
| 51 |
|
| 52 |
# 3. Serialize the Plotly Figure to JSON
|
|
|
|
| 53 |
plot_json1 = pio.to_json(fig1) if fig1 else None
|
| 54 |
plot_json2 = pio.to_json(fig2) if fig2 else None
|
|
|
|
| 55 |
|
| 56 |
return {
|
| 57 |
"results_table": res_df.to_dict('records'),
|
| 58 |
"plot_json1": plot_json1, # The serialized figure
|
| 59 |
+
"plot_json2": plot_json2 # The serialized figure
|
| 60 |
}
|
| 61 |
|
| 62 |
+
# 2. Mount the Dash app's Flask server into FastAPI.
|
| 63 |
+
# This makes Dash serve as your primary visual user interface.
|
| 64 |
+
app.mount("/", WSGIMiddleware(dash_app.server))
|
| 65 |
+
|
| 66 |
if __name__ == "__main__":
|
| 67 |
+
# Locally, you can still run this file directly
|
| 68 |
uvicorn.run(app, host="127.0.0.1", port=8000)
|
frontend/Dockerfile
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10-slim
|
| 2 |
+
|
| 3 |
+
# Install system dependencies if your ML models require compiling (optional but safe)
|
| 4 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 5 |
+
build-essential \
|
| 6 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 7 |
+
|
| 8 |
+
# Create a non-root user for Hugging Face security compliance
|
| 9 |
+
RUN useradd -m -u 1000 user
|
| 10 |
+
USER user
|
| 11 |
+
ENV PATH="/home/user/.local/bin:${PATH}"
|
| 12 |
+
|
| 13 |
+
# Force Python to look at the root directory for module imports
|
| 14 |
+
ENV PYTHONPATH="/code"
|
| 15 |
+
|
| 16 |
+
WORKDIR /code
|
| 17 |
+
|
| 18 |
+
# Copy and install requirements
|
| 19 |
+
COPY --chown=user requirements.txt .
|
| 20 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 21 |
+
|
| 22 |
+
# Copy the entire project structure over
|
| 23 |
+
COPY --chown=user . .
|
| 24 |
+
|
| 25 |
+
# Expose the mandatory Hugging Face port
|
| 26 |
+
EXPOSE 7860
|
| 27 |
+
|
| 28 |
+
# Run Uvicorn pointing directly to your backend's main.py FastAPI instance
|
| 29 |
+
CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
frontend/app.py
CHANGED
|
@@ -5,14 +5,20 @@ import pandas as pd
|
|
| 5 |
import json
|
| 6 |
import base64
|
| 7 |
import io
|
| 8 |
-
|
| 9 |
|
| 10 |
-
#
|
|
|
|
|
|
|
|
|
|
| 11 |
app = dash.Dash(
|
| 12 |
__name__,
|
| 13 |
external_stylesheets=[dbc.themes.FLATLY],
|
| 14 |
title="PvRecNet",
|
| 15 |
-
suppress_callback_exceptions=True
|
|
|
|
|
|
|
|
|
|
| 16 |
)
|
| 17 |
|
| 18 |
# 2. Define the Main App Layout (Navigation + Page Container)
|
|
@@ -22,7 +28,6 @@ app.layout = html.Div([
|
|
| 22 |
html.Div(id='page-content') # Where different pages will be rendered
|
| 23 |
])
|
| 24 |
|
| 25 |
-
# --- PAGE 1: THE HELP / GUIDELINE PAGE ---
|
| 26 |
# --- PAGE 1: THE HELP / GUIDELINE PAGE ---
|
| 27 |
def render_help_page():
|
| 28 |
return dbc.Container([
|
|
@@ -37,12 +42,12 @@ def render_help_page():
|
|
| 37 |
html.H1("System Guidelines & Documentation", className="display-5 text-primary"),
|
| 38 |
html.P([
|
| 39 |
"PvRecNet is a deep learning-based model for ",
|
| 40 |
-
html.B(html.I("Plasmodium vivax")),
|
| 41 |
" recurrence classification."
|
| 42 |
], className="lead"),
|
| 43 |
], className="mb-5"),
|
| 44 |
|
| 45 |
-
#
|
| 46 |
dbc.Row([
|
| 47 |
# Section: Description
|
| 48 |
dbc.Col([
|
|
@@ -51,7 +56,7 @@ def render_help_page():
|
|
| 51 |
"Our architecture differentiates between ",
|
| 52 |
html.B("Recrudescence, Relapse, and Reinfection"),
|
| 53 |
". It is trained on probabilistic outputs from ",
|
| 54 |
-
html.A("Pv3Rs", href="https://github.com/aimeertaylor/Pv3Rs", target="_blank"),
|
| 55 |
" to ensure robust genomic classification."
|
| 56 |
]),
|
| 57 |
], md=6),
|
|
@@ -81,10 +86,9 @@ def render_help_page():
|
|
| 81 |
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."]),
|
| 82 |
html.Li([html.B("Generalization: "), "The model may not generalize well to genetic markers or alleles unobserved during training."]),
|
| 83 |
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."]),
|
| 84 |
-
|
| 85 |
], className="text-secondary"),
|
| 86 |
|
| 87 |
-
#
|
| 88 |
dbc.Card([
|
| 89 |
dbc.CardBody([
|
| 90 |
dbc.Row([
|
|
@@ -115,7 +119,6 @@ def render_main_app():
|
|
| 115 |
return dbc.Container([
|
| 116 |
dbc.Row([
|
| 117 |
dbc.Col(html.H1("PvRecNet", className="text-center my-4", style={"color":'#113d59'}), width=10),
|
| 118 |
-
# Help Link in Top Right
|
| 119 |
dbc.Col(html.A("Help & Guidelines", href="/help", className="text-muted", style={"marginTop": "30px", "display": "block"}), width=2)
|
| 120 |
]),
|
| 121 |
|
|
@@ -171,18 +174,6 @@ def render_main_app():
|
|
| 171 |
], className="mt-4"),
|
| 172 |
dbc.Row(dbc.Col(dbc.Card([dbc.CardHeader(html.B("Step 3: Model Results")), dbc.CardBody(dcc.Loading(id="prediction-output"))], className="mt-4 mb-5"), width=12))
|
| 173 |
]),
|
| 174 |
-
|
| 175 |
-
# # Tab 2: Analytics Tools
|
| 176 |
-
# dbc.Tab(label="Analytics Tools", tab_id="tab-analytics", children=[
|
| 177 |
-
# dbc.Row(dbc.Col(dbc.Card([
|
| 178 |
-
# dbc.CardHeader(html.B("Genomic Analytics")),
|
| 179 |
-
# dbc.CardBody([
|
| 180 |
-
# dbc.Button("Compute MOI", id="moi-btn", color="info", className="me-2"),
|
| 181 |
-
# dbc.Button("Compute Allele Freq", id="freq-btn", color="secondary"),
|
| 182 |
-
# html.Hr(), dcc.Loading(id="analytics-output")
|
| 183 |
-
# ])
|
| 184 |
-
# ], className="mt-4"), md=12))
|
| 185 |
-
# ])
|
| 186 |
])
|
| 187 |
], fluid=True)
|
| 188 |
|
|
@@ -192,8 +183,11 @@ def render_main_app():
|
|
| 192 |
prevent_initial_call=True,
|
| 193 |
)
|
| 194 |
def download_sample_data(n_clicks):
|
| 195 |
-
#
|
| 196 |
-
|
|
|
|
|
|
|
|
|
|
| 197 |
return dcc.send_data_frame(sample_df.to_csv, "pvrecnet_sample_data.csv", index=False)
|
| 198 |
|
| 199 |
# --- ROUTER CALLBACK ---
|
|
@@ -216,7 +210,7 @@ def display_page(pathname):
|
|
| 216 |
def navigate_to_predict(n_clicks):
|
| 217 |
return "tab-predict" if n_clicks else "tab-intro"
|
| 218 |
|
| 219 |
-
# --- FUNCTIONAL CALLBACKS
|
| 220 |
|
| 221 |
@app.callback(
|
| 222 |
[Output('dataset-id-store', 'data'), Output('upload-status', 'children'), Output('predict-btn', 'disabled'),
|
|
@@ -240,32 +234,26 @@ def handle_upload(contents, filename):
|
|
| 240 |
State('dataset-id-store', 'data'),
|
| 241 |
prevent_initial_call=True
|
| 242 |
)
|
| 243 |
-
|
| 244 |
def run_predict(n_clicks, dataset_id):
|
| 245 |
try:
|
| 246 |
res = PvRecNetAPI.run_prediction(dataset_id)
|
| 247 |
fig1 = json.loads(res['plot_json1'])
|
| 248 |
fig2 = json.loads(res['plot_json2'])
|
| 249 |
|
| 250 |
-
# 1. Convert the results list to a DataFrame
|
| 251 |
df = pd.DataFrame(res['results_table'])
|
| 252 |
-
|
| 253 |
-
# 2. Identify the probability columns (adjust names based on your actual API output)
|
| 254 |
-
prob_cols = ['C_marg', 'L_marg', 'I_marg'] # or 'post_C', etc.
|
| 255 |
|
| 256 |
-
# 3. Apply string formatting for consistent visual alignment
|
| 257 |
for col in prob_cols:
|
| 258 |
if col in df.columns:
|
| 259 |
df[col] = df[col].map(lambda x: f"{x:.4f}" if pd.notnull(x) else x)
|
| 260 |
|
| 261 |
-
# 4. Create the DataTable using the formatted data
|
| 262 |
table = dash_table.DataTable(
|
| 263 |
data=df.to_dict('records'),
|
| 264 |
columns=[{"name": i, "id": i} for i in df.columns],
|
| 265 |
export_format='csv',
|
| 266 |
page_size=10,
|
| 267 |
style_table={'height': '400px', 'overflowY': 'auto'},
|
| 268 |
-
style_cell={'textAlign': 'left'}
|
| 269 |
)
|
| 270 |
|
| 271 |
return html.Div([
|
|
@@ -277,24 +265,6 @@ def run_predict(n_clicks, dataset_id):
|
|
| 277 |
except Exception as e:
|
| 278 |
return dbc.Alert(f"Error: {str(e)}", color="danger")
|
| 279 |
|
| 280 |
-
# @app.callback(
|
| 281 |
-
# Output('analytics-output', 'children'),
|
| 282 |
-
# [Input('moi-btn', 'n_clicks'), Input('freq-btn', 'n_clicks')],
|
| 283 |
-
# State('dataset-id-store', 'data'),
|
| 284 |
-
# prevent_initial_call=True
|
| 285 |
-
# )
|
| 286 |
-
# def handle_analytics(moi_n, freq_n, dataset_id):
|
| 287 |
-
# ctx = callback_context
|
| 288 |
-
# bid = ctx.triggered[0]['prop_id'].split('.')[0]
|
| 289 |
-
# try:
|
| 290 |
-
# if bid == "moi-btn":
|
| 291 |
-
# res = PvRecNetAPI.get_moi(dataset_id)
|
| 292 |
-
# return dash_table.DataTable(data=res, columns=[{"name": i, "id": i} for i in pd.DataFrame(res).columns], export_format='csv')
|
| 293 |
-
# else:
|
| 294 |
-
# res = PvRecNetAPI.get_allele_freq(dataset_id)
|
| 295 |
-
# import plotly.express as px
|
| 296 |
-
# return dcc.Graph(figure=px.pie(res, names='allele', values='frequency'))
|
| 297 |
-
# except Exception as e: return dbc.Alert(str(e), color="danger")
|
| 298 |
-
|
| 299 |
if __name__ == '__main__':
|
| 300 |
-
|
|
|
|
|
|
| 5 |
import json
|
| 6 |
import base64
|
| 7 |
import io
|
| 8 |
+
import os # Added for robust path parsing
|
| 9 |
|
| 10 |
+
# Ensure Python treats imports seamlessly relative to our app root folder
|
| 11 |
+
from frontend.services.api import PvRecNetAPI
|
| 12 |
+
|
| 13 |
+
# 1. Initialize App with Hugging Face proxy configurations
|
| 14 |
app = dash.Dash(
|
| 15 |
__name__,
|
| 16 |
external_stylesheets=[dbc.themes.FLATLY],
|
| 17 |
title="PvRecNet",
|
| 18 |
+
suppress_callback_exceptions=True,
|
| 19 |
+
# Crucial parameters for WSGI middleware hosting:
|
| 20 |
+
requests_pathname_prefix="/",
|
| 21 |
+
routes_pathname_prefix="/"
|
| 22 |
)
|
| 23 |
|
| 24 |
# 2. Define the Main App Layout (Navigation + Page Container)
|
|
|
|
| 28 |
html.Div(id='page-content') # Where different pages will be rendered
|
| 29 |
])
|
| 30 |
|
|
|
|
| 31 |
# --- PAGE 1: THE HELP / GUIDELINE PAGE ---
|
| 32 |
def render_help_page():
|
| 33 |
return dbc.Container([
|
|
|
|
| 42 |
html.H1("System Guidelines & Documentation", className="display-5 text-primary"),
|
| 43 |
html.P([
|
| 44 |
"PvRecNet is a deep learning-based model for ",
|
| 45 |
+
html.B(html.I("Plasmodium vivax")),
|
| 46 |
" recurrence classification."
|
| 47 |
], className="lead"),
|
| 48 |
], className="mb-5"),
|
| 49 |
|
| 50 |
+
# Visual Appeal: Use Cards for Sections
|
| 51 |
dbc.Row([
|
| 52 |
# Section: Description
|
| 53 |
dbc.Col([
|
|
|
|
| 56 |
"Our architecture differentiates between ",
|
| 57 |
html.B("Recrudescence, Relapse, and Reinfection"),
|
| 58 |
". It is trained on probabilistic outputs from ",
|
| 59 |
+
html.A("Pv3Rs", href="https://github.com/aimeertaylor/Pv3Rs", target="_blank"),
|
| 60 |
" to ensure robust genomic classification."
|
| 61 |
]),
|
| 62 |
], md=6),
|
|
|
|
| 86 |
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."]),
|
| 87 |
html.Li([html.B("Generalization: "), "The model may not generalize well to genetic markers or alleles unobserved during training."]),
|
| 88 |
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."]),
|
|
|
|
| 89 |
], className="text-secondary"),
|
| 90 |
|
| 91 |
+
# Sample Dataset Section
|
| 92 |
dbc.Card([
|
| 93 |
dbc.CardBody([
|
| 94 |
dbc.Row([
|
|
|
|
| 119 |
return dbc.Container([
|
| 120 |
dbc.Row([
|
| 121 |
dbc.Col(html.H1("PvRecNet", className="text-center my-4", style={"color":'#113d59'}), width=10),
|
|
|
|
| 122 |
dbc.Col(html.A("Help & Guidelines", href="/help", className="text-muted", style={"marginTop": "30px", "display": "block"}), width=2)
|
| 123 |
]),
|
| 124 |
|
|
|
|
| 174 |
], className="mt-4"),
|
| 175 |
dbc.Row(dbc.Col(dbc.Card([dbc.CardHeader(html.B("Step 3: Model Results")), dbc.CardBody(dcc.Loading(id="prediction-output"))], className="mt-4 mb-5"), width=12))
|
| 176 |
]),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
])
|
| 178 |
], fluid=True)
|
| 179 |
|
|
|
|
| 183 |
prevent_initial_call=True,
|
| 184 |
)
|
| 185 |
def download_sample_data(n_clicks):
|
| 186 |
+
# Safe path constructor that works perfectly both locally and inside the Hugging Face Docker Container
|
| 187 |
+
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 188 |
+
sample_path = os.path.join(base_dir, 'backend', 'PvDeepSetNet', 'datasets', 'GUI_sample_dataset.csv')
|
| 189 |
+
|
| 190 |
+
sample_df = pd.read_csv(sample_path)
|
| 191 |
return dcc.send_data_frame(sample_df.to_csv, "pvrecnet_sample_data.csv", index=False)
|
| 192 |
|
| 193 |
# --- ROUTER CALLBACK ---
|
|
|
|
| 210 |
def navigate_to_predict(n_clicks):
|
| 211 |
return "tab-predict" if n_clicks else "tab-intro"
|
| 212 |
|
| 213 |
+
# --- FUNCTIONAL CALLBACKS ---
|
| 214 |
|
| 215 |
@app.callback(
|
| 216 |
[Output('dataset-id-store', 'data'), Output('upload-status', 'children'), Output('predict-btn', 'disabled'),
|
|
|
|
| 234 |
State('dataset-id-store', 'data'),
|
| 235 |
prevent_initial_call=True
|
| 236 |
)
|
|
|
|
| 237 |
def run_predict(n_clicks, dataset_id):
|
| 238 |
try:
|
| 239 |
res = PvRecNetAPI.run_prediction(dataset_id)
|
| 240 |
fig1 = json.loads(res['plot_json1'])
|
| 241 |
fig2 = json.loads(res['plot_json2'])
|
| 242 |
|
|
|
|
| 243 |
df = pd.DataFrame(res['results_table'])
|
| 244 |
+
prob_cols = ['C_marg', 'L_marg', 'I_marg']
|
|
|
|
|
|
|
| 245 |
|
|
|
|
| 246 |
for col in prob_cols:
|
| 247 |
if col in df.columns:
|
| 248 |
df[col] = df[col].map(lambda x: f"{x:.4f}" if pd.notnull(x) else x)
|
| 249 |
|
|
|
|
| 250 |
table = dash_table.DataTable(
|
| 251 |
data=df.to_dict('records'),
|
| 252 |
columns=[{"name": i, "id": i} for i in df.columns],
|
| 253 |
export_format='csv',
|
| 254 |
page_size=10,
|
| 255 |
style_table={'height': '400px', 'overflowY': 'auto'},
|
| 256 |
+
style_cell={'textAlign': 'left'}
|
| 257 |
)
|
| 258 |
|
| 259 |
return html.Div([
|
|
|
|
| 265 |
except Exception as e:
|
| 266 |
return dbc.Alert(f"Error: {str(e)}", color="danger")
|
| 267 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
if __name__ == '__main__':
|
| 269 |
+
# Local fallback runner
|
| 270 |
+
app.run_server(debug=True, port=8050)
|
requirements.txt
CHANGED
|
@@ -1,6 +1,110 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
annotated-doc==0.0.4
|
| 2 |
+
annotated-types==0.7.0
|
| 3 |
+
anyio==4.13.0
|
| 4 |
+
asttokens @ file:///home/conda/feedstock_root/build_artifacts/asttokens_1763409923949/work
|
| 5 |
+
attrs==26.1.0
|
| 6 |
+
blinker==1.9.0
|
| 7 |
+
brotlicffi @ file:///C:/miniconda3/conda-bld/brotlicffi_1764961372591/work
|
| 8 |
+
build==1.4.2
|
| 9 |
+
certifi @ file:///C:/Users/task_176765902528894/croot/certifi_1767659216804/work/certifi
|
| 10 |
+
cffi @ file:///C:/miniconda3/conda-bld/cffi_1761832794697/work
|
| 11 |
+
charset-normalizer @ file:///C:/miniconda3/conda-bld/charset-normalizer_1761744944645/work
|
| 12 |
+
click==8.3.2
|
| 13 |
+
colorama @ file:///home/conda/feedstock_root/build_artifacts/colorama_1733218098505/work
|
| 14 |
+
comm @ file:///home/conda/feedstock_root/build_artifacts/bld/rattler-build_comm_1753453984/work
|
| 15 |
+
contourpy==1.3.2
|
| 16 |
+
cycler==0.12.1
|
| 17 |
+
dash==4.1.0
|
| 18 |
+
dash-bootstrap-components==2.0.4
|
| 19 |
+
debugpy @ file:///D:/bld/bld/rattler-build_debugpy_1769745019/work
|
| 20 |
+
decorator @ file:///home/conda/feedstock_root/build_artifacts/decorator_1740384970518/work
|
| 21 |
+
exceptiongroup @ file:///home/conda/feedstock_root/build_artifacts/exceptiongroup_1763918002538/work
|
| 22 |
+
executing @ file:///home/conda/feedstock_root/build_artifacts/executing_1756729339227/work
|
| 23 |
+
fastapi==0.135.3
|
| 24 |
+
fastjsonschema==2.21.2
|
| 25 |
+
filelock @ file:///C:/Users/task_176943980686702/croot/filelock_1769440565956/work
|
| 26 |
+
Flask==3.1.3
|
| 27 |
+
fonttools==4.62.1
|
| 28 |
+
gmpy2 @ file:///C:/miniconda3/conda-bld/gmpy2_1764748105976/work
|
| 29 |
+
h11==0.16.0
|
| 30 |
+
httptools==0.7.1
|
| 31 |
+
idna @ file:///C:/miniconda3/conda-bld/idna_1761912044311/work
|
| 32 |
+
importlib_metadata==9.0.0
|
| 33 |
+
ipykernel @ file:///D:/bld/bld/rattler-build_ipykernel_1770566174/work
|
| 34 |
+
ipython @ file:///D:/bld/bld/rattler-build_ipython_1748711254/work
|
| 35 |
+
itsdangerous==2.2.0
|
| 36 |
+
jedi @ file:///home/conda/feedstock_root/build_artifacts/jedi_1733300866624/work
|
| 37 |
+
Jinja2 @ file:///C:/b/abs_920kup4e6u/croot/jinja2_1741711580669/work
|
| 38 |
+
joblib==1.5.3
|
| 39 |
+
jsonschema==4.26.0
|
| 40 |
+
jsonschema-specifications==2025.9.1
|
| 41 |
+
jupyter_client @ file:///home/conda/feedstock_root/build_artifacts/bld/rattler-build_jupyter_client_1767954655/work
|
| 42 |
+
jupyter_core @ file:///D:/bld/bld/rattler-build_jupyter_core_1760643889/work
|
| 43 |
+
kiwisolver==1.5.0
|
| 44 |
+
MarkupSafe @ file:///C:/b/abs_a0ma7ge0jc/croot/markupsafe_1738584052792/work
|
| 45 |
+
matplotlib==3.10.8
|
| 46 |
+
matplotlib-inline @ file:///home/conda/feedstock_root/build_artifacts/matplotlib-inline_1761214490209/work
|
| 47 |
+
mkl-service==2.4.0
|
| 48 |
+
mkl_fft @ file:///C:/Users/dev-admin/mkl/mkl_fft_1730823082242/work
|
| 49 |
+
mkl_random @ file:///C:/Users/dev-admin/mkl/mkl_random_1730822522280/work
|
| 50 |
+
mpmath @ file:///C:/b/abs_7833jrbiox/croot/mpmath_1690848321154/work
|
| 51 |
+
narwhals==2.18.1
|
| 52 |
+
nbformat==5.10.4
|
| 53 |
+
nest_asyncio @ file:///home/conda/feedstock_root/build_artifacts/nest-asyncio_1733325553580/work
|
| 54 |
+
networkx @ file:///C:/b/abs_b054htfn9t/croot/networkx_1737043671910/work
|
| 55 |
+
numpy @ file:///C:/b/abs_0123vcxhf8/croot/numpy_and_numpy_base_1725470331966/work/dist/numpy-2.0.1-cp310-cp310-win_amd64.whl#sha256=e824ec3b279f4c5207736c83ac2f2dc79b489e08501a4ea9e3fc178c45db289b
|
| 56 |
+
packaging==26.0
|
| 57 |
+
pandas==2.3.3
|
| 58 |
+
parso @ file:///home/conda/feedstock_root/build_artifacts/bld/rattler-build_parso_1770676243/work
|
| 59 |
+
pickleshare @ file:///home/conda/feedstock_root/build_artifacts/pickleshare_1733327343728/work
|
| 60 |
+
pillow @ file:///D:/bld/bld/rattler-build_pillow_1770794018/work
|
| 61 |
+
platformdirs @ file:///home/conda/feedstock_root/build_artifacts/bld/rattler-build_platformdirs_1773199142/work
|
| 62 |
+
plotly==6.6.0
|
| 63 |
+
prompt_toolkit @ file:///home/conda/feedstock_root/build_artifacts/prompt-toolkit_1756321756983/work
|
| 64 |
+
psutil @ file:///D:/bld/bld/rattler-build_psutil_1769678167/work
|
| 65 |
+
pure_eval @ file:///home/conda/feedstock_root/build_artifacts/pure_eval_1733569405015/work
|
| 66 |
+
# Editable install with no version control (PvDeepSetNet==0.1.0)
|
| 67 |
+
-e d:\educational\pvrecnet\backend\pvdeepsetnet
|
| 68 |
+
pycparser @ file:///C:/Users/task_177495971250430/croot/pycparser_1774959822609/work
|
| 69 |
+
pydantic==2.13.1
|
| 70 |
+
pydantic_core==2.46.1
|
| 71 |
+
Pygments @ file:///home/conda/feedstock_root/build_artifacts/pygments_1774796700044/work
|
| 72 |
+
pyparsing==3.3.2
|
| 73 |
+
pyproject_hooks==1.2.0
|
| 74 |
+
PySocks @ file:///C:/miniconda3/conda-bld/pysocks_1761753030270/work
|
| 75 |
+
python-dateutil @ file:///home/conda/feedstock_root/build_artifacts/bld/rattler-build_python-dateutil_1751104122/work
|
| 76 |
+
python-dotenv==1.2.2
|
| 77 |
+
python-multipart==0.0.26
|
| 78 |
+
pytz==2026.1.post1
|
| 79 |
+
pywin32 @ file:///D:/bld/bld/rattler-build_pywin32_1756487147/work
|
| 80 |
+
PyYAML @ file:///C:/miniconda3/conda-bld/pyyaml_1763465513320/work
|
| 81 |
+
pyzmq @ file:///D:/bld/bld/rattler-build_pyzmq_1771716971/work
|
| 82 |
+
referencing==0.37.0
|
| 83 |
+
requests @ file:///C:/Users/task_177506608527885/croot/requests_1775066155000/work
|
| 84 |
+
retrying==1.4.2
|
| 85 |
+
rpds-py==0.30.0
|
| 86 |
+
scikit-learn==1.7.2
|
| 87 |
+
scipy==1.15.3
|
| 88 |
+
seaborn==0.13.2
|
| 89 |
+
six @ file:///home/conda/feedstock_root/build_artifacts/bld/rattler-build_six_1753199211/work
|
| 90 |
+
stack_data @ file:///home/conda/feedstock_root/build_artifacts/stack_data_1733569443808/work
|
| 91 |
+
starlette==1.0.0
|
| 92 |
+
sympy @ file:///C:/miniconda3/conda-bld/sympy_1764762978780/work
|
| 93 |
+
threadpoolctl==3.6.0
|
| 94 |
+
tomli==2.4.1
|
| 95 |
+
torch==2.5.1
|
| 96 |
+
torchaudio==2.5.1
|
| 97 |
+
torchvision==0.20.1
|
| 98 |
+
tornado @ file:///D:/bld/tornado_1774357955344/work
|
| 99 |
+
traitlets @ file:///home/conda/feedstock_root/build_artifacts/traitlets_1733367359838/work
|
| 100 |
+
typing-inspection==0.4.2
|
| 101 |
+
typing_extensions @ file:///home/conda/feedstock_root/build_artifacts/bld/rattler-build_typing_extensions_1756220668/work
|
| 102 |
+
tzdata==2026.1
|
| 103 |
+
urllib3 @ file:///C:/Users/task_176781036207501/croot/urllib3_1767810484846/work
|
| 104 |
+
uvicorn==0.44.0
|
| 105 |
+
watchfiles==1.1.1
|
| 106 |
+
wcwidth @ file:///home/conda/feedstock_root/build_artifacts/wcwidth_1770634525285/work
|
| 107 |
+
websockets==16.0
|
| 108 |
+
Werkzeug==3.1.8
|
| 109 |
+
win_inet_pton @ file:///C:/miniconda3/conda-bld/win_inet_pton_1761746276406/work
|
| 110 |
+
zipp==3.23.0
|