Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import os
|
|
| 2 |
import base64
|
| 3 |
import tempfile
|
| 4 |
import gradio as gr
|
| 5 |
-
from sambanova import
|
| 6 |
from hume import HumeClient
|
| 7 |
from PIL import Image
|
| 8 |
import whisper
|
|
@@ -16,16 +16,15 @@ if not SAMBA_API_KEY:
|
|
| 16 |
if not HUME_API_KEY:
|
| 17 |
raise ValueError("Falta la variable de entorno: HUME_API_KEY")
|
| 18 |
|
| 19 |
-
SAMBA_BASE_URL = "https://api.sambanova.ai/v1"
|
| 20 |
VOICE_ID_DEFAULT = "085fdec7-b201-4a58-b65b-4d321f7abd85"
|
| 21 |
MODEL_NAME = "Llama-4-Maverick-17B-128E-Instruct"
|
| 22 |
|
| 23 |
# --- Inicializar clientes ---
|
| 24 |
-
samba =
|
| 25 |
hume = HumeClient(api_key=HUME_API_KEY)
|
| 26 |
|
| 27 |
-
# Cargar Whisper (
|
| 28 |
-
whisper_model = whisper.load_model("
|
| 29 |
|
| 30 |
# --- Funciones auxiliares ---
|
| 31 |
def imagen_pil_a_base64(pil_img):
|
|
@@ -40,7 +39,7 @@ def audio_a_texto(audio_path):
|
|
| 40 |
if not audio_path:
|
| 41 |
return ""
|
| 42 |
try:
|
| 43 |
-
result = whisper_model.transcribe(audio_path, language="es")
|
| 44 |
return result["text"].strip()
|
| 45 |
except Exception as e:
|
| 46 |
print("Error en Whisper STT:", e)
|
|
@@ -72,7 +71,7 @@ def generar_respuesta(texto, imagen_pil):
|
|
| 72 |
return respuesta.choices[0].message.content
|
| 73 |
except Exception as e:
|
| 74 |
print("Error en SambaNova:", e)
|
| 75 |
-
return "Lo siento, no pude procesar
|
| 76 |
|
| 77 |
def generar_audio(texto, voz_id=VOICE_ID_DEFAULT):
|
| 78 |
if not texto or not texto.strip():
|
|
|
|
| 2 |
import base64
|
| 3 |
import tempfile
|
| 4 |
import gradio as gr
|
| 5 |
+
from sambanova import Client # SDK oficial desde GitHub
|
| 6 |
from hume import HumeClient
|
| 7 |
from PIL import Image
|
| 8 |
import whisper
|
|
|
|
| 16 |
if not HUME_API_KEY:
|
| 17 |
raise ValueError("Falta la variable de entorno: HUME_API_KEY")
|
| 18 |
|
|
|
|
| 19 |
VOICE_ID_DEFAULT = "085fdec7-b201-4a58-b65b-4d321f7abd85"
|
| 20 |
MODEL_NAME = "Llama-4-Maverick-17B-128E-Instruct"
|
| 21 |
|
| 22 |
# --- Inicializar clientes ---
|
| 23 |
+
samba = Client(api_key=SAMBA_API_KEY) # ✅ Correcto según SDK de SambaNova
|
| 24 |
hume = HumeClient(api_key=HUME_API_KEY)
|
| 25 |
|
| 26 |
+
# Cargar modelo Whisper (ligero y rápido en Spaces)
|
| 27 |
+
whisper_model = whisper.load_model("base") # Usa "base" para evitar timeouts en Spaces gratuitos
|
| 28 |
|
| 29 |
# --- Funciones auxiliares ---
|
| 30 |
def imagen_pil_a_base64(pil_img):
|
|
|
|
| 39 |
if not audio_path:
|
| 40 |
return ""
|
| 41 |
try:
|
| 42 |
+
result = whisper_model.transcribe(audio_path, language="es")
|
| 43 |
return result["text"].strip()
|
| 44 |
except Exception as e:
|
| 45 |
print("Error en Whisper STT:", e)
|
|
|
|
| 71 |
return respuesta.choices[0].message.content
|
| 72 |
except Exception as e:
|
| 73 |
print("Error en SambaNova:", e)
|
| 74 |
+
return "Lo siento, no pude procesar tu solicitud. ¿Puedes repetirla?"
|
| 75 |
|
| 76 |
def generar_audio(texto, voz_id=VOICE_ID_DEFAULT):
|
| 77 |
if not texto or not texto.strip():
|