Armacam commited on
Commit
fc3d107
·
verified ·
1 Parent(s): 0153f13

Deploy from HuggingChat

Browse files
Files changed (2) hide show
  1. README.md +9 -5
  2. index.html +562 -19
README.md CHANGED
@@ -1,10 +1,14 @@
1
  ---
2
- title: Agente H Brido Nvidia Edge Ai Orchestrator
3
- emoji: 📉
4
- colorFrom: yellow
5
- colorTo: green
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
1
  ---
2
+ title: "Agente Híbrido NVIDIA - Edge AI Orchestrator"
3
+ emoji: 🤗
4
+ colorFrom: gray
5
+ colorTo: pink
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - huggingchat
10
  ---
11
 
12
+ # Agente Híbrido NVIDIA - Edge AI Orchestrator
13
+
14
+ Built with [HuggingChat](https://huggingface.co/chat).
index.html CHANGED
@@ -1,19 +1,562 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="es">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Agente Híbrido NVIDIA - Edge AI Orchestrator</title>
7
+ <style>
8
+ :root {
9
+ --bg: #0b0f19;
10
+ --card: #111827;
11
+ --border: #1f2937;
12
+ --accent: #76b900;
13
+ --accent2: #00d4ff;
14
+ --text: #e5e7eb;
15
+ --muted: #9ca3af;
16
+ --danger: #f87171;
17
+ }
18
+ * { box-sizing: border-box; }
19
+ body {
20
+ margin: 0; font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
21
+ background: var(--bg); color: var(--text); line-height: 1.6;
22
+ }
23
+ header {
24
+ background: linear-gradient(90deg, #0000%, #0b1d0b 100%);
25
+ border-bottom: 1px solid var(--border);
26
+ padding: 2rem 1.5rem; text-align: center;
27
+ }
28
+ header h1 { margin: 0; font-size: 1.8rem; color: var(--accent); letter-spacing: -0.5px; }
29
+ header p { margin: .5rem 0 0; color: var(--muted); font-size: .95rem; }
30
+ .container { max-width: 1000px; margin: 0 auto; padding: 1.5rem; }
31
+ .tabs { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
32
+ .tab {
33
+ background: var(--card); border: 1px solid var(--border);
34
+ color: var(--muted); padding: .65rem 1.1rem; border-radius: 8px;
35
+ cursor: pointer; font-size: .92rem; transition: .2s;
36
+ }
37
+ .tab:hover { color: var(--text); border-color: var(--accent); }
38
+ .tab.active { color: #fff; border-color: var(--accent); background: #162818; }
39
+ .panel { display: none; animation: fade .3s ease; }
40
+ .panel.active { display: block; }
41
+ @keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }
42
+ .card {
43
+ background: var(--card); border: 1px solid var(--border);
44
+ border-radius: 12px; padding: 1.5rem; margin-bottom: 1.5rem;
45
+ }
46
+ .card h2 { margin-top: 0; font-size: 1.15rem; color: var(--accent2); }
47
+ .tag {
48
+ display: inline-block; background: #1e293b; color: var(--accent2);
49
+ padding: .2rem .6rem; border-radius: 99px; font-size: .78rem;
50
+ margin: .15rem .2rem .15rem 0; border: 1px solid #334155;
51
+ }
52
+ pre {
53
+ background: #0e1525; border: 1px solid #1f2937; border-radius: 8px;
54
+ padding: 1rem; overflow-x: auto; font-size: .85rem; color: #d1d5db;
55
+ }
56
+ .highlight { color: var(--accent); }
57
+ .note {
58
+ border-left: 3px solid var(--accent); background: #0f1d0f;
59
+ padding: .8rem 1rem; border-radius: 0 8px 8px 0; color: #bbf7d0; font-size: .9rem;
60
+ }
61
+ .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
62
+ @media (max-width: 720px) { .grid-2 { grid-template-columns: 1fr; } }
63
+ button.copy {
64
+ float: right; background: #1f2937; border: 1px solid #334155; color: var(--text);
65
+ padding: .3rem .6rem; border-radius: 6px; font-size: .75rem; cursor: pointer;
66
+ }
67
+ button.copy:hover { background: #334155; }
68
+ svg.diagram { width: 100%; height: auto; }
69
+ </style>
70
+ </head>
71
+ <body>
72
+
73
+ <header>
74
+ <h1>🧠 Agente Híbrido NVIDIA Nemotron</h1>
75
+ <p>Edge AI Orchestrator · Razonamiento Multimodal · Multiplataforma ARM/Android · Automatización Agéntica</p>
76
+ </header>
77
+
78
+ <div class="container">
79
+ <div class="tabs" id="tabs">
80
+ <div class="tab active" onclick="show('vision')">Visión General</div>
81
+ <div class="tab" onclick="show('arq')">Arquitectura</div>
82
+ <div class="tab" onclick="show('core')">Core Python</div>
83
+ <div class="tab" onclick="show('android')">Android ARM</div>
84
+ <div class="tab" onclick="show('auto')">Auto-Cuentas/APIs</div>
85
+ <div class="tab" onclick="show('deploy')">Deploy</div>
86
+ </div>
87
+
88
+ <!-- VISIÓN -->
89
+ <div id="vision" class="panel active">
90
+ <div class="card">
91
+ <h2>🎯 Objetivo</h2>
92
+ <p>
93
+ Construir un <strong>agente cognitivo híbrido</strong> que use <strong>NVIDIA Nemotron 3</strong> como núcleo de razonamiento,
94
+ con capacidad para operar tanto en <em>cloud</em> (infraestructura GPU H100/B200) como en <em>edge</em>
95
+ (Jetson Thor, DGX Spark, Android ARM con NPU/GPU vía Arm NN / MLLM / Cactus).
96
+ El agente automatiza:
97
+ </p>
98
+ <ul>
99
+ <li><strong>Búsqueda y descubrimiento de APIs</strong> vía Hugging Face Discover (`hf discover`).</li>
100
+ <li><strong>Lectura inteligente de documentos</strong> (PDFs, manuales, términos) con OCR + reasoning multimodal.</li>
101
+ <li><strong>Registro y creación de cuentas</strong> automatizado mediante control de navegador + LLM.</li>
102
+ <li><strong>Generación de código multiplataforma</strong> (Python, Kotlin, C++, Rust) acelerado con NumPy-SVE en ARM.</li>
103
+ <li><strong>Traducción y razonamiento multilingüe</strong> (EN/ES/DE/FR/IT/JP/中文/한국어).</li>
104
+ </ul>
105
+ <div class="note">💡 <strong>Tip de modelo:</strong> Nemotron-3-Nano-Omni-30B-A3B en NVFP4 cabe en Jetson Thor/RTX 5090 y permite video+audio+texto+razonamiento en un solo modelo.</div>
106
+ </div>
107
+ <div class="grid-2">
108
+ <div class="card">
109
+ <h2>🔧 Stack Tecnológico</h2>
110
+ <div>
111
+ <span class="tag">NVIDIA Nemotron 3</span>
112
+ <span class="tag">Hugging Face Hub</span>
113
+ <span class="tag">HF CLI & Skills</span>
114
+ <span class="tag">vLLM / TensorRT-LLM</span>
115
+ <span class="tag">Playwright</span>
116
+ <span class="tag">NumPy + SVE</span>
117
+ <span class="tag">MLLM / Cactus</span>
118
+ <span class="tag">Arm NN (Android)</span>
119
+ <span class="tag">KleidiAI</span>
120
+ <span class="tag">Kotlin Multiplatform</span>
121
+ <span class="tag">ExecuTorch</span>
122
+ <span class="tag">QNN / Hexagon NPU</span>
123
+ </div>
124
+ </div>
125
+ <div class="card">
126
+ <h2>📐 Patrón de Despliegue</h2>
127
+ <ul>
128
+ <li><strong>Cloud:</strong> Nemotron-3-Super-120B o Ultra-550B en vLLM con reasoning on/off.</li>
129
+ <li><strong>Edge:</strong> Nemotron-3-Nano-Omni-30B en NVFP4 via TensorRT-LLM o llama.cpp.</li>
130
+ <li><strong>Android:</strong> Modelo cuantizado INT4/W4A16 ejecutado con MLLM + servidor in-app Golang.</li>
131
+ </ul>
132
+ </div>
133
+ </div>
134
+ </div>
135
+
136
+ <!-- ARQUITECTURA -->
137
+ <div id="arq" class="panel">
138
+ <div class="card">
139
+ <h2>🏗 Diagrama de Arquitectura</h2>
140
+ <svg class="diagram" viewBox="0 0 800 520" xmlns="http://www.w3.org/2000/svg">
141
+ <defs>
142
+ <linearGradient id="g1" x1="0" y1="0" x2="1" y2="1"><stop offset="0%" stop-color="#111827"/><stop offset="100%" stop-color="#0b1222"/></linearGradient>
143
+ </defs>
144
+ <rect x="10" y="10" width="780" height="500" rx="14" fill="url(#g1)" stroke="#1f2937" stroke-width="1"/>
145
+ <!-- Nemotron Core -->
146
+ <rect x="250" y="40" width="300" height="70" rx="10" fill="#162818" stroke="#76b900" stroke-width="2"/>
147
+ <text x="400" y="65" fill="#76b900" font-size="13" font-weight="bold" text-anchor="middle">NVIDIA Nemotron 3 Core</text>
148
+ <text x="400" y="85" fill="#9ca3af" font-size="11" text-anchor="middle">Reasoning · Tool Calling · Multimodal</text>
149
+ <text x="400" y="100" fill="#9ca3af" font-size="11" text-anchor="middle">NVFP4 / BF16 / FP8</text>
150
+
151
+ <!-- Hugging Face Skills -->
152
+ <rect x="40" y="160" width="220" height="90" rx="10" fill="#0e1525" stroke="#00d4ff" stroke-width="1"/>
153
+ <text x="150" y="185" fill="#00d4ff" font-size="12" font-weight="bold" text-anchor="middle">HF CLI + Skills</text>
154
+ <text x="150" y="205" fill="#9ca3af" font-size="10" text-anchor="middle">hf discover · hf skills add</text>
155
+ <text x="150" y="220" fill="#9ca3af" font-size="10" text-anchor="middle">API search · MCP Servers</text>
156
+ <text x="150" y="235" fill="#9ca3af" font-size="10" text-anchor="middle">Jobs · Datasets · Models</text>
157
+
158
+ <!-- Automatización -->
159
+ <rect x="290" y="160" width="220" height="90" rx="10" fill="#0e1525" stroke="#f87171" stroke-width="1"/>
160
+ <text x="400" y="185" fill="#f87171" font-size="12" font-weight="bold" text-anchor="middle">Agente de Automatización</text>
161
+ <text x="400" y="205" fill="#9ca3af" font-size="10" text-anchor="middle">Playwright + LLM</text>
162
+ <text x="400" y="220" fill="#9ca3af" font-size="10" text-anchor="middle">Doc Parser · OCR · RAG</text>
163
+ <text x="400" y="235" fill="#9ca3af" font-size="10" text-anchor="middle">Creación de Cuentas</text>
164
+
165
+ <!-- Code Gen -->
166
+ <rect x="540" y="160" width="220" height="90" rx="10" fill="#0e1525" stroke="#fbbf24" stroke-width="1"/>
167
+ <text x="650" y="185" fill="#fbbf24" font-size="12" font-weight="bold" text-anchor="middle">Generación de Código</text>
168
+ <text x="650" y="205" fill="#9ca3af" font-size="10" text-anchor="middle">Multi-idioma · Multiplataforma</text>
169
+ <text x="650" y="220" fill="#9ca3af" font-size="10" text-anchor="middle">Python · Kotlin · C++ · Rust</text>
170
+ <text x="650" y="235" fill="#9ca3af" font-size="10" text-anchor="middle">NumPy acelerado (SVE/AVX)</text>
171
+
172
+ <!-- Connectors -->
173
+ <line x1="150" y1="160" x2="320" y2="110" stroke="#374151" stroke-width="1"/>
174
+ <line x1="400" y1="160" x2="400" y2="110" stroke="#374151" stroke-width="1"/>
175
+ <line x1="650" y1="160" x2="480" y2="110" stroke="#374151" stroke-width="1"/>
176
+
177
+ <!-- Edge Layer -->
178
+ <rect x="40" y="290" width="350" height="90" rx="10" fill="#1a1025" stroke="#a78bfa" stroke-width="1"/>
179
+ <text x="215" y="315" fill="#a78bfa" font-size="12" font-weight="bold" text-anchor="middle">Edge / On-Device Runtime</text>
180
+ <text x="215" y="335" fill="#9ca3af" font-size="10" text-anchor="middle">MLLM · Cactus · Arm NN · ExecuTorch</text>
181
+ <text x="215" y="350" fill="#9ca3af" font-size="10" text-anchor="middle">Android (Kotlin) · Linux ARM · Jetson</text>
182
+ <text x="215" y="365" fill="#9ca3af" font-size="10" text-anchor="middle">INT4/W4A16 · NPU / GPU / CPU</text>
183
+
184
+ <!-- NumPy Accel -->
185
+ <rect x="410" y="290" width="350" height="90" rx="10" fill="#1a1025" stroke="#f472b6" stroke-width="1"/>
186
+ <text x="585" y="315" fill="#f472b6" font-size="12" font-weight="bold" text-anchor="middle">Computación Acelerada</text>
187
+ <text x="585" y="335" fill="#9ca3af" font-size="10" text-anchor="middle">NumPy + OpenBLAS / MKL / SVE</text>
188
+ <text x="585" y="350" fill="#9ca3af" font-size="10" text-anchor="middle">CuPy / Numba · CUDA / ROCm</text>
189
+ <text x="585" y="365" fill="#9ca3af" font-size="10" text-anchor="middle">TensorRT-LLM · vLLM · llama.cpp</text>
190
+
191
+ <line x1="400" y1="250" x2="215" y2="290" stroke="#374151" stroke-width="1"/>
192
+ <line x1="400" y1="250" x2="585" y2="290" stroke="#374151" stroke-width="1"/>
193
+
194
+ <!-- Data Ingest -->
195
+ <rect x="40" y="420" width="720" height="60" rx="10" fill="#0f172a" stroke="#334155" stroke-width="1"/>
196
+ <text x="400" y="445" fill="#94a3b8" font-size="12" font-weight="bold" text-anchor="middle">Entradas: Texto · Imagen · Audio · Video · PDF · Web · APIs</text>
197
+ <text x="400" y="465" fill="#64748b" font-size="10" text-anchor="middle">OCR (Nano Omni) · ASR (Parakeet) · Traducción · Embeddings</text>
198
+
199
+ <line x1="215" y1="380" x2="300" y2="420" stroke="#374151" stroke-width="1"/>
200
+ <line x1="585" y1="380" x2="500" y2="420" stroke="#374151" stroke-width="1"/>
201
+ </svg>
202
+ </div>
203
+ </div>
204
+
205
+ <!-- CORE PYTHON -->
206
+ <div id="core" class="panel">
207
+ <div class="card">
208
+ <h2>🐍 Core Python: Nemotron + HF Skills + NumPy SVE</h2>
209
+ <button class="copy" onclick="copy(this)">Copiar</button>
210
+ <pre><code><span class="highlight"># orchestrator.py - Motor híbrido del agente</span>
211
+ import os
212
+ from huggingface_hub import hf_hub_download, HfApi
213
+ from transformers import AutoTokenizer, AutoModelForCausalLM
214
+ import numpy as np
215
+ import subprocess
216
+ import json
217
+
218
+ <span class="highlight"># 1. CONFIGURACIÓN HÍBRIDA</span>
219
+ class HybridConfig:
220
+ CLOUD_MODEL = "nvidia/NVIDIA-Nemotron-3-Super-120B-A12B-FP8"
221
+ EDGE_MODEL = "nvidia/Nemotron-3-Nano-Omni-30B-A3B-Reasoning-NVFP4"
222
+ HF_TOKEN = os.getenv("HF_TOKEN")
223
+ ENABLE_SVE = True # Activar kernels SVE en ARM
224
+
225
+ <span class="highlight"># 2. CLI WRAPPER PARA SKILLS Y DISCOVER</span>
226
+ class HFAgentCLI:
227
+ @staticmethod
228
+ def search_skill(query: str, kind="skill"):
229
+ <span class="highlight">"""Descubre APIs, skills o MCP servers automáticamente."""</span>
230
+ cmd = ["hf", "discover", "search", query, "--kind", kind, "--json"]
231
+ out = subprocess.run(cmd, capture_output=True, text=True)
232
+ return json.loads(out.stdout) if out.returncode == 0 else {}
233
+
234
+ @staticmethod
235
+ def add_skill(scope="--global"):
236
+ subprocess.run(["hf", "skills", "add", scope])
237
+
238
+ @staticmethod
239
+ def download_model(repo_id: str, filename: str = None):
240
+ api = HfApi(token=HybridConfig.HF_TOKEN)
241
+ if filename:
242
+ return hf_hub_download(repo_id, filename, token=HybridConfig.HF_TOKEN)
243
+ return repo_id
244
+
245
+ <span class="highlight"># 3. REASONING ENGINE</span>
246
+ class NemotronEngine:
247
+ def __init__(self, model_name: str, device="cuda"):
248
+ self.tok = AutoTokenizer.from_pretrained(
249
+ model_name, token=HybridConfig.HF_TOKEN, trust_remote_code=True
250
+ )
251
+ self.model = AutoModelForCausalLM.from_pretrained(
252
+ model_name,
253
+ token=HybridConfig.HF_TOKEN,
254
+ device_map="auto",
255
+ torch_dtype="auto",
256
+ trust_remote_code=True
257
+ )
258
+ self.device = device
259
+
260
+ def reason(self, prompt: str, enable_thinking=True) -&gt; dict:
261
+ <span class="highlight">"""Genera traza de razonamiento + respuesta final."""</span>
262
+ messages = [
263
+ {"role": "system", "content": "enable_thinking=True" if enable_thinking else ""},
264
+ {"role": "user", "content": prompt}
265
+ ]
266
+ inputs = self.tok.apply_chat_template(
267
+ messages, tokenize=True, return_tensors="pt", add_generation_prompt=True
268
+ ).to(self.device)
269
+ outputs = self.model.generate(inputs, max_new_tokens=2048, do_sample=False)
270
+ text = self.tok.decode(outputs[0], skip_special_tokens=False)
271
+ <span class="highlight"># Parsing de reasoning trace vs final answer</span>
272
+ return {"raw": text, "thinking": self._extract_thinking(text), "answer": self._extract_answer(text)}
273
+
274
+ def _extract_thinking(self, text): return text.split("&lt;think&gt;")[-1].split("&lt;/think&gt;")[0] if "&lt;think&gt;" in text else ""
275
+ def _extract_answer(self, text): return text.split("&lt;/think&gt;")[-1] if "&lt;/think&gt;" in text else text
276
+
277
+ <span class="highlight"># 4. NUMPY ACELERADO PARA ARM (SVE)</span>
278
+ class AcceleratedCompute:
279
+ def __init__(self):
280
+ self.backend = "numpy+openblas"
281
+ if HybridConfig.ENABLE_SVE:
282
+ <span class="highlight"># En compilaciones con SVE, NumPy usa kernels SVE para HPC ARM</span>
283
+ try:
284
+ import scipy; self.backend += "+scipy"
285
+ except Exception: pass
286
+
287
+ def fast_matmul(self, a: np.ndarray, b: np.ndarray) -&gt; np.ndarray:
288
+ <span class="highlight">"""GEMM acelerado; en ARM con SVE puede alcanzar hasta 1300x vs scalar."""</span>
289
+ return np.dot(a, b)
290
+
291
+ <span class="highlight"># 5. API DE AGENTE COMPLETA</span>
292
+ if __name__ == "__main__":
293
+ <span class="highlight"># Instalar skills primero: hf skills add --global</span>
294
+ agent = NemotronEngine(HybridConfig.CLOUD_MODEL)
295
+ compute = AcceleratedCompute()
296
+
297
+ <span class="highlight"># Ejemplo: buscar APIs y razonar sobre ellas</span>
298
+ skills = HFAgentCLI.search_skill("API para generación de imágenes")
299
+ print(skills)
300
+
301
+ result = agent.reason(
302
+ "Analiza este JSON de APIs y dime cuál es mejor para generar imágenes en edge: " + json.dumps(skills),
303
+ enable_thinking=True
304
+ )
305
+ print(result["thinking"])
306
+ print(result["answer"])
307
+ </code></pre>
308
+ </div>
309
+ <div class="note">
310
+ 💡 <strong>Punto clave:</strong> `hf discover search` permite que el agente encuentre automáticamente MCP servers y skills sin intervención humana.
311
+ </div>
312
+ </div>
313
+
314
+ <!-- ANDROID ARM -->
315
+ <div id="android" class="panel">
316
+ <div class="card">
317
+ <h2>📱 Android ARM - Edge Inference (MLLM / Cactus / ExecuTorch)</h2>
318
+ <button class="copy" onclick="copy(this)">Copiar</button>
319
+ <pre><code><span class="highlight">// build.gradle.kts - Dependencias para edge inference</span>
320
+ dependencies {
321
+ <span class="highlight">// Opción A: MLLM (Motor de inferencia multi-backend con servidor in-app)</span>
322
+ implementation(files("libs/mllm_server.aar"))
323
+
324
+ <span class="highlight">// Opción B: Cactus Compute (Kotlin Multiplatform + NPU)</span>
325
+ implementation("com.cactuscompute:geniex-android:0.2.0")
326
+
327
+ <span class="highlight">// Opción C: ExecuTorch (PyTorch Edge)</span>
328
+ implementation("org.pytorch:executorch-android:0.5.0")
329
+ }
330
+
331
+ <span class="highlight">// HybridAgent.kt - Agente que corre en Android/ARM</span>
332
+ package com.hybridagent.edge
333
+
334
+ import android.content.Context
335
+ import kotlinx.coroutines.*
336
+
337
+ class HybridEdgeAgent(private val ctx: Context) {
338
+ private val dispatcher = Dispatchers.Default <span class="highlight">// Carga modelo cuantizado W4A16 o INT4 para edge</span>
339
+ suspend fun initModel(modelPath: String) = withContext(dispatcher) {
340
+ <span class="highlight">// Ejemplo con MLLM: servidor in-app Golang vía FFI</span>
341
+ MLLMNative.loadModel(modelPath, backend = "qnn") <span class="highlight">// qnn, opencl, cpu</span>
342
+ }
343
+
344
+ <span class="highlight">// Razonamiento on-device con Nemotron-3-Nano (cuantizado)</span>
345
+ suspend fun reason(prompt: String): String = withContext(dispatcher) {
346
+ val system = "enable_thinking=True"
347
+ val json = """{"messages":[{"role":"system","content":"$system"},{"role":"user","content":"$prompt"}]}"""
348
+ MLLMNative.chat(json)
349
+ }
350
+
351
+ <span class="highlight">// OCR / Análisis de documentos (Nano Omni multimodal)</span>
352
+ suspend fun analyzeDocument(imageBytes: ByteArray): String = withContext(dispatcher) {
353
+ MLLMNative.processImage(imageBytes, task = "ocr+reasoning")
354
+ }
355
+
356
+ <span class="highlight">// Traducción acelerada por NPU</span>
357
+ suspend fun translate(text: String, targetLang: String): String = withContext(dispatcher) {
358
+ <span class="highlight">// El mismo modelo Nemotron soporta múltiples idiomas nativamente</span>
359
+ reason("Traduce al $targetLang: $text")
360
+ }
361
+
362
+ companion object {
363
+ <span class="highlight">// Singleton para la app</span>
364
+ @Volatile private var instance: HybridEdgeAgent? = null
365
+ fun getInstance(ctx: Context): HybridEdgeAgent =
366
+ instance ?: synchronized(this) {
367
+ instance ?: HybridEdgeAgent(ctx.applicationContext).also { instance = it }
368
+ }
369
+ }
370
+ }
371
+
372
+ <span class="highlight">// MainActivity.kt - Uso</span>
373
+ class MainActivity : AppCompatActivity() {
374
+ private val agent by lazy { HybridEdgeAgent.getInstance(this) }
375
+
376
+ override fun onCreate(savedInstanceState: Bundle?) {
377
+ super.onCreate(savedInstanceState)
378
+ lifecycleScope.launch {
379
+ agent.initModel("/sdcard/models/nemotron-3-nano-30b-q4.gguf")
380
+ val answer = agent.reason("Resume y traduce este documento...")
381
+ Log.d("Agent", answer)
382
+ }
383
+ }
384
+ }
385
+ </code></pre>
386
+ </div>
387
+ <div class="card">
388
+ <h2>⚡ Aceleración NumPy en Android (Chaquopy / Kivy)</h2>
389
+ <p>Si usas Python en Android con <strong>Chaquopy</strong> o integración JNI, compila NumPy contra <strong>OpenBLAS</strong> con soporte ARM NEON/SVE para aceleración vectorial.</p>
390
+ <pre><code># chaquopy build logic (build.gradle)
391
+ python {
392
+ pip {
393
+ install "numpy" <span class="highlight"># preferiblemente con wheel optimizado para ARM</span>
394
+ install "llama-cpp-python" <span class="highlight"># para inference ARM vía llama.cpp</span>
395
+ }
396
+ }</code></pre>
397
+ </div>
398
+ </div>
399
+
400
+ <!-- AUTOMATIZACIÓN -->
401
+ <div id="auto" class="panel">
402
+ <div class="card">
403
+ <h2>🤖 Módulo de Automatización: Cuentas + Documentos + APIs</h2>
404
+ <button class="copy" onclick="copy(this)">Copiar</button>
405
+ <pre><code><span class="highlight"># automation_engine.py - Motor de automatización agéntica</span>
406
+ import asyncio
407
+ from playwright.async_api import async_playwright
408
+ from dataclasses import dataclass
409
+ from typing import Optionalimport base64, json
410
+
411
+ @dataclass
412
+ class AccountConfig:
413
+ service: str <span class="highlight"># ej: "github", "aws", "huggingface"</span>
414
+ username: str
415
+ email: str
416
+ strategy: str = "llm_guided" <span class="highlight"># llm_guided o deterministic</span>
417
+
418
+ class AutomationEngine:
419
+ def __init__(self, nemotron_engine):
420
+ self.nemotron = nemotron_engine <span class="highlight"># instancia de NemotronEngine</span>
421
+ self.browser = None
422
+ self.page = None
423
+
424
+ async def start(self, headless=False):
425
+ self.playwright = await async_playwright().start()
426
+ self.browser = await self.playwright.chromium.launch(headless=headless)
427
+ self.page = await self.browser.new_page()
428
+
429
+ async def read_document(self, url_or_path: str) -&gt; dict:
430
+ <span class="highlight">"""Lee PDF o página web, extrae texto, resume y traduce."""</span>
431
+ if url_or_path.endswith(".pdf"):
432
+ await self.page.goto(f"https://docs.google.com/viewer?url={url_or_path}")
433
+ content = await self.page.inner_text("#viewer")
434
+ else:
435
+ await self.page.goto(url_or_path)
436
+ content = await self.page.inner_text("body")
437
+
438
+ <span class="highlight"># Envía al LLM para análisis profundo</span>
439
+ analysis = self.nemotron.reason(
440
+ f"Resume, extrae pasos clave y traduce esta documentación:\n\n{content[:8000]}",
441
+ enable_thinking=True
442
+ )
443
+ return analysis
444
+
445
+ async def create_account(self, config: AccountConfig) -&gt; bool:
446
+ <span class="highlight">"""Automatiza flujo de registro GUI usando LLM para navegación adaptativa."""</span>
447
+ guide = self.nemotron.reason(
448
+ f"Genera un plan paso a paso para crear una cuenta en {config.service}. "
449
+ f"Incluye URLs, selectores CSS probables, validaciones de email y TOS.",
450
+ enable_thinking=True
451
+ )["answer"]
452
+
453
+ <span class="highlight"># Parsear plan y ejecutar acciones Playwright</span>
454
+ steps = self._parse_plan(guide)
455
+ for action in steps:
456
+ if action["type"] == "goto":
457
+ await self.page.goto(action["url"])
458
+ elif action["type"] == "fill":
459
+ await self.page.fill(action["selector"], action["value"].replace("{{email}}", config.email))
460
+ elif action["type"] == "click":
461
+ await self.page.click(action["selector"])
462
+ await asyncio.sleep(0.5)
463
+ return True
464
+
465
+ def _parse_plan(self, plan_text: str) -&gt; list:
466
+ <span class="highlight">"""Convierte respuesta textual de Nemotron a estructura ejecutable."""</span>
467
+ <span class="highlight"># Implementación con regex/JSON parsing robusto</span>
468
+ return [{"type":"goto","url":"https://github.com/signup"},{"type":"fill","selector":"#email","value":"{{email}}"}]
469
+
470
+ async def discover_api_and_setup(self, service_description: str):
471
+ <span class="highlight">"""Busca APIs vía HF Discover y configura tokens/env."""</span>
472
+ from orchestrator import HFAgentCLI
473
+ results = HFAgentCLI.search_skill(f"API for {service_description}", kind="mcp")
474
+ <span class="highlight"># El LLM selecciona la mejor API y genera código de setup</span>
475
+ choice = self.nemotron.reason(f"Selecciona la mejor API de este listado: {json.dumps(results)}")
476
+ return choice async def close(self):
477
+ await self.browser.close()
478
+ await self.playwright.stop()
479
+
480
+ <span class="highlight"># Ejecución de ejemplo</span>
481
+ async def main():
482
+ agent = AutomationEngine(nemotron_engine=NemotronEngine("nvidia/Nemotron-3-Nano-Omni-30B-A3B-Reasoning-BF16"))
483
+ await agent.start(headless=False)
484
+
485
+ <span class="highlight"># 1. Leer documentación de una API desconocida</span>
486
+ doc = await agent.read_document("https://huggingface.co/docs/huggingface_hub/guides/cli")
487
+ print(doc["answer"])
488
+
489
+ <span class="highlight"># 2. Crear cuenta adaptativamente</span>
490
+ await agent.create_account(AccountConfig(service="huggingface", username="dev01", email="dev01@ai.dev"))
491
+
492
+ await agent.close()
493
+
494
+ if __name__ == "__main__":
495
+ asyncio.run(main())
496
+ </code></pre>
497
+ </div>
498
+ <div class="card">
499
+ <h2>🌐 Uso de HF Discover para Encontrar APIs Automáticamente</h2>
500
+ <pre><code># Descubre skills y MCP servers sin dejar la terminal
501
+ hf discover search "image generation API" --kind mcp --json
502
+ hf discover search "transcribe audio API" --kind skill --json
503
+ hf discover search "train vision model" --limit 5
504
+
505
+ <span class="highlight"># Instala el skill directamente para que el agente lo use</span>
506
+ hf skills add --global</code></pre>
507
+ </div>
508
+ </div>
509
+
510
+ <!-- DEPLOY -->
511
+ <div id="deploy" class="panel">
512
+ <div class="card">
513
+ <h2>🚀 Guía de Despliegue Multi-Escenario</h2>
514
+ <table style="width:100%; border-collapse:collapse; color:#e5e7eb; font-size:.9rem;">
515
+ <tr style="background:#0e1525"><th style="padding:.6rem; text-align:left; border-bottom:1px solid #334155;">Escenario</th><th style="padding:.6rem; text-align:left; border-bottom:1px solid #334155;">Modelo</th><th style="padding:.6rem; text-align:left; border-bottom:1px solid #334155;">Runtime</th><th style="padding:.6rem; text-align:left; border-bottom:1px solid #334155;">Hardware</th></tr>
516
+ <tr><td style="padding:.6rem; border-bottom:1px solid #1f2937;">Cloud GPU</td><td style="padding:.6rem; border-bottom:1px solid #1f2937;">Nemotron-3-Ultra-550B-A55B</td><td style="padding:.6rem; border-bottom:1px solid #1f2937;">vLLM / TensorRT-LLM</td><td style="padding:.6rem; border-bottom:1px solid #1f2937;">2x B200 / 8x H100</td></tr>
517
+ <tr style="background:#0b0f19"><td style="padding:.6rem; border-bottom:1px solid #1f2937;">Workstation</td><td style="padding:.6rem; border-bottom:1px solid #1f2937;">Nemotron-3-Super-120B-A12B-FP8</td><td style="padding:.6rem; border-bottom:1px solid #1f2937;">TensorRT-LLM / vLLM</td><td style="padding:.6rem; border-bottom:1px solid #1f2937;">2x RTX Pro 6000 /2x H100</td></tr>
518
+ <tr><td style="padding:.6rem; border-bottom:1px solid #1f2937;">Edge / Developer</td><td style="padding:.6rem; border-bottom:1px solid #1f2937;">Nemotron-3-Nano-30B-A3B (NVFP4)</td><td style="padding:.6rem; border-bottom:1px solid #1f2937;">TensorRT-LLM / llama.cpp</td><td style="padding:.6rem; border-bottom:1px solid #1f2937;">DGX Spark / RTX 5090 / Jetson Thor</td></tr>
519
+ <tr style="background:#0b0f19"><td style="padding:.6rem; border-bottom:1px solid #1f2937;">Android NPU</td><td style="padding:.6rem; border-bottom:1px solid #1f2937;">Nemotron-3-Nano Q4/K quantized</td><td style="padding:.6rem; border-bottom:1px solid #1f2937;">MLLM + QNN / Cactus</td><td style="padding:.6rem; border-bottom:1px solid #1f2937;">Snapdragon 8 Gen4 / Dimensity 9400</td></tr>
520
+ <tr><td style="padding:.6rem; border-bottom:1px solid #1f2937;">ARM Linux Edge</td><td style="padding:.6rem; border-bottom:1px solid #1f2937;">Nemotron-H-47B / Nano 30B</td><td style="padding:.6rem; border-bottom:1px solid #1f2937;">llama.cpp + KleidiAI / Arm NN</td><td style="padding:.6rem; border-bottom:1f2937;">Raspberry Pi 5 (Cortex-A76) / AGX Orin</td></tr>
521
+ </table>
522
+ </div>
523
+ <div class="grid-2">
524
+ <div class="card">
525
+ <h2>🐳 Dockerfile - Cloud Agent</h2>
526
+ <pre><code>FROM nvidia/cuda:12.6-devel-ubuntu24.04
527
+ RUN pip install vllm huggingface_hub transformers playwrightRUN playwright install-deps
528
+ RUN hf skills add --global
529
+ ENV HF_TOKEN=${HF_TOKEN}
530
+ CMD ["python", "orchestrator.py"]</code></pre>
531
+ </div>
532
+ <div class="card">
533
+ <h2>📦 Dockerfile - Edge ARM</h2>
534
+ <pre><code>FROM arm64v8/python:3.12-slim
535
+ RUN pip install llama-cpp-python --extra-index-url ...
536
+ COPY models/ /models/
537
+ COPY orchestrator.py /
538
+ CMD ["python", "orchestrator.py", "--edge"]</code></pre>
539
+ </div>
540
+ </div>
541
+ <div class="note">
542
+ 🚀 <strong>Quick start:</strong> Para probar el razonamiento sin GPU masiva, usa el modelo <code>nvidia/OpenReasoning-Nemotron-32B</code> (derivado de Qwen2.5) con vLLM en una sola H100 o incluso RTX 4090 con cuantización.
543
+ </div>
544
+ </div>
545
+ </div>
546
+
547
+ <script>
548
+ function show(id) {
549
+ document.querySelectorAll('.panel').forEach(p => p.classList.remove('active'));
550
+ document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
551
+ document.getElementById(id).classList.add('active');
552
+ event.target.classList.add('active');
553
+ }
554
+ function copy(btn) {
555
+ const code = btn.parentElement.querySelector('pre').innerText;
556
+ navigator.clipboard.writeText(code);
557
+ btn.textContent = "¡Copiado!";
558
+ setTimeout(() => btn.textContent = "Copiar", 1500);
559
+ }
560
+ </script>
561
+ </body>
562
+ </html>