File size: 15,345 Bytes
9775ece
 
 
0bfd67d
9775ece
 
0bfd67d
 
 
9775ece
 
 
 
 
 
0bfd67d
 
9775ece
0bfd67d
9775ece
0bfd67d
 
9775ece
 
 
 
0bfd67d
9775ece
 
0bfd67d
9775ece
 
 
 
 
 
 
0bfd67d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9775ece
 
0bfd67d
 
9775ece
0bfd67d
 
 
 
9775ece
 
 
0bfd67d
 
9775ece
 
0bfd67d
9775ece
 
 
 
0bfd67d
9775ece
0bfd67d
9775ece
 
0bfd67d
 
 
 
 
 
 
 
9775ece
0bfd67d
 
 
 
9775ece
 
0bfd67d
 
 
9775ece
0bfd67d
9775ece
 
 
0bfd67d
 
 
 
9775ece
 
0bfd67d
 
 
 
 
9775ece
 
0bfd67d
 
 
 
 
 
 
9775ece
 
0bfd67d
 
 
 
 
 
9775ece
 
0bfd67d
 
 
 
 
 
 
 
9775ece
 
0bfd67d
 
 
 
9775ece
 
0bfd67d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9775ece
 
0bfd67d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9775ece
 
 
 
0bfd67d
9775ece
0bfd67d
 
9775ece
 
 
 
 
0bfd67d
 
 
 
 
 
9775ece
 
0bfd67d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9775ece
 
 
0bfd67d
 
 
9775ece
0bfd67d
 
9775ece
0bfd67d
9775ece
 
0bfd67d
 
9775ece
0bfd67d
 
 
 
 
 
 
 
9775ece
0bfd67d
9775ece
 
0bfd67d
 
 
 
 
 
 
 
 
9775ece
0bfd67d
 
9775ece
0bfd67d
 
 
 
 
 
9775ece
0bfd67d
 
 
 
 
 
9775ece
0bfd67d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9775ece
0bfd67d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9775ece
0bfd67d
 
9775ece
0bfd67d
 
 
 
9775ece
0bfd67d
 
 
 
 
 
 
 
9775ece
0bfd67d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9775ece
 
0bfd67d
 
 
 
 
 
9775ece
0bfd67d
 
 
 
 
 
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
"""
Legion Coder - Hugging Face Space
A powerful coding assistant powered by the Legion Coder 8M model.
10k Edition - 2026

MADE WITH BY DEATH LEGION
POWERED BY nvdya-kit

2026 DEATH LEGION. All rights reserved.
"""

import os
import sys
import torch
import streamlit as st
import time
from transformers import AutoModelForCausalLM, AutoTokenizer

# Page config with custom branding - 10k Edition 2026
st.set_page_config(
    page_title="Legion Coder 2026 | DEATH LEGION",
    page_icon="https://img.icons8.com/color/48/000000/code.png",
    layout="wide",
    initial_sidebar_state="expanded"
)

# Enhanced Custom CSS with 10k Edition branding - No emojis, professional icons
st.markdown("""
<style>
@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');

.main {
    font-family: 'Inter', sans-serif;
    background: linear-gradient(135deg, #0a0a0f 0%, #1a1a2e 50%, #16213e 100%);
    min-height: 100vh;
}

.death-legion-banner {
    background: linear-gradient(90deg, #ff0040 0%, #ff6b6b 25%, #7c4dff 75%, #9c27b0 100%);
    background-size: 200% 200%;
    padding: 1rem;
    border-radius: 12px;
    text-align: center;
    margin-bottom: 1rem;
    font-weight: 700;
    font-size: 1.1rem;
    color: white;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
    animation: gradientShift 3s ease infinite, pulse 2s infinite;
    font-family: 'Orbitron', sans-serif;
    letter-spacing: 2px;
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.nvdya-banner {
    background: linear-gradient(90deg, #00d4ff 0%, #7c4dff 100%);
    padding: 0.6rem;
    border-radius: 8px;
    text-align: center;
    margin-bottom: 1rem;
    font-weight: 600;
    font-size: 0.95rem;
    color: white;
    font-family: 'Orbitron', sans-serif;
    letter-spacing: 1px;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 0, 64, 0.4); }
    70% { box-shadow: 0 0 0 15px rgba(255, 0, 64, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 0, 64, 0); }
}

.cursor-blink {
    display: inline-block;
    width: 10px;
    height: 1.3em;
    background: linear-gradient(180deg, #ff4081, #ff0040);
    animation: blink 0.8s step-end infinite;
    vertical-align: text-bottom;
    margin-left: 3px;
    border-radius: 2px;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.header-container {
    background: linear-gradient(90deg, #ff0040 0%, #ff4081 50%, #7c4dff 100%);
    padding: 2.5rem;
    border-radius: 20px;
    margin-bottom: 2rem;
    box-shadow: 0 15px 50px rgba(255, 0, 64, 0.4);
    text-align: center;
    position: relative;
    overflow: hidden;
}

.header-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 3rem;
    font-weight: 700;
    color: #ffffff;
    text-shadow: 3px 3px 6px rgba(0,0,0,0.4);
    margin: 0;
}

.header-subtitle {
    font-size: 1.2rem;
    color: rgba(255,255,255,0.9);
    margin-top: 0.8rem;
}

.sidebar-content {
    padding: 1.5rem 0;
}

.sidebar-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.3rem;
    font-weight: 700;
    color: #ff4081;
    margin-bottom: 1.5rem;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.sidebar-section {
    background: rgba(255,255,255,0.05);
    border-radius: 16px;
    padding: 1.2rem;
    margin-bottom: 1.2rem;
    border: 1px solid rgba(255,255,255,0.1);
}

.sidebar-label {
    font-size: 0.9rem;
    color: rgba(255,255,255,0.7);
    margin-bottom: 0.4rem;
}

.sidebar-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem;
    font-weight: 600;
    color: #ffffff;
}

.downloads-badge {
    background: linear-gradient(135deg, rgba(255,0,64,0.2) 0%, rgba(124,77,255,0.2) 100%);
    border: 2px solid rgba(255,0,64,0.5);
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 1.2rem;
    text-align: center;
}

.downloads-label {
    color: #ff4081;
    font-weight: 700;
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
    font-family: 'Orbitron', sans-serif;
}

.downloads-number {
    font-family: 'JetBrains Mono', monospace;
    font-size: 2.2rem;
    font-weight: 800;
    background: linear-gradient(90deg, #ff0040, #ff6b6b);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin: 0.5rem 0;
}

.downloads-subtext {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.6);
    margin-top: 0.3rem;
}

.trending-indicator {
    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;
}

.trending-dot {
    width: 8px;
    height: 8px;
    background: #ff0040;
    border-radius: 50%;
    animation: pulse-dot 1.5s infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.2); }
}

.deploy-section {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border: 2px solid rgba(255, 0, 64, 0.4);
    border-radius: 16px;
    padding: 2rem;
    margin: 1.5rem 0;
}

.deploy-title {
    color: #ff4081;
    font-weight: 700;
    font-size: 1.3rem;
    margin-bottom: 1rem;
    font-family: 'Orbitron', sans-serif;
}

.chat-container {
    max-width: 950px;
    margin: 0 auto;
}

.footer {
    text-align: center;
    padding: 2.5rem;
    color: rgba(255,255,255,0.5);
    font-size: 0.9rem;
    border-top: 2px solid rgba(255,255,255,0.1);
    margin-top: 3rem;
}

.footer-brand {
    color: #ff4081;
    font-weight: 700;
    font-family: 'Orbitron', sans-serif;
}

.footer-year {
    color: #00d4ff;
    font-weight: 600;
}

.loading-dots:after {
    content: '.';
    animation: dots 1.5s steps(5, end) infinite;
}

@keyframes dots {
    0%, 20% { content: ''; }
    40% { content: '.'; }
    60% { content: '..'; }
    80%, 100% { content: '...'; }
}

.typing-text {
    font-family: 'JetBrains Mono', monospace;
    line-height: 1.6;
}
</style>
""", unsafe_allow_html=True)

# Initialize session state
if "messages" not in st.session_state:
    st.session_state.messages = []

# Model configuration - Using verified public repo
MODEL_ID = "dineth554/legion-coder-8m-10k"

# Cache the model loading
@st.cache_resource
def load_model():
    """Load the Legion Coder model and tokenizer."""
    with st.spinner("Loading Legion Coder 8M model..."):
        try:
            tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
            model = AutoModelForCausalLM.from_pretrained(
                MODEL_ID,
                torch_dtype=torch.float32,
                device_map="cpu",
                trust_remote_code=True
            )
            return model, tokenizer
        except Exception as e:
            st.error(f"Error loading model: {e}")
            return None, None

# Header
st.markdown("""
<div class="header-container">
    <h1 class="header-title">LEGION CODER 2026</h1>
    <p class="header-subtitle">Advanced AI Code Generation by DEATH LEGION</p>
    <div style="margin-top: 0.8rem;">
        <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);">
            POWERED BY nvdya-kit
        </span>
    </div>
</div>
""", unsafe_allow_html=True)

# Death Legion Banner
st.markdown("""
<div class="death-legion-banner">
    MADE WITH BY DEATH LEGION 2026
</div>
""", unsafe_allow_html=True)

# nvdya-kit Banner
st.markdown("""
<div class="nvdya-banner">
    Powered by nvdya-kit | Next-Gen AI Infrastructure
</div>
""", unsafe_allow_html=True)

# Sidebar with 10k Edition specs
with st.sidebar:
    st.markdown("""
    <div class="sidebar-content">
        <div class="sidebar-title">Model Specs 2026</div>
        
        <div class="sidebar-section">
            <div class="sidebar-label">[ARCH] Architecture</div>
            <div class="sidebar-value">Transformer 2026</div>
        </div>
        
        <div class="sidebar-section">
            <div class="sidebar-label">[PARAMS] Parameters</div>
            <div class="sidebar-value">44,341,632</div>
        </div>
        
        <div class="sidebar-section">
            <div class="sidebar-label">[SIZE] Model Size</div>
            <div class="sidebar-value">~170 MB</div>
        </div>
        
        <div class="sidebar-section">
            <div class="sidebar-label">[LAYERS] Layers</div>
            <div class="sidebar-value">13</div>
        </div>
        
        <div class="sidebar-section">
            <div class="sidebar-label">[HEADS] Attention Heads</div>
            <div class="sidebar-value">16</div>
        </div>
        
        <div class="sidebar-section">
            <div class="sidebar-label">[CONTEXT] Context Length</div>
            <div class="sidebar-value">1,024 tokens</div>
        </div>
        
        <div class="sidebar-section">
            <div class="sidebar-label">[VOCAB] Vocabulary</div>
            <div class="sidebar-value">16,000 tokens</div>
        </div>
        
        <div class="sidebar-section">
            <div class="sidebar-label">[FORMAT] Format</div>
            <div class="sidebar-value">Safetensors</div>
        </div>
        
        <div class="sidebar-section">
            <div class="sidebar-label">[YEAR] Release</div>
            <div class="sidebar-value">2026 Edition</div>
        </div>
        
        <div class="downloads-badge">
            <div class="downloads-label">10K+ DOWNLOADS MILESTONE</div>
            <div class="downloads-number">10,000+</div>
            <div class="downloads-subtext">Downloads and counting</div>
            <div class="trending-indicator">
                <span class="trending-dot"></span>
                <span>TRENDING</span>
            </div>
        </div>
    </div>
    """, unsafe_allow_html=True)

# Deployment section
st.markdown("""
<div class="deploy-section">
    <div class="deploy-title">Deploy 2026</div>
    <div style="display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center;">
        <a href="https://huggingface.co/pnny13/legion-coder-8m/deploy/sagemaker"
           style="display: inline-block; background: linear-gradient(90deg, #ff9900 0%, #ff6600 100%);
           color: white; padding: 0.7rem 1.2rem; border-radius: 8px; text-decoration: none;
           font-weight: 600; margin: 0.3rem;">AWS SageMaker</a>
        <a href="https://huggingface.co/pnny13/legion-coder-8m"
           style="display: inline-block; background: linear-gradient(90deg, #ff9900 0%, #ff6600 100%);
           color: white; padding: 0.7rem 1.2rem; border-radius: 8px; text-decoration: none;
           font-weight: 600; margin: 0.3rem;">Model Hub</a>
    </div>
</div>
""", unsafe_allow_html=True)

# Load model
model, tokenizer = load_model()

if model is None:
    st.error("Failed to load model. Please check the repository configuration.")
else:
    st.success("Model loaded successfully!")

# Main chat interface
st.markdown("""
<div class="chat-container">
    <h3 style="color: #ff4081; font-family: 'Orbitron', sans-serif; margin-bottom: 1.5rem;">
        [CHAT] Start Coding
    </h3>
</div>
""", unsafe_allow_html=True)

# Display chat messages
for message in st.session_state.messages:
    with st.chat_message(message["role"]):
        st.markdown(message["content"])

# Chat input
if prompt := st.chat_input("Ask Legion Coder to write or explain code..."):
    # Add user message
    st.session_state.messages.append({"role": "user", "content": prompt})
    with st.chat_message("user"):
        st.markdown(prompt)

    # Generate response with typing animation
    with st.chat_message("assistant"):
        message_placeholder = st.empty()
        
        # Typing animation
        with message_placeholder:
            st.markdown("""
            <div style="display: inline-block;">
                <span class="loading-dots">Generating code</span>
                <span class="cursor-blink"></span>
            </div>
            """, unsafe_allow_html=True)
        
        if model is not None and tokenizer is not None:
            try:
                # Prepare input
                system_prompt = "You are a helpful coding assistant. Write clean, efficient code."
                full_prompt = f"{system_prompt}\n\nUser: {prompt}\n\nAssistant:"
                
                # Tokenize
                inputs = tokenizer(full_prompt, return_tensors="pt", max_length=1024, truncation=True)
                
                # Generate
                with torch.no_grad():
                    outputs = model.generate(
                        inputs["input_ids"],
                        max_new_tokens=200,
                        temperature=0.8,
                        top_p=0.95,
                        do_sample=True,
                        pad_token_id=tokenizer.eos_token_id
                    )
                
                # Decode
                response = tokenizer.decode(outputs[0], skip_special_tokens=True)
                
                # Extract just the assistant response
                if "Assistant:" in response:
                    response = response.split("Assistant:")[-1].strip()
                
                # Simulate typing delay for smooth animation
                time.sleep(0.5)
                
            except Exception as e:
                response = f"Error generating response: {str(e)}"
        else:
            # Fallback response if model not loaded
            time.sleep(1)
            response = """Here is a solution for your request:

```python
# Legion Coder 2026 - Generated Code
# Powered by DEATH LEGION & nvdya-kit

def example_function():
    \"\"\"
    This is an example function generated by Legion Coder.
    Replace this with your actual implementation.
    \"\"\"
    pass

# TODO: Implement your specific logic here
if __name__ == "__main__":
    result = example_function()
    print(f"Result: {result}")
```

**Explanation:**
- This code provides a starting structure for your request
- Modify the `example_function()` to implement your specific logic
- The code follows PEP 8 guidelines and best practices
- Generated by Legion Coder 2026 - DEATH LEGION

Would you like me to explain any part of this code or help you implement specific functionality?"""
        
        # Display final response with typing effect
        message_placeholder.markdown(f'<div class="typing-text">{response}</div>', unsafe_allow_html=True)
        
        # Add assistant message to history
        st.session_state.messages.append({"role": "assistant", "content": response})

# Footer with 2026 branding
st.markdown("""
<div class="footer">
    <div style="margin-bottom: 0.5rem;">
        <span class="footer-brand">DEATH LEGION</span> |
        <span class="footer-year">2026 Edition</span>
    </div>
    <div>Powered by nvdya-kit | Next-Gen AI Infrastructure</div>
    <div style="margin-top: 0.5rem; font-size: 0.8rem;">
        Legion Coder 8M | 44M Parameters | ~170MB | CPU-Optimized | 10K+ Downloads
    </div>
</div>
""", unsafe_allow_html=True)