-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
335 lines (275 loc) · 9.33 KB
/
setup.py
File metadata and controls
335 lines (275 loc) · 9.33 KB
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
import os
import sys
import argparse
import subprocess
# Répertoire de base du projet
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# Structure de dossiers à créer
FOLDER_STRUCTURE = [
"logs",
"storage/news",
"storage/ai_news",
"storage/stories",
"storage/music",
"storage/jingles",
"storage/reminders",
"storage/logo",
"storage/playlists",
"storage/playlists/hourly",
"storage/tmp",
"storage/reference_clips",
]
# Programmes musicaux
MUSIC_PROGRAMS = [
"morning-serenity",
"rhythmic-morning",
"midday-metal-madness",
"afternoon-harmony",
"prime-time-tunes",
"nightly-rhythms",
"midnight-melodies",
]
# Programmes spéciaux
SPECIAL_PROGRAMS = [
"ai-news",
"news",
"bed-time",
]
def create_folder_structure():
"""Crée la structure de dossiers"""
print("Création de la structure de dossiers...")
for folder in FOLDER_STRUCTURE:
folder_path = os.path.join(BASE_DIR, folder)
os.makedirs(folder_path, exist_ok=True)
print(f" Créé: {folder_path}")
# Créer les sous-dossiers pour chaque programme musical
for program in MUSIC_PROGRAMS:
# Dossier de musique
music_path = os.path.join(BASE_DIR, "storage", "music", program)
os.makedirs(music_path, exist_ok=True)
print(f" Créé: {music_path}")
# Dossier de jingles
jingle_path = os.path.join(BASE_DIR, "storage", "jingles", program)
os.makedirs(jingle_path, exist_ok=True)
print(f" Créé: {jingle_path}")
# Dossier de rappels
reminder_path = os.path.join(BASE_DIR, "storage", "reminders", program)
os.makedirs(reminder_path, exist_ok=True)
print(f" Créé: {reminder_path}")
# Créer les sous-dossiers pour les programmes spéciaux
for program in SPECIAL_PROGRAMS:
jingle_path = os.path.join(BASE_DIR, "storage", "jingles", program)
os.makedirs(jingle_path, exist_ok=True)
print(f" Créé: {jingle_path}")
reminder_path = os.path.join(BASE_DIR, "storage", "reminders", program)
os.makedirs(reminder_path, exist_ok=True)
print(f" Créé: {reminder_path}")
print("Structure de dossiers créée avec succès.")
def create_env_file():
"""Crée le fichier .env"""
env_path = os.path.join(BASE_DIR, ".env")
if os.path.exists(env_path):
overwrite = (
input(
"Le fichier .env existe déjà. Voulez-vous le remplacer ? (o/N) "
).lower()
== "o"
)
if not overwrite:
print("Conservation du fichier .env existant.")
return
print("Création du fichier .env...")
news_api_key = input(
"Entrez votre clé API News (ou appuyez sur Entrée pour laisser vide): "
)
llama_model = (
input(
"Chemin vers le modèle LLaMA (ou appuyez sur Entrée pour la valeur par défaut): "
)
or "/path/to/llama-model.gguf"
)
base_path = (
input(
"Chemin de base du projet (ou appuyez sur Entrée pour utiliser le répertoire actuel): "
)
or BASE_DIR
)
with open(env_path, "w") as f:
f.write(f"NEWS_API_KEY={news_api_key}\n")
f.write(f"LLAMA_MODEL={llama_model}\n")
f.write(f"BASE_PATH={base_path}\n")
f.write("TTS_MODEL=tts_models/en/jenny/jenny\n")
f.write("TTS_GPU_ENABLED=True\n")
f.write("ICECAST_SERVER=localhost\n")
f.write("ICECAST_PORT=8000\n")
f.write("ICECAST_MOUNT=stream\n")
f.write("ICECAST_PASSWORD=hackme\n")
print(f"Fichier .env créé à {env_path}")
def install_requirements():
"""Installe les dépendances"""
print("Installation des dépendances...")
# Installer PyTorch séparément avec l'index URL
try:
subprocess.check_call(
[
sys.executable,
"-m",
"pip",
"install",
"torch",
"torchvision",
"torchaudio",
"--index-url",
"https://download.pytorch.org/whl/cu118",
]
)
print("PyTorch installé avec succès.")
except subprocess.CalledProcessError as e:
print(f"Erreur lors de l'installation de PyTorch: {e}")
print("Essai d'installation de PyTorch sans CUDA...")
try:
subprocess.check_call(
[
sys.executable,
"-m",
"pip",
"install",
"torch",
"torchvision",
"torchaudio",
]
)
print("PyTorch installé sans support CUDA.")
except:
print(
"Erreur lors de l'installation de PyTorch. Veuillez l'installer manuellement."
)
# Installer llama-cpp-python avec support CUDA
try:
print("Installation de llama-cpp-python avec support CUDA...")
env = os.environ.copy()
env["CMAKE_ARGS"] = "-DGGML_CUDA=on"
# Désinstaller la version existante
subprocess.check_call(
[sys.executable, "-m", "pip", "uninstall", "llama-cpp-python", "-y"]
)
# Nettoyer le cache pip
subprocess.check_call([sys.executable, "-m", "pip", "cache", "purge"])
# Installer depuis GitHub
subprocess.check_call(
[
sys.executable,
"-m",
"pip",
"install",
"git+https://github.com/abetlen/llama-cpp-python.git",
],
env=env,
)
print("llama-cpp-python installé avec succès (avec support CUDA).")
except subprocess.CalledProcessError as e:
print(f"Erreur lors de l'installation de llama-cpp-python avec CUDA: {e}")
print("Essai d'installation de llama-cpp-python sans CUDA...")
try:
subprocess.check_call(
[sys.executable, "-m", "pip", "install", "llama-cpp-python"]
)
print("llama-cpp-python installé sans support CUDA.")
except:
print(
"Erreur lors de l'installation de llama-cpp-python. Veuillez l'installer manuellement."
)
# Installer les autres dépendances
requirements = [
"TTS",
"newspaper3k",
"transformers",
"requests",
"python-dotenv",
"coloredlogs",
"pydub",
"matchering",
"mutagen",
"python-daemon",
"lxml[html_clean]",
"requests",
"flask",
"psutil",
"paramiko",
"langdetect",
"lxml_html_clean",
]
try:
subprocess.check_call([sys.executable, "-m", "pip", "install"] + requirements)
print("Dépendances installées avec succès.")
except subprocess.CalledProcessError as e:
print(f"Erreur lors de l'installation des dépendances: {e}")
print("Veuillez installer manuellement les packages requis.")
def create_readme():
"""Crée le fichier README.md"""
readme_path = os.path.join(BASE_DIR, "README.md")
if os.path.exists(readme_path):
return
print("Création du fichier README.md...")
readme_content = """# AI Harmony Radio System
Un système de webradio entièrement automatisé utilisant l'intelligence artificielle pour générer du contenu.
## Fonctionnalités
- Génération quotidienne de bulletins d'information
- Bulletins spéciaux sur l'intelligence artificielle
- Histoires au coucher générées par IA
- Programmation musicale automatisée
- Diffusion 24/7 via Icecast
## Installation
1. Clonez ce dépôt
2. Exécutez `python setup.py` pour configurer l'environnement
3. Placez vos fichiers audio dans les dossiers appropriés
4. Démarrez le service avec `python scheduler_service.py`
## Structure du projet
- `config/` - Fichiers de configuration
- `core/` - Modules principaux
- `models/` - Classes de données
- `utils/` - Utilitaires
- `storage/` - Fichiers générés et ressources
## Utilisation
Pour générer du contenu uniquement :
```
python main.py --content-only
```
Pour mettre à jour les playlists uniquement :
```
python main.py --schedule-only
```
Pour démarrer le service en mode démon :
```
python scheduler_service.py --daemon
```
## Licence
Ce projet est sous licence MIT. Voir le fichier LICENSE pour plus de détails.
"""
with open(readme_path, "w") as f:
f.write(readme_content)
print(f"Fichier README.md créé à {readme_path}")
def main():
parser = argparse.ArgumentParser(
description="Configuration initiale pour AI Harmony"
)
parser.add_argument(
"--no-requirements",
action="store_true",
help="Ne pas installer les dépendances",
)
args = parser.parse_args()
print("=== Configuration d'AI Harmony ===")
create_folder_structure()
create_env_file()
create_readme()
if not args.no_requirements:
install_requirements()
print("\nConfiguration terminée avec succès !")
print("Pour commencer, vous devez :")
print("1. Placer vos fichiers audio dans les dossiers appropriés")
print("2. Ajuster les paramètres dans le fichier .env")
print("3. Démarrer le service avec : python main.py")
print("\nBonne utilisation !")
if __name__ == "__main__":
main()