From a143e27eeae463d6de0ab86f17cf24a17c3e5e2f Mon Sep 17 00:00:00 2001 From: nicoboy Date: Tue, 24 Feb 2026 15:33:05 +0100 Subject: [PATCH] correction bug --- scripts/webui/audio_action.py | 37 +++++++++++++++++++++++++++++++++++ services/audio-api/Dockerfile | 10 +++++++--- 2 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 scripts/webui/audio_action.py diff --git a/scripts/webui/audio_action.py b/scripts/webui/audio_action.py new file mode 100644 index 0000000..15b5989 --- /dev/null +++ b/scripts/webui/audio_action.py @@ -0,0 +1,37 @@ +import requests +import json + +class Action: + def __init__(self): + # L'URL interne au réseau Docker défini dans ton compose + self.api_url = "http://audio-api:7860/api/predict" + + async def action(self, body: dict, __user__: dict = None, __event_emitter__=None): + # 1. Récupérer le dernier message (le prompt) + last_message = body['messages'][-1]['content'] + + await __event_emitter__({ + "type": "status", + "data": {"description": "🎵 Génération de la musique en cours...", "done": False} + }) + + try: + # 2. Appel au container Audio-API (Gradio/FastAPI) + response = requests.post(self.api_url, json={ + "data": [last_message, 10] # Prompt + Durée + }, timeout=120) + + if response.status_code == 200: + result = response.json() + file_url = result['data'][0] # Chemin du .wav généré + + await __event_emitter__({ + "type": "status", + "data": {"description": "✅ Musique prête !", "done": True} + }) + + # 3. Envoyer le lien du fichier à l'étudiant + return f"Voici votre création : {file_url}" + + except Exception as e: + return f"❌ Erreur de connexion au studio audio : {str(e)}" \ No newline at end of file diff --git a/services/audio-api/Dockerfile b/services/audio-api/Dockerfile index 3ffe94f..3ee7436 100644 --- a/services/audio-api/Dockerfile +++ b/services/audio-api/Dockerfile @@ -10,11 +10,15 @@ RUN apt-get update && apt-get install -y \ python3.11 python3-pip ffmpeg libsndfile1 git \ && rm -rf /var/lib/apt/lists/* -# Installation des bibliothèques IA de base +# 1. Installer d'abord PyTorch depuis la source NVIDIA/CUDA RUN pip3 install --no-cache-dir \ - torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121 \ - fastapi uvicorn gradio + torch torchvision torchaudio \ + --index-url https://download.pytorch.org/whl/cu121 +# 2. Installer le reste depuis le dépôt Python standard (PyPI) +RUN pip3 install --no-cache-dir \ + fastapi uvicorn gradio + # Copie du code serveur COPY server.py .