correction bug
This commit is contained in:
37
scripts/webui/audio_action.py
Normal file
37
scripts/webui/audio_action.py
Normal file
@ -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)}"
|
||||
@ -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 .
|
||||
|
||||
|
||||
Reference in New Issue
Block a user