doctorlinux commited on
Commit
ad89307
·
verified ·
1 Parent(s): dc4d683

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +62 -15
  2. requirements.txt +1 -0
app.py CHANGED
@@ -2,21 +2,23 @@ import gradio as gr
2
  import json
3
  from transformers import pipeline
4
 
 
5
  SYSTEM_PROMPT = (
6
  "Eres el asistente técnico de Doctor Linux Ltda. "
7
- "Respondes en ESPAÑOL, claro y profesional, con comandos prácticos cuando aplique. "
 
8
  "Si algo implica riesgo, adviértelo brevemente."
9
  )
10
 
11
- # Carga de módulos (opcional si ya tienes modules.json)
12
  try:
13
  with open("modules.json", "r", encoding="utf-8") as f:
14
  MODULES = json.load(f)
15
  except Exception:
16
  MODULES = []
17
 
18
- # Modelo ligero que funciona en CPU Basic
19
- gen = pipeline("text2text-generation", model="google/flan-t5-small")
20
 
21
  def ask_ai(message, history):
22
  ctx = ""
@@ -28,30 +30,75 @@ def ask_ai(message, history):
28
  f"Pregunta: {message}\n\n"
29
  f"Respuesta:"
30
  )
31
- out = gen(prompt, max_new_tokens=256)[0]["generated_text"]
32
  return out.strip()
33
 
34
- with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="gray"),
35
- css="body{background:#0d1117;color:#f0f6fc}.gradio-container{max-width:1200px;margin:auto}") as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
- gr.Markdown("# 🧠 Manual de Ciberseguridad Operativa – Doctor Linux Ltda.\n"
38
- "### *“Seguridad real, ingeniería aplicada.”* \n"
39
- "**IA Edition – CPU Basic**")
 
 
 
 
 
 
40
 
 
41
  with gr.Tab("💬 Asistente IA"):
42
- gr.ChatInterface(fn=ask_ai, title="Asistente Técnico Doctor Linux IA")
 
 
 
 
 
 
 
 
43
 
44
- # Tabs de módulos (si modules.json existe)
45
  for m in MODULES:
46
  with gr.Tab(m["titulo"]):
47
  gr.Markdown(f"### 🎯 Objetivo\n{m['objetivo']}")
48
  gr.Markdown(f"#### 🧩 Contenido\n{m['contenido']}")
49
  if m.get("comandos"):
50
- gr.Code(value=m["comandos"], language="bash", label="Comandos")
 
 
 
 
 
51
  if m.get("checklist"):
52
- gr.CheckboxGroup(choices=m["checklist"], label="Checklist")
53
 
54
- gr.Markdown("---\n© 2025 Doctor Linux Ltda. – Departamento de Ingeniería")
 
 
 
55
 
56
  if __name__ == "__main__":
57
  demo.launch()
 
2
  import json
3
  from transformers import pipeline
4
 
5
+ # 🧠 Configuración base
6
  SYSTEM_PROMPT = (
7
  "Eres el asistente técnico de Doctor Linux Ltda. "
8
+ "Responde en ESPAÑOL, claro, conciso y profesional, "
9
+ "con comandos prácticos cuando sea posible. "
10
  "Si algo implica riesgo, adviértelo brevemente."
11
  )
12
 
13
+ # 🧩 Cargar módulos del manual
14
  try:
15
  with open("modules.json", "r", encoding="utf-8") as f:
16
  MODULES = json.load(f)
17
  except Exception:
18
  MODULES = []
19
 
20
+ # ⚙️ Modelo ligero compatible con CPU Basic (sin GPU ni API keys)
21
+ generator = pipeline("text2text-generation", model="google/flan-t5-small")
22
 
23
  def ask_ai(message, history):
24
  ctx = ""
 
30
  f"Pregunta: {message}\n\n"
31
  f"Respuesta:"
32
  )
33
+ out = generator(prompt, max_new_tokens=256)[0]["generated_text"]
34
  return out.strip()
35
 
36
+ # 🎨 Interfaz Gradio
37
+ with gr.Blocks(
38
+ theme=gr.themes.Soft(primary_hue="blue", secondary_hue="gray"),
39
+ css="""
40
+ body {
41
+ background-color: #0d1117;
42
+ color: #f0f6fc;
43
+ font-family: 'Segoe UI', Roboto, sans-serif;
44
+ }
45
+ .gradio-container {
46
+ max-width: 1200px;
47
+ margin: auto;
48
+ }
49
+ h1, h2, h3 {
50
+ color: #58a6ff;
51
+ }
52
+ .footer {
53
+ color: #8b949e;
54
+ font-size: 13px;
55
+ text-align: center;
56
+ margin-top: 25px;
57
+ }
58
+ """
59
+ ) as demo:
60
 
61
+ # 🧠 Encabezado
62
+ gr.Markdown(
63
+ """
64
+ # 🧠 Manual de Ciberseguridad Operativa – Doctor Linux Ltda.
65
+ ### *“Seguridad real, ingeniería aplicada.”*
66
+ ---
67
+ **Versión IA Edition 2025 – con asistencia técnica inteligente.**
68
+ """
69
+ )
70
 
71
+ # 💬 Pestaña de chat IA
72
  with gr.Tab("💬 Asistente IA"):
73
+ gr.ChatInterface(
74
+ fn=ask_ai,
75
+ title="Asistente Técnico Doctor Linux IA",
76
+ examples=[
77
+ ["Explícame cómo asegurar SSH en Debian."],
78
+ ["Muéstrame reglas básicas de firewall Mikrotik."],
79
+ ["Cómo monitorear jitter en Zabbix con ping ICMP."]
80
+ ],
81
+ )
82
 
83
+ # 📘 Pestañas para los módulos
84
  for m in MODULES:
85
  with gr.Tab(m["titulo"]):
86
  gr.Markdown(f"### 🎯 Objetivo\n{m['objetivo']}")
87
  gr.Markdown(f"#### 🧩 Contenido\n{m['contenido']}")
88
  if m.get("comandos"):
89
+ gr.Textbox(
90
+ value=m["comandos"],
91
+ label="Comandos (solo lectura)",
92
+ lines=8,
93
+ interactive=False,
94
+ )
95
  if m.get("checklist"):
96
+ gr.CheckboxGroup(choices=m["checklist"], label="Checklist técnico")
97
 
98
+ # 🧾 Pie de página
99
+ gr.Markdown(
100
+ "<div class='footer'>© 2025 Doctor Linux Ltda. – Departamento de Ingeniería | IA Edition – CPU Basic Compatible</div>"
101
+ )
102
 
103
  if __name__ == "__main__":
104
  demo.launch()
requirements.txt CHANGED
@@ -2,3 +2,4 @@ gradio>=4.31.0
2
  transformers>=4.41.0
3
  sentencepiece>=0.1.99
4
  accelerate>=0.31.0
 
 
2
  transformers>=4.41.0
3
  sentencepiece>=0.1.99
4
  accelerate>=0.31.0
5
+ # No fijar torch: el runtime ya incluye una versión válida