Spaces:
Sleeping
Sleeping
Tarea acabada
Browse files- .gitignore +36 -0
- app_tran_empresa.py +70 -0
- difuser_autismo.py +109 -0
- difuser_empresa.py +141 -0
- inference_disc_visual.py +65 -0
- inference_incidencia.py +94 -0
- requirements.txt +10 -0
- tran_visual.py +44 -0
.gitignore
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# --- Bytecode de Python (Archivos temporales) ---
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
|
| 6 |
+
# --- Entornos Virtuales (NUNCA se suben) ---
|
| 7 |
+
# Nombres comunes para la carpeta del entorno
|
| 8 |
+
venv/
|
| 9 |
+
.venv/
|
| 10 |
+
env/
|
| 11 |
+
ENV/
|
| 12 |
+
.env_folder/
|
| 13 |
+
|
| 14 |
+
# --- Variables de Entorno y Secretos (SEGURIDAD CRÍTICA) ---
|
| 15 |
+
# Esto evita que tu Token de Hugging Face se suba a Internet
|
| 16 |
+
.env
|
| 17 |
+
.env.*
|
| 18 |
+
.secrets
|
| 19 |
+
|
| 20 |
+
# --- Archivos de IDE (Configuraciones de tu editor) ---
|
| 21 |
+
.vscode/
|
| 22 |
+
.idea/
|
| 23 |
+
*.swp
|
| 24 |
+
|
| 25 |
+
# --- Archivos específicos de Gradio ---
|
| 26 |
+
# Gradio crea esta carpeta si le das al botón "Flag" en la interfaz
|
| 27 |
+
flagged/
|
| 28 |
+
|
| 29 |
+
# --- Archivos del Sistema Operativo ---
|
| 30 |
+
.DS_Store
|
| 31 |
+
Thumbs.db
|
| 32 |
+
|
| 33 |
+
# --- Distribución / Instaladores (si creas paquetes) ---
|
| 34 |
+
dist/
|
| 35 |
+
build/
|
| 36 |
+
*.egg-info/
|
app_tran_empresa.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
#Configuración del modelo
|
| 5 |
+
modelo_sentimiento = "pysentimiento/robertuito-sentiment-analysis"
|
| 6 |
+
|
| 7 |
+
print("Cargando modelo de sentimientos... (Esto es rápido)")
|
| 8 |
+
|
| 9 |
+
try:
|
| 10 |
+
clasificador = pipeline("text-classification", model=modelo_sentimiento)
|
| 11 |
+
print("✅ Modelo cargado y listo.")
|
| 12 |
+
except Exception as e:
|
| 13 |
+
print(f"❌ Error al cargar: {e}")
|
| 14 |
+
clasificador = None
|
| 15 |
+
|
| 16 |
+
def analizar_texto(texto):
|
| 17 |
+
if clasificador is None:
|
| 18 |
+
return "Error: El modelo no está cargado."
|
| 19 |
+
|
| 20 |
+
if not texto:
|
| 21 |
+
return "Escribe algo primero."
|
| 22 |
+
|
| 23 |
+
try:
|
| 24 |
+
resultados = clasificador(texto)
|
| 25 |
+
|
| 26 |
+
# Formateamos bonito el resultado
|
| 27 |
+
mejor_resultado = resultados[0]
|
| 28 |
+
etiqueta = mejor_resultado['label'] # POS, NEG, NEU
|
| 29 |
+
confianza = round(mejor_resultado['score'] * 100, 2)
|
| 30 |
+
|
| 31 |
+
# Traducción de etiquetas para que se entienda mejor
|
| 32 |
+
traduccion = {
|
| 33 |
+
'POS': '😃 Positivo',
|
| 34 |
+
'NEG': '😡 Negativo',
|
| 35 |
+
'NEU': '😐 Neutro'
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
resultado_texto = traduccion.get(etiqueta, etiqueta)
|
| 39 |
+
return f"{resultado_texto} (Confianza: {confianza}%)"
|
| 40 |
+
|
| 41 |
+
except Exception as e:
|
| 42 |
+
return f"Error al analizar: {str(e)}"
|
| 43 |
+
|
| 44 |
+
# --- INTERFAZ GRÁFICA ---
|
| 45 |
+
with gr.Blocks(theme=gr.themes.Base()) as demo:
|
| 46 |
+
gr.Markdown("# 🌡️ Termómetro de Opinión")
|
| 47 |
+
gr.Markdown("Escribe una frase, reseña o tweet y la IA detectará el tono emocional.")
|
| 48 |
+
|
| 49 |
+
with gr.Row():
|
| 50 |
+
input_text = gr.Textbox(
|
| 51 |
+
label="Tu texto",
|
| 52 |
+
placeholder="Ej: ¡Este producto es una maravilla, me encanta!",
|
| 53 |
+
lines=3
|
| 54 |
+
)
|
| 55 |
+
output_text = gr.Label(label="Sentimiento Detectado")
|
| 56 |
+
|
| 57 |
+
btn = gr.Button("Analizar Sentimiento", variant="primary")
|
| 58 |
+
btn.click(fn=analizar_texto, inputs=input_text, outputs=output_text)
|
| 59 |
+
|
| 60 |
+
gr.Examples(
|
| 61 |
+
examples=[
|
| 62 |
+
["El servicio fue pésimo y la comida estaba fría."],
|
| 63 |
+
["Es una película entretenida, aunque el final es un poco flojo."],
|
| 64 |
+
["¡Estoy superfeliz con mi nueva compra!"]
|
| 65 |
+
],
|
| 66 |
+
inputs=input_text
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
if __name__ == "__main__":
|
| 70 |
+
demo.launch()
|
difuser_autismo.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from diffusers import DiffusionPipeline
|
| 4 |
+
|
| 5 |
+
# --- 1. CONFIGURACIÓN DEL MODELO (LCM para velocidad) ---
|
| 6 |
+
print("🚀 Cargando modelo de difusión rápida (LCM)...")
|
| 7 |
+
model_id = "SimianLuo/LCM_Dreamshaper_v7"
|
| 8 |
+
|
| 9 |
+
try:
|
| 10 |
+
pipe = DiffusionPipeline.from_pretrained(model_id)
|
| 11 |
+
|
| 12 |
+
pipe.to("cpu")
|
| 13 |
+
|
| 14 |
+
pipe.safety_checker = None
|
| 15 |
+
|
| 16 |
+
print("✅ Modelo LCM cargado. Listo para generar imágenes rápidas.")
|
| 17 |
+
except Exception as e:
|
| 18 |
+
print(f"❌ Error al cargar modelo: {e}")
|
| 19 |
+
pipe = None
|
| 20 |
+
|
| 21 |
+
# --- 2. LÓGICA DE GENERACIÓN ---
|
| 22 |
+
def generar_pictograma(texto_usuario, estilo):
|
| 23 |
+
if pipe is None:
|
| 24 |
+
return None
|
| 25 |
+
|
| 26 |
+
prompt_base = f"{texto_usuario}, {estilo}, white background, centered, vector illustration, flat design, high contrast, minimal, simple shapes, no shadows"
|
| 27 |
+
prompt_negativo = "complex, realistic, photo, details, text, watermark, blurry, distorted, 3d render"
|
| 28 |
+
|
| 29 |
+
print(f"🎨 Generando: {texto_usuario}...")
|
| 30 |
+
|
| 31 |
+
try:
|
| 32 |
+
|
| 33 |
+
imagen = pipe(
|
| 34 |
+
prompt=prompt_base,
|
| 35 |
+
negative_prompt=prompt_negativo,
|
| 36 |
+
num_inference_steps=4,
|
| 37 |
+
guidance_scale=8.0,
|
| 38 |
+
width=512,
|
| 39 |
+
height=512
|
| 40 |
+
).images[0]
|
| 41 |
+
return imagen
|
| 42 |
+
except Exception as e:
|
| 43 |
+
print(f"Error generando: {e}")
|
| 44 |
+
return None
|
| 45 |
+
|
| 46 |
+
# --- 3. INTERFAZ GRÁFICA ---
|
| 47 |
+
css_accesible = """
|
| 48 |
+
.gradio-container {background-color: #f0f8ff !important;}
|
| 49 |
+
h1 {font-family: 'Arial', sans-serif; color: #2c3e50;}
|
| 50 |
+
.boton-grande {font-size: 20px !important; height: 60px !important;}
|
| 51 |
+
.texto-grande textarea {font-size: 24px !important; line-height: 1.5 !important;}
|
| 52 |
+
.info-box {background-color: #e8f4f8; padding: 15px; border-radius: 10px; border: 2px solid #3498db;}
|
| 53 |
+
"""
|
| 54 |
+
|
| 55 |
+
with gr.Blocks(theme=gr.themes.Soft(), css=css_accesible) as demo:
|
| 56 |
+
|
| 57 |
+
with gr.Row():
|
| 58 |
+
gr.Markdown("# 🗣️ PictoGen: Comunicación Visual")
|
| 59 |
+
|
| 60 |
+
gr.Markdown(
|
| 61 |
+
"""
|
| 62 |
+
<div class='info-box'>
|
| 63 |
+
<b>Herramienta de Accesibilidad:</b> Escribe lo que necesitas comunicar y la IA creará una tarjeta visual simple al instante.
|
| 64 |
+
Ideal para crear tableros de comunicación, agendas visuales o expresar necesidades.
|
| 65 |
+
</div>
|
| 66 |
+
"""
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
with gr.Row():
|
| 70 |
+
# Columna Izquierda: Controles
|
| 71 |
+
with gr.Column(scale=1):
|
| 72 |
+
input_text = gr.Textbox(
|
| 73 |
+
label="¿Qué imagen necesitas?",
|
| 74 |
+
placeholder="Ej: Comer manzana, Ir al baño, Jugar pelota...",
|
| 75 |
+
elem_classes="texto-grande"
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
radio_style = gr.Radio(
|
| 79 |
+
["icon style, thick lines", "cartoon style, colorful", "line art, black and white"],
|
| 80 |
+
label="Estilo Visual",
|
| 81 |
+
value="icon style, thick lines",
|
| 82 |
+
info="Selecciona el tipo de dibujo que mejor se entienda."
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
btn = gr.Button("🎨 Crear Pictograma", variant="primary", elem_classes="boton-grande")
|
| 86 |
+
|
| 87 |
+
# Columna Derecha: Resultado
|
| 88 |
+
with gr.Column(scale=1):
|
| 89 |
+
output_image = gr.Image(
|
| 90 |
+
label="Tu Pictograma",
|
| 91 |
+
type="pil",
|
| 92 |
+
interactive=False,
|
| 93 |
+
height=512
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
btn.click(fn=generar_pictograma, inputs=[input_text, radio_style], outputs=output_image)
|
| 98 |
+
|
| 99 |
+
gr.Examples(
|
| 100 |
+
examples=[
|
| 101 |
+
["Un vaso de agua", "icon style, thick lines"],
|
| 102 |
+
["Sentirse feliz", "cartoon style, colorful"],
|
| 103 |
+
["Autobús escolar", "icon style, thick lines"]
|
| 104 |
+
],
|
| 105 |
+
inputs=[input_text, radio_style]
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
if __name__ == "__main__":
|
| 109 |
+
demo.launch()
|
difuser_empresa.py
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from diffusers import DiffusionPipeline
|
| 4 |
+
import gc
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
print("💼 Iniciando BizSketch. Cargando motor gráfico ligero...")
|
| 8 |
+
model_id = "SimianLuo/LCM_Dreamshaper_v7"
|
| 9 |
+
|
| 10 |
+
try:
|
| 11 |
+
|
| 12 |
+
pipe = DiffusionPipeline.from_pretrained(model_id)
|
| 13 |
+
pipe.to("cpu", torch.float32)
|
| 14 |
+
pipe.safety_checker = None
|
| 15 |
+
print("✅ Motor listo. Modo de bajo consumo activado.")
|
| 16 |
+
|
| 17 |
+
except Exception as e:
|
| 18 |
+
print(f"❌ Error crítico al cargar el modelo: {e}\nAsegúrate de tener instalado: pip install diffusers transformers accelerate torch")
|
| 19 |
+
pipe = None
|
| 20 |
+
|
| 21 |
+
def limpiar_memoria():
|
| 22 |
+
gc.collect()
|
| 23 |
+
|
| 24 |
+
# --- 2. LÓGICA DE GENERACIÓN ---
|
| 25 |
+
def generar_concepto(concepto_negocio, estilo_visual):
|
| 26 |
+
if pipe is None:
|
| 27 |
+
raise gr.Error("El modelo no se pudo cargar. Revisa la terminal.")
|
| 28 |
+
|
| 29 |
+
if not concepto_negocio:
|
| 30 |
+
raise gr.Error("Por favor, escribe un concepto primero.")
|
| 31 |
+
|
| 32 |
+
prompt_base = f"{concepto_negocio}, {estilo_visual}, professional corporate illustration, clean background, minimal design, high quality, presentation ready"
|
| 33 |
+
|
| 34 |
+
prompt_negativo = "blurry, messy, amateur, ugly, deformed hands, text, watermark, signature, low resolution, photograph"
|
| 35 |
+
|
| 36 |
+
print(f"📊 Generando concepto: {concepto_negocio}...")
|
| 37 |
+
|
| 38 |
+
try:
|
| 39 |
+
|
| 40 |
+
imagen = pipe(
|
| 41 |
+
prompt=prompt_base,
|
| 42 |
+
negative_prompt=prompt_negativo,
|
| 43 |
+
num_inference_steps=5,
|
| 44 |
+
guidance_scale=7.5,
|
| 45 |
+
width=512,
|
| 46 |
+
height=512
|
| 47 |
+
).images[0]
|
| 48 |
+
|
| 49 |
+
limpiar_memoria()
|
| 50 |
+
return imagen
|
| 51 |
+
except Exception as e:
|
| 52 |
+
limpiar_memoria()
|
| 53 |
+
raise gr.Error(f"Error durante la generación: {e}")
|
| 54 |
+
|
| 55 |
+
# --- 3. DISEÑO DE LA INTERFAZ (Layout Profesional) ---
|
| 56 |
+
|
| 57 |
+
tema_negocio = gr.themes.Monochrome(
|
| 58 |
+
primary_hue="slate",
|
| 59 |
+
radius_size=gr.themes.sizes.radius_sm,
|
| 60 |
+
font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"],
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
css_corporativo = """
|
| 64 |
+
.container {max-width: 900px; margin: auto; padding-top: 20px;}
|
| 65 |
+
#header-box {text-align: center; margin-bottom: 30px; border-bottom: 2px solid #e5e7eb; padding-bottom: 20px;}
|
| 66 |
+
h1 {font-weight: 700; color: #1a202c;}
|
| 67 |
+
.subtitle {color: #4b5563; font-size: 1.1rem;}
|
| 68 |
+
#generate-btn {font-weight: bold; font-size: 1.1rem;}
|
| 69 |
+
"""
|
| 70 |
+
|
| 71 |
+
with gr.Blocks(theme=tema_negocio, css=css_corporativo, title="BizSketch App") as demo:
|
| 72 |
+
|
| 73 |
+
with gr.Column(elem_classes="container"):
|
| 74 |
+
# Header
|
| 75 |
+
with gr.Column(elem_id="header-box"):
|
| 76 |
+
gr.Markdown("# 💼 BizSketch: Visualizador de Conceptos")
|
| 77 |
+
gr.Markdown("<span class='subtitle'>Genera ilustraciones rápidas para tus presentaciones y brainstorms.</span>")
|
| 78 |
+
|
| 79 |
+
with gr.Row(equal_height=False):
|
| 80 |
+
# --- Columna Izquierda: Inputs ---
|
| 81 |
+
with gr.Column(scale=2):
|
| 82 |
+
with gr.Group():
|
| 83 |
+
gr.Markdown("### 1. Define tu idea")
|
| 84 |
+
input_concept = gr.Textbox(
|
| 85 |
+
label="Concepto de Negocio",
|
| 86 |
+
placeholder="Ej: Crecimiento sostenible en mercados emergentes...",
|
| 87 |
+
lines=3,
|
| 88 |
+
show_label=False
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
with gr.Group():
|
| 92 |
+
gr.Markdown("### 2. Elige el estilo visual")
|
| 93 |
+
radio_style = gr.Radio(
|
| 94 |
+
choices=[
|
| 95 |
+
"clean line art sketch, blueprint style",
|
| 96 |
+
"flat vector illustration, modern tech style",
|
| 97 |
+
"isometric 3D render, soft colors",
|
| 98 |
+
"watercolor sketch, business storyboard style"
|
| 99 |
+
],
|
| 100 |
+
value="flat vector illustration, modern tech style",
|
| 101 |
+
label="Estilo",
|
| 102 |
+
show_label=False,
|
| 103 |
+
interactive=True
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
btn = gr.Button("🚀 Generar Visualización", variant="primary", elem_id="generate-btn")
|
| 107 |
+
|
| 108 |
+
with gr.Accordion("💡 Consejos para mejores resultados", open=False):
|
| 109 |
+
gr.Markdown("- Mantén los conceptos simples (ej: 'reunión de equipo exitosa' en vez de una descripción de 3 párrafos).")
|
| 110 |
+
gr.Markdown("- El estilo 'Flat vector' suele ser el más limpio para presentaciones.")
|
| 111 |
+
|
| 112 |
+
# --- Columna Derecha: Output ---
|
| 113 |
+
with gr.Column(scale=3):
|
| 114 |
+
gr.Markdown("### 🎯 Resultado")
|
| 115 |
+
output_image = gr.Image(
|
| 116 |
+
label="Visualización Generada",
|
| 117 |
+
type="pil",
|
| 118 |
+
interactive=False,
|
| 119 |
+
#show_download_button=True,
|
| 120 |
+
height=400
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
# --- Footer / Ejemplos ---
|
| 124 |
+
gr.Markdown("---")
|
| 125 |
+
gr.Markdown("### ⚡ Ejemplos Rápidos")
|
| 126 |
+
gr.Examples(
|
| 127 |
+
examples=[
|
| 128 |
+
["Equipo diverso colaborando alrededor de una mesa con gráficos", "flat vector illustration, modern tech style"],
|
| 129 |
+
["Innovación tecnológica y medio ambiente, bombilla con hoja", "clean line art sketch, blueprint style"],
|
| 130 |
+
["Logística global, red de conexiones alrededor del mundo", "isometric 3D render, soft colors"]
|
| 131 |
+
],
|
| 132 |
+
inputs=[input_concept, radio_style],
|
| 133 |
+
outputs=output_image,
|
| 134 |
+
fn=generar_concepto,
|
| 135 |
+
cache_examples=False
|
| 136 |
+
)
|
| 137 |
+
|
| 138 |
+
btn.click(fn=generar_concepto, inputs=[input_concept, radio_style], outputs=output_image)
|
| 139 |
+
|
| 140 |
+
if __name__ == "__main__":
|
| 141 |
+
demo.queue().launch()
|
inference_disc_visual.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import os
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
|
| 6 |
+
# --- CONFIGURACIÓN ---
|
| 7 |
+
load_dotenv()
|
| 8 |
+
MI_TOKEN = os.getenv("HF_TOKEN")
|
| 9 |
+
|
| 10 |
+
MODELO = "Helsinki-NLP/opus-mt-es-en"
|
| 11 |
+
|
| 12 |
+
API_URL = f"https://router.huggingface.co/hf-inference/models/{MODELO}"
|
| 13 |
+
HEADERS = {"Authorization": f"Bearer {MI_TOKEN}"}
|
| 14 |
+
|
| 15 |
+
def traducir_texto(texto):
|
| 16 |
+
if not texto:
|
| 17 |
+
return "Escribe algo..."
|
| 18 |
+
|
| 19 |
+
print(f"📡 Enviando a traducir ({MODELO})...")
|
| 20 |
+
|
| 21 |
+
payload = {"inputs": texto}
|
| 22 |
+
|
| 23 |
+
try:
|
| 24 |
+
response = requests.post(API_URL, headers=HEADERS, json=payload)
|
| 25 |
+
|
| 26 |
+
# Leemos el resultado crudo
|
| 27 |
+
datos = response.json()
|
| 28 |
+
|
| 29 |
+
if response.status_code == 200:
|
| 30 |
+
if isinstance(datos, list) and len(datos) > 0:
|
| 31 |
+
return datos[0].get('translation_text', 'No se pudo traducir')
|
| 32 |
+
elif isinstance(datos, dict):
|
| 33 |
+
return datos.get('translation_text', str(datos))
|
| 34 |
+
else:
|
| 35 |
+
return str(datos)
|
| 36 |
+
|
| 37 |
+
elif response.status_code == 503:
|
| 38 |
+
return "⏳ El modelo está cargando (Cold Boot). Espera 20 segundos y reintenta."
|
| 39 |
+
|
| 40 |
+
else:
|
| 41 |
+
return f"❌ Error {response.status_code}: {response.text}"
|
| 42 |
+
|
| 43 |
+
except Exception as e:
|
| 44 |
+
return f"Error de conexión: {e}"
|
| 45 |
+
|
| 46 |
+
# Interfaz
|
| 47 |
+
ui = gr.Interface(
|
| 48 |
+
fn=traducir_texto,
|
| 49 |
+
inputs=gr.Textbox(
|
| 50 |
+
label="Texto en Español",
|
| 51 |
+
placeholder="Escribe aquí (ej: La accesibilidad es vital para la empresa)",
|
| 52 |
+
lines=3
|
| 53 |
+
),
|
| 54 |
+
outputs=gr.Textbox(label="Traducción al Inglés (Modelo Helsinki-NLP)"),
|
| 55 |
+
title="🌍 Traductor Empresarial",
|
| 56 |
+
description="Herramienta de eliminación de barreras idiomáticas usando IA.",
|
| 57 |
+
examples=[
|
| 58 |
+
["La inteligencia artificial transforma los negocios."],
|
| 59 |
+
["Es necesario firmar el contrato antes del lunes."]
|
| 60 |
+
],
|
| 61 |
+
flagging_mode="never"
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
if __name__ == "__main__":
|
| 65 |
+
ui.launch()
|
inference_incidencia.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import os
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
|
| 6 |
+
# --- CONFIGURACIÓN ---
|
| 7 |
+
load_dotenv()
|
| 8 |
+
MI_TOKEN = os.getenv("HF_TOKEN")
|
| 9 |
+
|
| 10 |
+
MODELO = "facebook/bart-large-mnli"
|
| 11 |
+
|
| 12 |
+
API_URL = f"https://router.huggingface.co/hf-inference/models/{MODELO}"
|
| 13 |
+
HEADERS = {"Authorization": f"Bearer {MI_TOKEN}"}
|
| 14 |
+
|
| 15 |
+
def clasificar_incidencia(mensaje):
|
| 16 |
+
if not mensaje:
|
| 17 |
+
return None
|
| 18 |
+
|
| 19 |
+
print(f"📡 Enviando incidencia: '{mensaje}'...")
|
| 20 |
+
|
| 21 |
+
# Departamentos (Etiquetas)
|
| 22 |
+
departamentos = [
|
| 23 |
+
"Soporte IT",
|
| 24 |
+
"Mantenimiento",
|
| 25 |
+
"Secretaría",
|
| 26 |
+
"Seguridad",
|
| 27 |
+
"Cafetería"
|
| 28 |
+
]
|
| 29 |
+
|
| 30 |
+
# Configuración para clasificación
|
| 31 |
+
payload = {
|
| 32 |
+
"inputs": mensaje,
|
| 33 |
+
"parameters": {
|
| 34 |
+
"candidate_labels": departamentos,
|
| 35 |
+
"multi_label": False
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
try:
|
| 40 |
+
response = requests.post(API_URL, headers=HEADERS, json=payload)
|
| 41 |
+
datos = response.json()
|
| 42 |
+
|
| 43 |
+
print(f"📦 DATOS RECIBIDOS: {datos}")
|
| 44 |
+
|
| 45 |
+
if response.status_code == 200:
|
| 46 |
+
|
| 47 |
+
resultados_gradio = {}
|
| 48 |
+
|
| 49 |
+
if isinstance(datos, list):
|
| 50 |
+
for item in datos:
|
| 51 |
+
etiqueta = item.get('label')
|
| 52 |
+
puntuacion = item.get('score')
|
| 53 |
+
|
| 54 |
+
if etiqueta and puntuacion is not None:
|
| 55 |
+
resultados_gradio[etiqueta] = puntuacion
|
| 56 |
+
|
| 57 |
+
return resultados_gradio
|
| 58 |
+
|
| 59 |
+
elif isinstance(datos, dict) and 'labels' in datos:
|
| 60 |
+
return {l: s for l, s in zip(datos['labels'], datos['scores'])}
|
| 61 |
+
|
| 62 |
+
else:
|
| 63 |
+
return {"Error: Formato desconocido": 0.0}
|
| 64 |
+
|
| 65 |
+
elif response.status_code == 503:
|
| 66 |
+
return {"⏳ Cargando modelo... (Prueba en 10s)": 0.0}
|
| 67 |
+
|
| 68 |
+
else:
|
| 69 |
+
return {f"Error {response.status_code}": 0.0}
|
| 70 |
+
|
| 71 |
+
except Exception as e:
|
| 72 |
+
return {f"Error técnico: {e}": 0.0}
|
| 73 |
+
|
| 74 |
+
# Interfaz
|
| 75 |
+
ui = gr.Interface(
|
| 76 |
+
fn=clasificar_incidencia,
|
| 77 |
+
inputs=gr.Textbox(
|
| 78 |
+
label="📝 Incidencia",
|
| 79 |
+
placeholder="Ej: Se ha roto la silla del aula 4...",
|
| 80 |
+
lines=2
|
| 81 |
+
),
|
| 82 |
+
outputs=gr.Label(num_top_classes=5, label="Clasificación IA"),
|
| 83 |
+
title="🏢 Smart Campus: Router IA",
|
| 84 |
+
description="Sistema de triaje inteligente para incidencias universitarias.",
|
| 85 |
+
examples=[
|
| 86 |
+
["El proyector no enciende y tengo clase ahora."],
|
| 87 |
+
["He perdido mi cartera en el pasillo."],
|
| 88 |
+
["Necesito un certificado de notas para la beca."]
|
| 89 |
+
],
|
| 90 |
+
flagging_mode="never"
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
if __name__ == "__main__":
|
| 94 |
+
ui.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
gradio
|
| 3 |
+
requests
|
| 4 |
+
pillow
|
| 5 |
+
python-dotenv
|
| 6 |
+
huggingface_hub
|
| 7 |
+
transformers
|
| 8 |
+
torch
|
| 9 |
+
torchaudio
|
| 10 |
+
numpy
|
tran_visual.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
# --- CARGA DE LOS MODELOS ---
|
| 4 |
+
# MODELO A: (Imagen -> Texto Inglés) BLIP Genera la descripción en inglés.
|
| 5 |
+
captioner = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
| 6 |
+
|
| 7 |
+
# MODELO B:(Texto Inglés -> Texto Español) Traductor.
|
| 8 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-es")
|
| 9 |
+
|
| 10 |
+
# MODELO C: Voz (Texto Español -> Audio) Crea audio en español.
|
| 11 |
+
tts = pipeline("text-to-speech", model="facebook/mms-tts-spa")
|
| 12 |
+
|
| 13 |
+
# --- LÓGICA ---
|
| 14 |
+
#Retornona texto y audio en español
|
| 15 |
+
def procesar_imagen(imagen):
|
| 16 |
+
if imagen is None:
|
| 17 |
+
return "No hay imagen", None
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
texto_ingles = captioner(imagen)[0]['generated_text']
|
| 21 |
+
|
| 22 |
+
texto_espanol = translator(texto_ingles)[0]['translation_text']
|
| 23 |
+
|
| 24 |
+
salida_audio = tts(texto_espanol)
|
| 25 |
+
|
| 26 |
+
audio_data = salida_audio['audio'][0]
|
| 27 |
+
sampling_rate = salida_audio['sampling_rate']
|
| 28 |
+
|
| 29 |
+
return texto_espanol, (sampling_rate, audio_data)
|
| 30 |
+
|
| 31 |
+
# ---INTERFAZ ---
|
| 32 |
+
interfaz = gr.Interface(
|
| 33 |
+
fn=procesar_imagen,
|
| 34 |
+
inputs=gr.Image(label="Sube una imagen", type="pil"),
|
| 35 |
+
outputs=[
|
| 36 |
+
gr.Textbox(label="Descripción en Español"),
|
| 37 |
+
gr.Audio(label="Audio")
|
| 38 |
+
],
|
| 39 |
+
title="Asistente para Invidentes (Español)",
|
| 40 |
+
description="Sube una imagen y la aplicación te dirá qué contiene.",
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
if __name__ == "__main__":
|
| 44 |
+
interfaz.launch()
|