omarbajouk commited on
Commit
d72142f
·
verified ·
1 Parent(s): d1d656e

Delete src/ui.py

Browse files
Files changed (1) hide show
  1. src/ui.py +0 -123
src/ui.py DELETED
@@ -1,123 +0,0 @@
1
- import gradio as gr
2
- from .config import THEMES
3
- from .tts_utils import get_edge_voices, init_edge_voices
4
- from .capsule_builder import (
5
- build_capsule, table_capsules, assemble_final, supprimer_capsule, deplacer_capsule
6
- )
7
-
8
- def build_ui():
9
- print("[INIT] Lancement de Gradio...")
10
- init_edge_voices()
11
-
12
- with gr.Blocks(title="Créateur de Capsules CPAS – Version avec vidéo présentateur",
13
- theme=gr.themes.Soft()) as demo:
14
-
15
- gr.Markdown("## 🎬 Créateur de Capsules CPAS – Version avec vidéo présentateur")
16
- gr.Markdown("**Nouveau** : Utilisez directement une vidéo de présentateur au lieu d'une image.")
17
-
18
- with gr.Tab("Créer une capsule"):
19
- with gr.Row():
20
- with gr.Column():
21
- image_fond = gr.Image(label="🖼 Image de fond", type="filepath")
22
- fond_mode = gr.Radio(["plein écran", "moitié gauche", "moitié droite", "moitié bas"],
23
- label="Mode d'affichage du fond", value="plein écran")
24
- logo_path = gr.Image(label="🏛 Logo", type="filepath")
25
- logo_pos = gr.Radio(["haut-gauche","haut-droite","centre"],
26
- label="Position logo", value="haut-gauche")
27
- video_presentateur = gr.Video(label="🎬 Vidéo du présentateur")
28
- position_presentateur = gr.Radio(["bottom-right","bottom-left","top-right","top-left","center"],
29
- label="Position", value="bottom-right")
30
- plein = gr.Checkbox(label="Plein écran présentateur", value=False)
31
- with gr.Column():
32
- titre = gr.Textbox(label="Titre", value="Aide médicale urgente / Dringende medische hulp")
33
- sous_titre = gr.Textbox(label="Sous-titre", value="Soins accessibles à tous / Toegankelijke zorg voor iedereen")
34
- theme = gr.Radio(list(THEMES.keys()), label="Thème", value="Bleu Professionnel")
35
- langue = gr.Radio(["fr", "nl"], label="Langue de la voix", value="fr")
36
-
37
- def maj_voix(lang):
38
- try:
39
- voices = get_edge_voices(lang)
40
- return gr.update(choices=voices, value=voices[0] if voices else None)
41
- except Exception:
42
- return gr.update(choices=[], value=None)
43
-
44
- speaker_id = gr.Dropdown(
45
- label="🎙 Voix Edge-TTS",
46
- choices=get_edge_voices("fr"),
47
- value="fr-FR-DeniseNeural",
48
- info="Liste dynamique des voix Edge-TTS (FR & NL)"
49
- )
50
- langue.change(maj_voix, [langue], [speaker_id])
51
-
52
- voix_type = gr.Radio(["Féminine","Masculine"], label="Voix IA", value="Féminine")
53
- moteur_voix = gr.Radio(["Edge-TTS (recommandé)", "gTTS (fallback)"],
54
- label="Moteur voix", value="Edge-TTS (recommandé)")
55
- texte_voix = gr.Textbox(label="Texte voix off", lines=4,
56
- value="Bonjour, le CPAS de Bruxelles vous aide pour vos soins de santé.")
57
- texte_ecran = gr.Textbox(label="Texte à l'écran", lines=4,
58
- value="💊 Aides médicales\n🏥 Soins urgents\n📋 Formalités simplifiées")
59
- btn = gr.Button("🎬 Créer Capsule", variant="primary")
60
-
61
- sortie = gr.Video(label="Capsule générée")
62
- srt_out = gr.File(label="Sous-titres .srt")
63
- statut = gr.Markdown()
64
-
65
- with gr.Tab("Gestion & Assemblage"):
66
- gr.Markdown("### 🗂 Gestion des capsules")
67
- liste = gr.Dataframe(
68
- headers=["N°","Titre","Langue","Durée","Thème","Voix","Fichier"],
69
- value=table_capsules(),
70
- interactive=False
71
- )
72
- with gr.Row():
73
- index = gr.Number(label="Index capsule", value=1, precision=0)
74
- btn_up = gr.Button("⬆️ Monter")
75
- btn_down = gr.Button("⬇️ Descendre")
76
- btn_del = gr.Button("🗑 Supprimer")
77
- message = gr.Markdown()
78
-
79
- btn_up.click(lambda i: deplacer_capsule(i, "up"), [index], [message, liste])
80
- btn_down.click(lambda i: deplacer_capsule(i, "down"), [index], [message, liste])
81
- btn_del.click(supprimer_capsule, [index], [message, liste])
82
-
83
- gr.Markdown("### 🎬 Assemblage final")
84
- btn_asm = gr.Button("🎥 Assembler la vidéo complète", variant="primary")
85
- sortie_finale = gr.Video(label="Vidéo finale")
86
- btn_asm.click(lambda: assemble_final(), [], [sortie_finale, message])
87
-
88
- # --- Export ZIP intégré ---
89
- from .capsule_builder import export_project_zip
90
- btn_zip = gr.Button("📦 Télécharger projet complet (ZIP)", variant="secondary")
91
- zip_file = gr.File(label="ZIP exporté")
92
-
93
- def zip_action():
94
- path = export_project_zip()
95
- if path and os.path.exists(path):
96
- return path
97
- else:
98
- raise gr.Error("Erreur : impossible de générer le ZIP.")
99
-
100
- btn_zip.click(zip_action, [], [zip_file])
101
-
102
-
103
- def creer_capsule_ui(t, st, tv, te, th, img, fmode, logo, pos_logo, vp, vx, pos_p, plein, motor, lang, speaker):
104
- try:
105
- vid, msg, srt = build_capsule(t, st, tv, te, th,
106
- img, logo, pos_logo, fmode,
107
- vp, vx, pos_p, plein,
108
- motor, lang, speaker=speaker)
109
- return vid, srt, msg, table_capsules()
110
- except Exception as e:
111
- import traceback
112
- return None, None, f"❌ Erreur: {e}\n\n{traceback.format_exc()}", table_capsules()
113
-
114
- btn.click(
115
- creer_capsule_ui,
116
- [titre, sous_titre, texte_voix, texte_ecran, theme,
117
- image_fond, fond_mode, logo_path, logo_pos,
118
- video_presentateur, voix_type, position_presentateur,
119
- plein, moteur_voix, langue, speaker_id],
120
- [sortie, srt_out, statut, liste]
121
- )
122
-
123
- return demo