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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Legion Coder - Gradio Interface
|
| 3 |
+
A powerful coding assistant powered by the Legion Coder 8M model.
|
| 4 |
+
10k Edition - 2026
|
| 5 |
+
|
| 6 |
+
MADE WITH BY DEATH LEGION
|
| 7 |
+
POWERED BY nvdya-kit
|
| 8 |
+
|
| 9 |
+
2026 DEATH LEGION. All rights reserved.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
import os
|
| 13 |
+
import sys
|
| 14 |
+
import torch
|
| 15 |
+
import gradio as gr
|
| 16 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 17 |
+
|
| 18 |
+
# Model configuration
|
| 19 |
+
MODEL_ID = "dineth554/legion-coder-8m-10k"
|
| 20 |
+
|
| 21 |
+
# Custom CSS for dark professional theme
|
| 22 |
+
custom_css = """
|
| 23 |
+
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600;700&family=Inter:wght@400;500;600;700&family=Orbitron:wght@400;700&display=swap');
|
| 24 |
+
|
| 25 |
+
:root {
|
| 26 |
+
--primary-gradient: linear-gradient(90deg, #ff0040 0%, #ff6b6b 25%, #7c4dff 75%, #9c27b0 100%);
|
| 27 |
+
--nvdya-gradient: linear-gradient(90deg, #00d4ff 0%, #7c4dff 100%);
|
| 28 |
+
--bg-dark: #0a0a0f;
|
| 29 |
+
--bg-card: #1a1a2e;
|
| 30 |
+
--border-color: rgba(255, 0, 64, 0.3);
|
| 31 |
+
--text-primary: #ffffff;
|
| 32 |
+
--text-secondary: rgba(255, 255, 255, 0.7);
|
| 33 |
+
--accent-pink: #ff4081;
|
| 34 |
+
--accent-cyan: #00d4ff;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
body {
|
| 38 |
+
font-family: 'Inter', sans-serif !important;
|
| 39 |
+
background: var(--bg-dark) !important;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
.gradio-container {
|
| 43 |
+
background: linear-gradient(135deg, #0a0a0f 0%, #1a1a2e 50%, #16213e 100%) !important;
|
| 44 |
+
min-height: 100vh !important;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
/* Header styling */
|
| 48 |
+
.header-container {
|
| 49 |
+
background: var(--primary-gradient) !important;
|
| 50 |
+
background-size: 200% 200% !important;
|
| 51 |
+
padding: 2rem !important;
|
| 52 |
+
border-radius: 16px !important;
|
| 53 |
+
margin-bottom: 1.5rem !important;
|
| 54 |
+
text-align: center !important;
|
| 55 |
+
animation: gradientShift 3s ease infinite !important;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
@keyframes gradientShift {
|
| 59 |
+
0% { background-position: 0% 50%; }
|
| 60 |
+
50% { background-position: 100% 50%; }
|
| 61 |
+
100% { background-position: 0% 50%; }
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
.header-title {
|
| 65 |
+
font-family: 'Orbitron', sans-serif !important;
|
| 66 |
+
font-size: 2.5rem !important;
|
| 67 |
+
font-weight: 700 !important;
|
| 68 |
+
color: #ffffff !important;
|
| 69 |
+
text-shadow: 2px 2px 4px rgba(0,0,0,0.4) !important;
|
| 70 |
+
margin: 0 !important;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
.header-subtitle {
|
| 74 |
+
font-size: 1rem !important;
|
| 75 |
+
color: rgba(255,255,255,0.9) !important;
|
| 76 |
+
margin-top: 0.5rem !important;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
/* Banner styling */
|
| 80 |
+
.death-legion-banner {
|
| 81 |
+
background: var(--primary-gradient) !important;
|
| 82 |
+
background-size: 200% 200% !important;
|
| 83 |
+
padding: 1rem !important;
|
| 84 |
+
border-radius: 12px !important;
|
| 85 |
+
text-align: center !important;
|
| 86 |
+
margin-bottom: 1rem !important;
|
| 87 |
+
font-weight: 700 !important;
|
| 88 |
+
font-size: 1.1rem !important;
|
| 89 |
+
color: white !important;
|
| 90 |
+
font-family: 'Orbitron', sans-serif !important;
|
| 91 |
+
letter-spacing: 2px !important;
|
| 92 |
+
animation: gradientShift 3s ease infinite, pulse 2s infinite !important;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
@keyframes pulse {
|
| 96 |
+
0% { box-shadow: 0 0 0 0 rgba(255, 0, 64, 0.4); }
|
| 97 |
+
70% { box-shadow: 0 0 0 15px rgba(255, 0, 64, 0); }
|
| 98 |
+
100% { box-shadow: 0 0 0 0 rgba(255, 0, 64, 0); }
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
.nvdya-banner {
|
| 102 |
+
background: var(--nvdya-gradient) !important;
|
| 103 |
+
padding: 0.6rem !important;
|
| 104 |
+
border-radius: 8px !important;
|
| 105 |
+
text-align: center !important;
|
| 106 |
+
margin-bottom: 1rem !important;
|
| 107 |
+
font-weight: 600 !important;
|
| 108 |
+
font-size: 0.95rem !important;
|
| 109 |
+
color: white !important;
|
| 110 |
+
font-family: 'Orbitron', sans-serif !important;
|
| 111 |
+
letter-spacing: 1px !important;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
/* Sidebar styling */
|
| 115 |
+
.sidebar-title {
|
| 116 |
+
font-family: 'Orbitron', sans-serif !important;
|
| 117 |
+
font-size: 1.2rem !important;
|
| 118 |
+
font-weight: 700 !important;
|
| 119 |
+
color: var(--accent-pink) !important;
|
| 120 |
+
margin-bottom: 1rem !important;
|
| 121 |
+
text-align: center !important;
|
| 122 |
+
text-transform: uppercase !important;
|
| 123 |
+
letter-spacing: 2px !important;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
.sidebar-section {
|
| 127 |
+
background: rgba(255,255,255,0.05) !important;
|
| 128 |
+
border-radius: 12px !important;
|
| 129 |
+
padding: 1rem !important;
|
| 130 |
+
margin-bottom: 1rem !important;
|
| 131 |
+
border: 1px solid rgba(255,255,255,0.1) !important;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
.sidebar-label {
|
| 135 |
+
font-size: 0.85rem !important;
|
| 136 |
+
color: rgba(255,255,255,0.7) !important;
|
| 137 |
+
margin-bottom: 0.3rem !important;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.sidebar-value {
|
| 141 |
+
font-family: 'JetBrains Mono', monospace !important;
|
| 142 |
+
font-size: 1rem !important;
|
| 143 |
+
font-weight: 600 !important;
|
| 144 |
+
color: #ffffff !important;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
/* Downloads badge */
|
| 148 |
+
.downloads-badge {
|
| 149 |
+
background: linear-gradient(135deg, rgba(255,0,64,0.2) 0%, rgba(124,77,255,0.2) 100%) !important;
|
| 150 |
+
border: 2px solid rgba(255,0,64,0.5) !important;
|
| 151 |
+
border-radius: 16px !important;
|
| 152 |
+
padding: 1.2rem !important;
|
| 153 |
+
margin-bottom: 1rem !important;
|
| 154 |
+
text-align: center !important;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
.downloads-label {
|
| 158 |
+
color: var(--accent-pink) !important;
|
| 159 |
+
font-weight: 700 !important;
|
| 160 |
+
font-size: 0.8rem !important;
|
| 161 |
+
margin-bottom: 0.5rem !important;
|
| 162 |
+
font-family: 'Orbitron', sans-serif !important;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
.downloads-number {
|
| 166 |
+
font-family: 'JetBrains Mono', monospace !important;
|
| 167 |
+
font-size: 2rem !important;
|
| 168 |
+
font-weight: 800 !important;
|
| 169 |
+
background: linear-gradient(90deg, #ff0040, #ff6b6b) !important;
|
| 170 |
+
-webkit-background-clip: text !important;
|
| 171 |
+
-webkit-text-fill-color: transparent !important;
|
| 172 |
+
margin: 0.5rem 0 !important;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
/* Chat interface */
|
| 176 |
+
.chat-container {
|
| 177 |
+
background: var(--bg-card) !important;
|
| 178 |
+
border-radius: 16px !important;
|
| 179 |
+
border: 1px solid var(--border-color) !important;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
.message.user {
|
| 183 |
+
background: rgba(255, 0, 64, 0.1) !important;
|
| 184 |
+
border-left: 3px solid #ff0040 !important;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.message.bot {
|
| 188 |
+
background: rgba(0, 212, 255, 0.1) !important;
|
| 189 |
+
border-left: 3px solid #00d4ff !important;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
/* Input styling */
|
| 193 |
+
.input-container textarea {
|
| 194 |
+
background: rgba(255,255,255,0.05) !important;
|
| 195 |
+
border: 1px solid rgba(255,255,255,0.1) !important;
|
| 196 |
+
border-radius: 12px !important;
|
| 197 |
+
color: white !important;
|
| 198 |
+
font-family: 'JetBrains Mono', monospace !important;
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
.input-container textarea:focus {
|
| 202 |
+
border-color: var(--accent-pink) !important;
|
| 203 |
+
box-shadow: 0 0 0 2px rgba(255, 0, 64, 0.2) !important;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
/* Button styling */
|
| 207 |
+
button.primary {
|
| 208 |
+
background: var(--primary-gradient) !important;
|
| 209 |
+
border: none !important;
|
| 210 |
+
border-radius: 8px !important;
|
| 211 |
+
font-weight: 600 !important;
|
| 212 |
+
text-transform: uppercase !important;
|
| 213 |
+
letter-spacing: 1px !important;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
button.secondary {
|
| 217 |
+
background: rgba(255,255,255,0.1) !important;
|
| 218 |
+
border: 1px solid rgba(255,255,255,0.2) !important;
|
| 219 |
+
border-radius: 8px !important;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
/* Code blocks */
|
| 223 |
+
pre {
|
| 224 |
+
background: #0d1117 !important;
|
| 225 |
+
border-radius: 12px !important;
|
| 226 |
+
border: 1px solid rgba(255,255,255,0.1) !important;
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
code {
|
| 230 |
+
font-family: 'JetBrains Mono', monospace !important;
|
| 231 |
+
color: #e6edf3 !important;
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
/* Footer */
|
| 235 |
+
.footer {
|
| 236 |
+
text-align: center !important;
|
| 237 |
+
padding: 2rem !important;
|
| 238 |
+
color: rgba(255,255,255,0.5) !important;
|
| 239 |
+
font-size: 0.9rem !important;
|
| 240 |
+
border-top: 2px solid rgba(255,255,255,0.1) !important;
|
| 241 |
+
margin-top: 2rem !important;
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
/* Deploy section */
|
| 245 |
+
.deploy-section {
|
| 246 |
+
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%) !important;
|
| 247 |
+
border: 2px solid rgba(255, 0, 64, 0.4) !important;
|
| 248 |
+
border-radius: 16px !important;
|
| 249 |
+
padding: 1.5rem !important;
|
| 250 |
+
margin: 1rem 0 !important;
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
.deploy-title {
|
| 254 |
+
color: var(--accent-pink) !important;
|
| 255 |
+
font-weight: 700 !important;
|
| 256 |
+
font-size: 1.2rem !important;
|
| 257 |
+
margin-bottom: 1rem !important;
|
| 258 |
+
font-family: 'Orbitron', sans-serif !important;
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
/* Typing cursor */
|
| 262 |
+
.typing-cursor {
|
| 263 |
+
display: inline-block !important;
|
| 264 |
+
width: 10px !important;
|
| 265 |
+
height: 1.2em !important;
|
| 266 |
+
background: linear-gradient(180deg, #ff4081, #ff0040) !important;
|
| 267 |
+
animation: blink 0.8s step-end infinite !important;
|
| 268 |
+
vertical-align: text-bottom !important;
|
| 269 |
+
margin-left: 3px !important;
|
| 270 |
+
border-radius: 2px !important;
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
@keyframes blink {
|
| 274 |
+
0%, 50% { opacity: 1; }
|
| 275 |
+
51%, 100% { opacity: 0; }
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
/* Scrollbar */
|
| 279 |
+
::-webkit-scrollbar {
|
| 280 |
+
width: 8px !important;
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
::-webkit-scrollbar-track {
|
| 284 |
+
background: rgba(255,255,255,0.05) !important;
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
::-webkit-scrollbar-thumb {
|
| 288 |
+
background: rgba(255, 0, 64, 0.5) !important;
|
| 289 |
+
border-radius: 4px !important;
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
::-webkit-scrollbar-thumb:hover {
|
| 293 |
+
background: rgba(255, 0, 64, 0.7) !important;
|
| 294 |
+
}
|
| 295 |
+
"""
|
| 296 |
+
|
| 297 |
+
# Global model and tokenizer
|
| 298 |
+
model = None
|
| 299 |
+
tokenizer = None
|
| 300 |
+
|
| 301 |
+
def load_model():
|
| 302 |
+
"""Load the Legion Coder model and tokenizer."""
|
| 303 |
+
global model, tokenizer
|
| 304 |
+
if model is None or tokenizer is None:
|
| 305 |
+
try:
|
| 306 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
|
| 307 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 308 |
+
MODEL_ID,
|
| 309 |
+
torch_dtype=torch.float32,
|
| 310 |
+
device_map="cpu",
|
| 311 |
+
trust_remote_code=True
|
| 312 |
+
)
|
| 313 |
+
return True
|
| 314 |
+
except Exception as e:
|
| 315 |
+
print(f"Error loading model: {e}")
|
| 316 |
+
return False
|
| 317 |
+
return True
|
| 318 |
+
|
| 319 |
+
def generate_code(message, history, temperature, max_tokens):
|
| 320 |
+
"""Generate code response using the Legion Coder model."""
|
| 321 |
+
global model, tokenizer
|
| 322 |
+
|
| 323 |
+
if not load_model():
|
| 324 |
+
return "Error: Failed to load model. Please check the repository configuration."
|
| 325 |
+
|
| 326 |
+
try:
|
| 327 |
+
# Prepare system prompt
|
| 328 |
+
system_prompt = "You are a helpful coding assistant. Write clean, efficient code."
|
| 329 |
+
|
| 330 |
+
# Build conversation history
|
| 331 |
+
conversation = system_prompt + "\n\n"
|
| 332 |
+
for human, assistant in history:
|
| 333 |
+
conversation += f"User: {human}\nAssistant: {assistant}\n\n"
|
| 334 |
+
conversation += f"User: {message}\nAssistant:"
|
| 335 |
+
|
| 336 |
+
# Tokenize
|
| 337 |
+
inputs = tokenizer(conversation, return_tensors="pt", max_length=1024, truncation=True)
|
| 338 |
+
|
| 339 |
+
# Generate
|
| 340 |
+
with torch.no_grad():
|
| 341 |
+
outputs = model.generate(
|
| 342 |
+
inputs["input_ids"],
|
| 343 |
+
max_new_tokens=max_tokens,
|
| 344 |
+
temperature=temperature,
|
| 345 |
+
top_p=0.95,
|
| 346 |
+
do_sample=True,
|
| 347 |
+
pad_token_id=tokenizer.eos_token_id
|
| 348 |
+
)
|
| 349 |
+
|
| 350 |
+
# Decode
|
| 351 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 352 |
+
|
| 353 |
+
# Extract just the assistant response
|
| 354 |
+
if "Assistant:" in response:
|
| 355 |
+
response = response.split("Assistant:")[-1].strip()
|
| 356 |
+
|
| 357 |
+
return response
|
| 358 |
+
|
| 359 |
+
except Exception as e:
|
| 360 |
+
return f"Error generating response: {str(e)}"
|
| 361 |
+
|
| 362 |
+
# Create the Gradio interface
|
| 363 |
+
def create_interface():
|
| 364 |
+
"""Create the Gradio chat interface."""
|
| 365 |
+
|
| 366 |
+
with gr.Blocks(css=custom_css, title="Legion Coder 2026") as demo:
|
| 367 |
+
# Header
|
| 368 |
+
gr.HTML("""
|
| 369 |
+
<div class="header-container">
|
| 370 |
+
<h1 class="header-title">LEGION CODER 2026</h1>
|
| 371 |
+
<p class="header-subtitle">Advanced AI Code Generation by DEATH LEGION</p>
|
| 372 |
+
<div style="margin-top: 0.8rem;">
|
| 373 |
+
<span style="background: rgba(0,0,0,0.3); padding: 0.4rem 1rem; border-radius: 25px; font-size: 0.8rem; font-weight: 600; color: #ff4081; border: 1px solid rgba(255,64,129,0.3);">
|
| 374 |
+
POWERED BY nvdya-kit
|
| 375 |
+
</span>
|
| 376 |
+
</div>
|
| 377 |
+
</div>
|
| 378 |
+
""")
|
| 379 |
+
|
| 380 |
+
# Death Legion Banner
|
| 381 |
+
gr.HTML("""
|
| 382 |
+
<div class="death-legion-banner">
|
| 383 |
+
MADE WITH BY DEATH LEGION 2026
|
| 384 |
+
</div>
|
| 385 |
+
""")
|
| 386 |
+
|
| 387 |
+
# nvdya-kit Banner
|
| 388 |
+
gr.HTML("""
|
| 389 |
+
<div class="nvdya-banner">
|
| 390 |
+
Powered by nvdya-kit | Next-Gen AI Infrastructure
|
| 391 |
+
</div>
|
| 392 |
+
""")
|
| 393 |
+
|
| 394 |
+
with gr.Row():
|
| 395 |
+
# Sidebar
|
| 396 |
+
with gr.Column(scale=1):
|
| 397 |
+
gr.HTML("""
|
| 398 |
+
<div class="sidebar-title">Model Specs 2026</div>
|
| 399 |
+
|
| 400 |
+
<div class="sidebar-section">
|
| 401 |
+
<div class="sidebar-label">[ARCH] Architecture</div>
|
| 402 |
+
<div class="sidebar-value">Transformer 2026</div>
|
| 403 |
+
</div>
|
| 404 |
+
|
| 405 |
+
<div class="sidebar-section">
|
| 406 |
+
<div class="sidebar-label">[PARAMS] Parameters</div>
|
| 407 |
+
<div class="sidebar-value">44,341,632</div>
|
| 408 |
+
</div>
|
| 409 |
+
|
| 410 |
+
<div class="sidebar-section">
|
| 411 |
+
<div class="sidebar-label">[SIZE] Model Size</div>
|
| 412 |
+
<div class="sidebar-value">~170 MB</div>
|
| 413 |
+
</div>
|
| 414 |
+
|
| 415 |
+
<div class="sidebar-section">
|
| 416 |
+
<div class="sidebar-label">[LAYERS] Layers</div>
|
| 417 |
+
<div class="sidebar-value">13</div>
|
| 418 |
+
</div>
|
| 419 |
+
|
| 420 |
+
<div class="sidebar-section">
|
| 421 |
+
<div class="sidebar-label">[HEADS] Attention Heads</div>
|
| 422 |
+
<div class="sidebar-value">16</div>
|
| 423 |
+
</div>
|
| 424 |
+
|
| 425 |
+
<div class="sidebar-section">
|
| 426 |
+
<div class="sidebar-label">[CONTEXT] Context Length</div>
|
| 427 |
+
<div class="sidebar-value">1,024 tokens</div>
|
| 428 |
+
</div>
|
| 429 |
+
|
| 430 |
+
<div class="sidebar-section">
|
| 431 |
+
<div class="sidebar-label">[VOCAB] Vocabulary</div>
|
| 432 |
+
<div class="sidebar-value">16,000 tokens</div>
|
| 433 |
+
</div>
|
| 434 |
+
|
| 435 |
+
<div class="sidebar-section">
|
| 436 |
+
<div class="sidebar-label">[FORMAT] Format</div>
|
| 437 |
+
<div class="sidebar-value">Safetensors</div>
|
| 438 |
+
</div>
|
| 439 |
+
|
| 440 |
+
<div class="downloads-badge">
|
| 441 |
+
<div class="downloads-label">10K+ DOWNLOADS MILESTONE</div>
|
| 442 |
+
<div class="downloads-number">10,000+</div>
|
| 443 |
+
<div style="font-size: 0.75rem; color: rgba(255,255,255,0.6); margin-top: 0.3rem;">Downloads and counting</div>
|
| 444 |
+
<div style="display: inline-flex; align-items: center; gap: 5px; background: rgba(255,0,64,0.2); padding: 0.3rem 0.8rem; border-radius: 20px; font-size: 0.75rem; color: #ff4081; margin-top: 0.5rem;">
|
| 445 |
+
<span style="width: 8px; height: 8px; background: #ff0040; border-radius: 50%; animation: pulse-dot 1.5s infinite;"></span>
|
| 446 |
+
<span>TRENDING</span>
|
| 447 |
+
</div>
|
| 448 |
+
</div>
|
| 449 |
+
|
| 450 |
+
# Parameters
|
| 451 |
+
temperature = gr.Slider(
|
| 452 |
+
minimum=0.1,
|
| 453 |
+
maximum=1.0,
|
| 454 |
+
value=0.8,
|
| 455 |
+
step=0.1,
|
| 456 |
+
label="Temperature",
|
| 457 |
+
info="Controls creativity vs determinism"
|
| 458 |
+
)
|
| 459 |
+
|
| 460 |
+
max_tokens = gr.Slider(
|
| 461 |
+
minimum=50,
|
| 462 |
+
maximum=500,
|
| 463 |
+
value=200,
|
| 464 |
+
step=50,
|
| 465 |
+
label="Max Tokens",
|
| 466 |
+
info="Maximum response length"
|
| 467 |
+
)
|
| 468 |
+
|
| 469 |
+
# Deploy section
|
| 470 |
+
gr.HTML("""
|
| 471 |
+
<div class="deploy-section">
|
| 472 |
+
<div class="deploy-title">Deploy 2026</div>
|
| 473 |
+
<div style="display: flex; flex-direction: column; gap: 0.5rem;">
|
| 474 |
+
<a href="https://huggingface.co/pnny13/legion-coder-8m/deploy/sagemaker"
|
| 475 |
+
style="display: block; background: linear-gradient(90deg, #ff9900 0%, #ff6600 100%);
|
| 476 |
+
color: white; padding: 0.7rem 1.2rem; border-radius: 8px; text-decoration: none;
|
| 477 |
+
font-weight: 600; text-align: center;">AWS SageMaker</a>
|
| 478 |
+
<a href="https://huggingface.co/pnny13/legion-coder-8m"
|
| 479 |
+
style="display: block; background: linear-gradient(90deg, #ff9900 0%, #ff6600 100%);
|
| 480 |
+
color: white; padding: 0.7rem 1.2rem; border-radius: 8px; text-decoration: none;
|
| 481 |
+
font-weight: 600; text-align: center;">Model Hub</a>
|
| 482 |
+
</div>
|
| 483 |
+
</div>
|
| 484 |
+
""")
|
| 485 |
+
|
| 486 |
+
# Main chat area
|
| 487 |
+
with gr.Column(scale=3):
|
| 488 |
+
gr.HTML("""
|
| 489 |
+
<h3 style="color: #ff4081; font-family: 'Orbitron', sans-serif; margin-bottom: 1rem;">
|
| 490 |
+
[CHAT] Start Coding
|
| 491 |
+
</h3>
|
| 492 |
+
""")
|
| 493 |
+
|
| 494 |
+
chatbot = gr.Chatbot(
|
| 495 |
+
height=500,
|
| 496 |
+
bubble_full_width=False,
|
| 497 |
+
show_copy_button=True,
|
| 498 |
+
avatar_images=(
|
| 499 |
+
"https://img.icons8.com/color/48/000000/user-male-circle.png",
|
| 500 |
+
"https://img.icons8.com/color/48/000000/code.png"
|
| 501 |
+
)
|
| 502 |
+
)
|
| 503 |
+
|
| 504 |
+
msg = gr.Textbox(
|
| 505 |
+
placeholder="Ask Legion Coder to write or explain code...",
|
| 506 |
+
label="",
|
| 507 |
+
container=False,
|
| 508 |
+
scale=7
|
| 509 |
+
)
|
| 510 |
+
|
| 511 |
+
with gr.Row():
|
| 512 |
+
submit_btn = gr.Button("Send", variant="primary", scale=1)
|
| 513 |
+
clear_btn = gr.Button("Clear", variant="secondary", scale=1)
|
| 514 |
+
|
| 515 |
+
# Footer
|
| 516 |
+
gr.HTML("""
|
| 517 |
+
<div class="footer">
|
| 518 |
+
<span style="color: #ff4081; font-weight: 700; font-family: 'Orbitron', sans-serif;">MADE WITH BY DEATH LEGION</span>
|
| 519 |
+
<br><br>
|
| 520 |
+
<span style="color: #00d4ff; font-weight: 600;">Powered by nvdya-kit</span>
|
| 521 |
+
<br><br>
|
| 522 |
+
<span style="color: rgba(255,255,255,0.5);">2026 DEATH LEGION. All rights reserved.</span>
|
| 523 |
+
</div>
|
| 524 |
+
""")
|
| 525 |
+
|
| 526 |
+
# Event handlers
|
| 527 |
+
def respond(message, chat_history, temp, max_tok):
|
| 528 |
+
"""Handle message response."""
|
| 529 |
+
bot_message = generate_code(message, chat_history, temp, max_tok)
|
| 530 |
+
chat_history.append([message, bot_message])
|
| 531 |
+
return "", chat_history
|
| 532 |
+
|
| 533 |
+
def clear_chat():
|
| 534 |
+
"""Clear chat history."""
|
| 535 |
+
return None, []
|
| 536 |
+
|
| 537 |
+
submit_btn.click(
|
| 538 |
+
respond,
|
| 539 |
+
inputs=[msg, chatbot, temperature, max_tokens],
|
| 540 |
+
outputs=[msg, chatbot]
|
| 541 |
+
)
|
| 542 |
+
|
| 543 |
+
msg.submit(
|
| 544 |
+
respond,
|
| 545 |
+
inputs=[msg, chatbot, temperature, max_tokens],
|
| 546 |
+
outputs=[msg, chatbot]
|
| 547 |
+
)
|
| 548 |
+
|
| 549 |
+
clear_btn.click(
|
| 550 |
+
clear_chat,
|
| 551 |
+
outputs=[msg, chatbot]
|
| 552 |
+
)
|
| 553 |
+
|
| 554 |
+
return demo
|
| 555 |
+
|
| 556 |
+
# Create and launch the interface
|
| 557 |
+
if __name__ == "__main__":
|
| 558 |
+
demo = create_interface()
|
| 559 |
+
demo.launch(
|
| 560 |
+
server_name="0.0.0.0",
|
| 561 |
+
server_port=7860,
|
| 562 |
+
share=False,
|
| 563 |
+
show_error=True
|
| 564 |
+
)
|