File size: 6,864 Bytes
8086e8b
8a9498e
7204409
8a9498e
 
 
8dcd29d
5dfe91a
7204409
5dfe91a
 
 
8086e8b
5dfe91a
 
 
7204409
4b8f61c
7204409
 
 
 
 
 
 
4b8f61c
7204409
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4b8f61c
7204409
4b8f61c
7204409
 
 
 
 
 
 
 
 
 
 
 
 
 
4b8f61c
7204409
 
 
 
 
 
 
 
 
 
 
4150623
7204409
 
 
 
 
 
 
 
 
 
 
 
4b8f61c
7204409
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4b8f61c
 
7204409
 
 
 
 
 
 
 
 
 
 
ed10808
 
e763436
7204409
 
4b8f61c
7204409
 
 
 
 
 
 
 
 
 
 
 
 
8086e8b
7204409
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import dash_bootstrap_components as dbc
from dash import dcc, html
from pathlib import Path
from dotenv import load_dotenv

load_dotenv()
BUCKET_NAME = "moore-collection"

# --- Helper pour récupérer les chapitres ---
def get_chapter_paths(base_folder):
    base = Path(base_folder)
    return [d for d in base.iterdir() if d.is_dir()]

chapters = get_chapter_paths("assets")
chapter_options = [{"label": d.name, "value": str(d)} for d in chapters]

# --- Fonctions de création des différentes cards ---

def header_card():
    """Carte d'en-tête avec le titre de l'application."""
    return dbc.Row(
        dbc.Col(
            html.H1(
                "Outil de transcription audio",
                className="text-center my-4 text-primary",
            ),
            width=12,
        )
    )

def user_info_card():
    """Carte pour la saisie des informations utilisateur."""
    return dbc.Row(
        dbc.Col(
            [
                dbc.Input(
                    id="user-info",
                    placeholder="Entrez votre email, pseudonyme ou nom pour qu'on vous crédite",
                    type="text",
                    className="mb-3",
                ),
                dbc.Button(
                    "Continuer",
                    id="pseudo-continue-button",
                    color="primary",
                    className="w-100",
                ),
            ],
            width=12,
        )
    )

def chapter_card():
    """Carte pour la sélection d'un chapitre."""
    return dbc.Row(
        id="chapter-section",
        style={"display": "none"},
        children=[
            dbc.Col(
                dbc.Card(
                    [
                        dbc.CardHeader("Sélectionnez un chapitre"),
                        dbc.CardBody(
                            [
                                dcc.Dropdown(
                                    id="chapter-dropdown",
                                    options=chapter_options,
                                    placeholder="Choisissez un chapitre",
                                ),
                                dbc.Button(
                                    "Continuer",
                                    id="chapter-continue-button",
                                    color="primary",
                                    className="w-100 mt-2",
                                ),
                            ]
                        ),
                    ]
                ),
                width=12,
            )
        ],
    )

def page_card():
    """Carte pour la sélection d'une page."""
    return dbc.Row(
        id="page-section",
        style={"display": "none"},
        children=[
            dbc.Col(
                dbc.Card(
                    [
                        dbc.CardHeader("Sélectionnez une page"),
                        dbc.CardBody(
                            [
                                dcc.Dropdown(
                                    id="page-dropdown",
                                    placeholder="Choisissez une page",
                                ),
                                dbc.Button(
                                    "Démarrer la transcription",
                                    id="start-button",
                                    color="primary",
                                    className="w-100 mt-2",
                                ),
                            ]
                        ),
                    ]
                ),
                width=12,
            )
        ],
    )

def transcription_card():
    """Carte regroupant la lecture audio, les suggestions et les actions de transcription."""
    audio_card = dbc.Card(
        [
            dbc.CardHeader("Lecture audio"),
            dbc.CardBody(
                dcc.Loading(
                    html.Audio(
                        id="audio-player",
                        controls=True,
                        autoPlay=False,
                        className="w-100",
                    )
                )
            ),
        ],
        className="mb-4 shadow",
    )

    suggestion_card = dbc.Card(
        [
            dbc.CardHeader("Suggestions de transcriptions"),
            dbc.CardBody(
                dcc.Checklist(
                    id="suggestion-checklist",
                    options=[],  # Initialement vide, sera mis à jour via callback
                    value=[],
                    style={"columns": "3", "column-gap": "1rem"},
                )
            ),
        ],
        className="mb-4 shadow",
    )

    hidden_message = html.Div(
        id="hidden-message",
        style={"display": "none"},
        children=[
            html.P(
                "Traitement de la page actuelle terminé, vous devez changer de page pour continuer. N'oubliez pas de sauvegarder.",
                style={"color": "red"},
            )
        ],
    )

    action_buttons = dbc.Col(
        [
            dbc.Button(
                "Soumettre",
                id="submit-button",
                n_clicks=0,
                color="secondary",
                className="w-100",
                style={"marginTop": "20px"},
            ),
            dbc.Button(
                "Sauvegarder résultats",
                id="save-results-button",
                n_clicks=0,
                color="success",
                className="w-100",
                style={"marginTop": "20px"},
            ),
        ],
        width=12,
    )

    confirmation_message = dbc.Col(
        html.Div(
            id="confirmation-message",
            className="text-success text-center mt-3",
        ),
        width=12,
    )

    # La carte de transcription regroupe plusieurs composants et dcc.Store pour l'état
    return dbc.Row(
        id="transcription-section",
        style={"display": "none"},
        children=[
            dbc.Col(audio_card, width=12),
            dbc.Col(suggestion_card, width=12),
            dbc.Col(hidden_message, width=12),
            action_buttons,
            confirmation_message,
            # Stores pour l'état de l'application
            dcc.Store(id="transcription-store", data=[], storage_type='session'),
            dcc.Store(id="audio-store", data=[], storage_type='session'),
            dcc.Store(id="values-store", data=[], storage_type='session'),
        ],
    )

def create_layout():
    """Compose le layout principal à partir des différentes cards."""
    return dbc.Container(
        [
            header_card(),
            user_info_card(),
            chapter_card(),
            page_card(),
            transcription_card(),
        ],
        fluid=True,
        className="p-4",
    )

# Initialisation du layout
layout = create_layout()
from .callbacks import *