Issues in displaying results in multi pages app

Hello All !

I am coding an app for health sector.
Output of pipeline results in PDF generated saved in ./src/assets/pdf. I verified PDF file exists.
I cannot succeed in having this PDF file downloaded in dash.
I finally wonder if dash is able to work with my app. structure…
Here is app. structure:

.
├── LICENSE.txt
├── README.md
├── constantes_sante.db
├── pyproject.toml
├── requirements.txt
├── src
│ ├── init.py
│ ├── pycache
│ │ ├── init.cpython-312.pyc
│ │ └── app.cpython-312.pyc
│ ├── app.py
│ ├── assets
│ │ ├── pdf
│ │ │ └── dupont_tension.pdf
│ │ └── plots
│ │ └── dupont_tension.png

│ ├── pages
│ │ ├── init.py
│ │ ├── pycache
│ │ │ ├── init.cpython-312.pyc
│ │ │ ├── chatbot_ui.cpython-312.pyc
│ │ │ └── home.cpython-312.pyc
│ │ ├── chatbot_ui.py
│ │ └── home.py

Here is chatbot_ui code responsible for displaying.

import dash
from dash import html, dcc, Input, Output, State, callback
import dash_bootstrap_components as dbc
import os
from pathlib import Path
from src.func.orchestrator import run_all_from_input


dash.register_page(__name__, path="/chatbot")

layout = dbc.Container([
    html.H2("🧠 Chatbot Synthèse Patient", className="mt-4"),
    dcc.Textarea(id="chatbot-input", placeholder="Tapez une requête", value="", style={"width": "100%", "height": 100}),
    dbc.Button("Envoyer", id="chatbot-btn", n_clicks=0, color="primary", className="mt-2"),
    html.Hr(),
    html.Div(id="chatbot-output", style={"marginTop": "20px", "border": "1px solid #ddd", "padding": "15px"})
])

@callback(
    Output("chatbot-output", "children"),
    Input("chatbot-btn", "n_clicks"),
    State("chatbot-input", "value"),
    prevent_initial_call=True
)
def update_chatbot(n_clicks, user_input):
    print("🔥 Callback chatbot lancé")

    if not user_input.strip():  # Protection contre input vide
        return dbc.Alert("❌ Merci de saisir une requête avant d'envoyer.", color="danger")


    try:
        pdf_path = run_all_from_input(user_input)
        print("📁 Chemin du PDF généré :", pdf_path)

        if not pdf_path or not isinstance(pdf_path, str):
            return dbc.Alert("❌ Échec lors de la génération de la synthèse.", color="danger")

        filename = os.path.basename(pdf_path)
        base_name = os.path.splitext(filename)[0]

        public_pdf_path = f"/assets/pdf/{filename}"
        public_img_path = f"/assets/plots/{base_name}.png"

        # Vérification fichiers
        if not (os.path.exists(f"./src{public_pdf_path}") and os.path.exists(f"./src{public_img_path}")):
            return dbc.Alert("❌ Fichiers PDF ou graphique non trouvés.", color="danger")

        return html.Div([
            dbc.Alert("✅ Synthèse générée avec succès !", color="success"),
            dbc.Button("📄 Télécharger le PDF", href=public_pdf_path, target="_blank", color="primary", className="mb-3"),
            html.Div("📈 Aperçu du graphique :", className="fw-bold mb-2"),
            html.Img(
                src=public_img_path,
                style={"width": "100%", "border": "1px solid #ccc", "padding": "10px", "borderRadius": "8px"},
                alt="Graphique non disponible"
            )
        ])

    except Exception as e:
        import traceback
        print("❌ ERREUR dans update_chatbot :")
        traceback.print_exc()
        return dbc.Alert(f"❌ Erreur interne : {str(e)}", color="danger")

If you have any idea on how to resolve this, it would be really great !

Many thanks for your time on this!

Hello @Olivier_fr I would write the file into a buffer instead of writing it on HDD. Then you will have to do something similar as here:

Some time ago I had to download zipped figures, maybe that helps:

1 Like

Many thanks for your time on this
I have to consider this option!
Thank you again!