Spaces:
Sleeping
Sleeping
File size: 3,160 Bytes
0fd5ce9 ad89307 b638a38 ad89307 12c9371 b638a38 0fd5ce9 ad89307 12c9371 ad89307 12c9371 0fd5ce9 b638a38 12c9371 b638a38 ad89307 b638a38 0fd5ce9 ad89307 12c9371 ad89307 b638a38 ad89307 0fd5ce9 ad89307 0fd5ce9 ad89307 12c9371 ad89307 12c9371 ad89307 0fd5ce9 ad89307 0fd5ce9 | 1 2 3 4 5 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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | import gradio as gr
import json
from transformers import pipeline
# 🧠 Configuración base
SYSTEM_PROMPT = (
"Eres el asistente técnico de Doctor Linux Ltda. "
"Responde en ESPAÑOL, claro, conciso y profesional, "
"con comandos prácticos cuando sea posible. "
"Si algo implica riesgo, adviértelo brevemente."
)
# 🧩 Cargar módulos del manual
try:
with open("modules.json", "r", encoding="utf-8") as f:
MODULES = json.load(f)
except Exception:
MODULES = []
# ⚙️ Modelo ligero compatible con CPU Basic (sin GPU ni API keys)
generator = pipeline("text2text-generation", model="google/flan-t5-small")
def ask_ai(message, history):
ctx = ""
for u, a in history[-3:]:
ctx += f"Usuario: {u}\nAsistente: {a}\n"
prompt = (
f"{SYSTEM_PROMPT}\n\n"
f"Contexto reciente:\n{ctx}\n"
f"Pregunta: {message}\n\n"
f"Respuesta:"
)
out = generator(prompt, max_new_tokens=256)[0]["generated_text"]
return out.strip()
# 🎨 Interfaz Gradio
with gr.Blocks(
theme=gr.themes.Soft(primary_hue="blue", secondary_hue="gray"),
css="""
body {
background-color: #0d1117;
color: #f0f6fc;
font-family: 'Segoe UI', Roboto, sans-serif;
}
.gradio-container {
max-width: 1200px;
margin: auto;
}
h1, h2, h3 {
color: #58a6ff;
}
.footer {
color: #8b949e;
font-size: 13px;
text-align: center;
margin-top: 25px;
}
"""
) as demo:
# 🧠 Encabezado
gr.Markdown(
"""
# 🧠 Manual de Ciberseguridad Operativa – Doctor Linux Ltda.
### *“Seguridad real, ingeniería aplicada.”*
---
**Versión IA Edition 2025 – con asistencia técnica inteligente.**
"""
)
# 💬 Pestaña de chat IA
with gr.Tab("💬 Asistente IA"):
gr.ChatInterface(
fn=ask_ai,
title="Asistente Técnico Doctor Linux IA",
examples=[
["Explícame cómo asegurar SSH en Debian."],
["Muéstrame reglas básicas de firewall Mikrotik."],
["Cómo monitorear jitter en Zabbix con ping ICMP."]
],
)
# 📘 Pestañas para los módulos
for m in MODULES:
with gr.Tab(m["titulo"]):
gr.Markdown(f"### 🎯 Objetivo\n{m['objetivo']}")
gr.Markdown(f"#### 🧩 Contenido\n{m['contenido']}")
if m.get("comandos"):
gr.Textbox(
value=m["comandos"],
label="Comandos (solo lectura)",
lines=8,
interactive=False,
)
if m.get("checklist"):
gr.CheckboxGroup(choices=m["checklist"], label="Checklist técnico")
# 🧾 Pie de página
gr.Markdown(
"<div class='footer'>© 2025 Doctor Linux Ltda. – Departamento de Ingeniería | IA Edition – CPU Basic Compatible</div>"
)
if __name__ == "__main__":
demo.launch()
|