Spaces:
Sleeping
Sleeping
| 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() | |