Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- 0.26.0 +24 -0
- app.py +155 -80
- requirements.txt +8 -8
0.26.0
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Requirement already satisfied: accelerate in c:\users\nelson\appdata\local\programs\python\python313\lib\site-packages (1.4.0)
|
| 2 |
+
Requirement already satisfied: numpy<3.0.0,>=1.17 in c:\users\nelson\appdata\local\programs\python\python313\lib\site-packages (from accelerate) (2.2.3)
|
| 3 |
+
Requirement already satisfied: packaging>=20.0 in c:\users\nelson\appdata\local\programs\python\python313\lib\site-packages (from accelerate) (24.2)
|
| 4 |
+
Requirement already satisfied: psutil in c:\users\nelson\appdata\local\programs\python\python313\lib\site-packages (from accelerate) (7.0.0)
|
| 5 |
+
Requirement already satisfied: pyyaml in c:\users\nelson\appdata\local\programs\python\python313\lib\site-packages (from accelerate) (6.0.2)
|
| 6 |
+
Requirement already satisfied: torch>=2.0.0 in c:\users\nelson\appdata\local\programs\python\python313\lib\site-packages (from accelerate) (2.6.0)
|
| 7 |
+
Requirement already satisfied: huggingface-hub>=0.21.0 in c:\users\nelson\appdata\local\programs\python\python313\lib\site-packages (from accelerate) (0.29.2)
|
| 8 |
+
Requirement already satisfied: safetensors>=0.4.3 in c:\users\nelson\appdata\local\programs\python\python313\lib\site-packages (from accelerate) (0.5.3)
|
| 9 |
+
Requirement already satisfied: filelock in c:\users\nelson\appdata\local\programs\python\python313\lib\site-packages (from huggingface-hub>=0.21.0->accelerate) (3.17.0)
|
| 10 |
+
Requirement already satisfied: fsspec>=2023.5.0 in c:\users\nelson\appdata\local\programs\python\python313\lib\site-packages (from huggingface-hub>=0.21.0->accelerate) (2025.3.0)
|
| 11 |
+
Requirement already satisfied: requests in c:\users\nelson\appdata\local\programs\python\python313\lib\site-packages (from huggingface-hub>=0.21.0->accelerate) (2.32.3)
|
| 12 |
+
Requirement already satisfied: tqdm>=4.42.1 in c:\users\nelson\appdata\local\programs\python\python313\lib\site-packages (from huggingface-hub>=0.21.0->accelerate) (4.67.1)
|
| 13 |
+
Requirement already satisfied: typing-extensions>=3.7.4.3 in c:\users\nelson\appdata\local\programs\python\python313\lib\site-packages (from huggingface-hub>=0.21.0->accelerate) (4.12.2)
|
| 14 |
+
Requirement already satisfied: networkx in c:\users\nelson\appdata\local\programs\python\python313\lib\site-packages (from torch>=2.0.0->accelerate) (3.4.2)
|
| 15 |
+
Requirement already satisfied: jinja2 in c:\users\nelson\appdata\local\programs\python\python313\lib\site-packages (from torch>=2.0.0->accelerate) (3.1.6)
|
| 16 |
+
Requirement already satisfied: setuptools in c:\users\nelson\appdata\local\programs\python\python313\lib\site-packages (from torch>=2.0.0->accelerate) (76.0.0)
|
| 17 |
+
Requirement already satisfied: sympy==1.13.1 in c:\users\nelson\appdata\local\programs\python\python313\lib\site-packages (from torch>=2.0.0->accelerate) (1.13.1)
|
| 18 |
+
Requirement already satisfied: mpmath<1.4,>=1.1.0 in c:\users\nelson\appdata\local\programs\python\python313\lib\site-packages (from sympy==1.13.1->torch>=2.0.0->accelerate) (1.3.0)
|
| 19 |
+
Requirement already satisfied: colorama in c:\users\nelson\appdata\local\programs\python\python313\lib\site-packages (from tqdm>=4.42.1->huggingface-hub>=0.21.0->accelerate) (0.4.6)
|
| 20 |
+
Requirement already satisfied: MarkupSafe>=2.0 in c:\users\nelson\appdata\local\programs\python\python313\lib\site-packages (from jinja2->torch>=2.0.0->accelerate) (3.0.2)
|
| 21 |
+
Requirement already satisfied: charset-normalizer<4,>=2 in c:\users\nelson\appdata\local\programs\python\python313\lib\site-packages (from requests->huggingface-hub>=0.21.0->accelerate) (3.4.1)
|
| 22 |
+
Requirement already satisfied: idna<4,>=2.5 in c:\users\nelson\appdata\local\programs\python\python313\lib\site-packages (from requests->huggingface-hub>=0.21.0->accelerate) (3.10)
|
| 23 |
+
Requirement already satisfied: urllib3<3,>=1.21.1 in c:\users\nelson\appdata\local\programs\python\python313\lib\site-packages (from requests->huggingface-hub>=0.21.0->accelerate) (2.3.0)
|
| 24 |
+
Requirement already satisfied: certifi>=2017.4.17 in c:\users\nelson\appdata\local\programs\python\python313\lib\site-packages (from requests->huggingface-hub>=0.21.0->accelerate) (2025.1.31)
|
app.py
CHANGED
|
@@ -1,80 +1,155 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
import
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 📌 INSTALAR DEPENDENCIAS (si no están en tu entorno)
|
| 2 |
+
# pip install transformers torch gradio whisper gtts accelerate
|
| 3 |
+
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import torch
|
| 6 |
+
import random
|
| 7 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 8 |
+
import whisper
|
| 9 |
+
from gtts import gTTS
|
| 10 |
+
|
| 11 |
+
<<<<<<< HEAD
|
| 12 |
+
# 📌 Verificar si se tiene GPU disponible
|
| 13 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 14 |
+
|
| 15 |
+
# 📌 MODELO ESPAÑOL PÚBLICO (con código personalizado)
|
| 16 |
+
modelo_id = "deepseek-ai/DeepSeek-R1"
|
| 17 |
+
|
| 18 |
+
# Intentar importar accelerate sin fallar
|
| 19 |
+
try:
|
| 20 |
+
import accelerate
|
| 21 |
+
accelerate_installed = True
|
| 22 |
+
except ImportError:
|
| 23 |
+
accelerate_installed = False
|
| 24 |
+
|
| 25 |
+
# Cargar el modelo de manera segura
|
| 26 |
+
modelo = AutoModelForCausalLM.from_pretrained(
|
| 27 |
+
modelo_id,
|
| 28 |
+
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
|
| 29 |
+
trust_remote_code=True
|
| 30 |
+
).to(device)
|
| 31 |
+
|
| 32 |
+
# 📌 LISTA NEGRA DE INSULTOS
|
| 33 |
+
palabras_prohibidas = [
|
| 34 |
+
"Abollado", "Arrecho(a)", "Azote de barrio", "Bolsa", "Cagao E zamuro",
|
| 35 |
+
"Ladilla", "Mojón", "Ñero", "Piche", "Rata(ón)", "Vuelto mierda"
|
| 36 |
+
]
|
| 37 |
+
|
| 38 |
+
# 📌 DICCIONARIO VENEZOLANO
|
| 39 |
+
diccionario_venezolano = {
|
| 40 |
+
"dinero": "palo",
|
| 41 |
+
"amigo": "pana",
|
| 42 |
+
"genial": "chévere",
|
| 43 |
+
"problema": "culebra",
|
| 44 |
+
"fiesta": "bonche",
|
| 45 |
+
"hola": "¡Epa mi pana!",
|
| 46 |
+
"adiós": "¡Váyalo, chamo!",
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
=======
|
| 50 |
+
# 📌 CARGAR MODELO (requiere autenticación si es privado)
|
| 51 |
+
modelo_id = "deepseek-ai/DeepSeek-R1"
|
| 52 |
+
tokenizer = AutoTokenizer.from_pretrained(modelo_id, trust_remote_code=True) # 🌟 Clave para modelos con código personalizado
|
| 53 |
+
modelo = AutoModelForCausalLM.from_pretrained(
|
| 54 |
+
modelo_id,
|
| 55 |
+
device_map="auto",
|
| 56 |
+
torch_dtype=torch.float16,
|
| 57 |
+
trust_remote_code=True # 🌟 Necesario para DeepSeek-R1
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
# 📌 LISTA NEGRA DE INSULTOS (previamente generada)
|
| 61 |
+
palabras_prohibidas = [
|
| 62 |
+
"Abollado", "Arrecho(a)", "Azote de barrio", "Bolsa", "Cagao E zamuro", "Caimanera",
|
| 63 |
+
"Cariaquito morao", "Chimbo, todo", "Chimbo", "Chola", "Conejo", "Coño'e madre",
|
| 64 |
+
"Culebra", "Flux", "Friqueado", "Furruqueado", "Guaya", "Güevo", "Hediondo", "Ladilla",
|
| 65 |
+
"Landro", "Mamagüevo", "Mandinga", "Mapanare", "Marico triste", "Metra",
|
| 66 |
+
"Mojón", "Muérgano", "Ñero", "Oracio", "Pasoneado(a)", "Pava", "Peaje", "Pecueca",
|
| 67 |
+
"Piche", "Rata(ón)", "Raya'o", "Rolo", "Salado", "Tachón", "Taguara", "Vergajo",
|
| 68 |
+
"Violín", "Vuelto mierda"
|
| 69 |
+
]
|
| 70 |
+
|
| 71 |
+
# 📌 CARGAR DICCIONARIO VENEZOLANO COMPLETO
|
| 72 |
+
def cargar_diccionario(ruta_archivo):
|
| 73 |
+
diccionario = {
|
| 74 |
+
"saludo": [],
|
| 75 |
+
"despedida": [],
|
| 76 |
+
"afirmacion": [],
|
| 77 |
+
"negacion": [],
|
| 78 |
+
"colloquial": {} # Palabras venezolanas y sus equivalentes formales
|
| 79 |
+
}
|
| 80 |
+
with open(ruta_archivo, "r", encoding="utf-8") as f:
|
| 81 |
+
for linea in f:
|
| 82 |
+
linea = linea.strip()
|
| 83 |
+
if linea and not linea.startswith("#"):
|
| 84 |
+
partes = linea.split(".-", 1)
|
| 85 |
+
if len(partes) >= 2:
|
| 86 |
+
palabra = partes[0].strip()
|
| 87 |
+
definicion = partes[1].strip().lower()
|
| 88 |
+
|
| 89 |
+
# Clasificar palabras según contexto
|
| 90 |
+
if "saludo" in definicion:
|
| 91 |
+
diccionario["saludo"].append(palabra)
|
| 92 |
+
elif "despedida" in definicion:
|
| 93 |
+
diccionario["despedida"].append(palabra)
|
| 94 |
+
elif "afirmación" in definicion or "positivo" in definicion:
|
| 95 |
+
diccionario["afirmacion"].append(palabra)
|
| 96 |
+
elif "negación" in definicion or "negativo" in definicion:
|
| 97 |
+
diccionario["negacion"].append(palabra)
|
| 98 |
+
else:
|
| 99 |
+
# Agregar palabras coloquiales con su significado
|
| 100 |
+
if palabra not in palabras_prohibidas:
|
| 101 |
+
diccionario["colloquial"][palabra] = definicion
|
| 102 |
+
return diccionario
|
| 103 |
+
|
| 104 |
+
diccionario_venezolano = cargar_diccionario("Diccionario_Venezolano.txt")
|
| 105 |
+
|
| 106 |
+
>>>>>>> 445cf16 (Mejoras: optimización, memoria, voz y expresiones venezolanas)
|
| 107 |
+
# 📌 Función para adaptar respuestas
|
| 108 |
+
def adaptar_respuesta(respuesta):
|
| 109 |
+
# Filtrar insultos
|
| 110 |
+
for palabra in palabras_prohibidas:
|
| 111 |
+
respuesta = respuesta.replace(palabra, "****")
|
| 112 |
+
|
| 113 |
+
# Reemplazar términos formales por coloquiales
|
| 114 |
+
for formal, venezolano in diccionario_venezolano.items():
|
| 115 |
+
respuesta = respuesta.replace(formal, venezolano)
|
| 116 |
+
|
| 117 |
+
return respuesta
|
| 118 |
+
|
| 119 |
+
# 📌 Función principal del asistente
|
| 120 |
+
def chamo_asistente(pregunta):
|
| 121 |
+
<<<<<<< HEAD
|
| 122 |
+
inputs = tokenizer(pregunta, return_tensors="pt").to(device) # Enviar a GPU si está disponible
|
| 123 |
+
=======
|
| 124 |
+
inputs = tokenizer(pregunta, return_tensors="pt")
|
| 125 |
+
>>>>>>> 445cf16 (Mejoras: optimización, memoria, voz y expresiones venezolanas)
|
| 126 |
+
output = modelo.generate(**inputs, max_new_tokens=150)
|
| 127 |
+
respuesta = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 128 |
+
return adaptar_respuesta(respuesta)
|
| 129 |
+
|
| 130 |
+
# 📌 Procesar audio
|
| 131 |
+
def procesar_audio(archivo):
|
| 132 |
+
<<<<<<< HEAD
|
| 133 |
+
modelo_whisper = whisper.load_model("small") # Cargar modelo una sola vez
|
| 134 |
+
texto = modelo_whisper.transcribe(archivo)["text"]
|
| 135 |
+
respuesta = chamo_asistente(texto)
|
| 136 |
+
|
| 137 |
+
# Convertir texto a audio
|
| 138 |
+
=======
|
| 139 |
+
texto = whisper.load_model("small").transcribe(archivo)["text"]
|
| 140 |
+
respuesta = chamo_asistente(texto)
|
| 141 |
+
>>>>>>> 445cf16 (Mejoras: optimización, memoria, voz y expresiones venezolanas)
|
| 142 |
+
tts = gTTS(respuesta, lang="es")
|
| 143 |
+
tts.save("respuesta.mp3")
|
| 144 |
+
|
| 145 |
+
return respuesta, "respuesta.mp3"
|
| 146 |
+
|
| 147 |
+
# 📌 Interfaz Gradio
|
| 148 |
+
iface_texto = gr.Interface(fn=chamo_asistente, inputs="text", outputs="text")
|
| 149 |
+
iface_voz = gr.Interface(fn=procesar_audio, inputs="microphone", outputs=["text", "audio"])
|
| 150 |
+
demo = gr.TabbedInterface([iface_texto, iface_voz], ["Texto", "Voz"])
|
| 151 |
+
<<<<<<< HEAD
|
| 152 |
+
demo.launch()
|
| 153 |
+
=======
|
| 154 |
+
demo.launch()
|
| 155 |
+
>>>>>>> 445cf16 (Mejoras: optimización, memoria, voz y expresiones venezolanas)
|
requirements.txt
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
-
transformers
|
| 2 |
-
torch
|
| 3 |
-
gradio
|
| 4 |
-
pydub
|
| 5 |
-
openai-whisper
|
| 6 |
-
gtts
|
| 7 |
-
soundfile
|
| 8 |
-
llama-cpp-python
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
torch
|
| 3 |
+
gradio
|
| 4 |
+
pydub
|
| 5 |
+
openai-whisper
|
| 6 |
+
gtts
|
| 7 |
+
soundfile
|
| 8 |
+
llama-cpp-python # Necesario para modelos GGUF
|