Spaces:
Runtime error
Runtime error
Upload app.py with huggingface_hub
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529"""Legion Coder - Hugging Face SpaceA powerful coding assistant powered by the Legion Coder 8M model.10k Edition - 2026
MADE WITH BY DEATH LEGIONPOWERED BY nvdya-kit
2026 DEATH LEGION. All rights reserved."""
import osimport sysimport torchimport streamlit as stimport timefrom transformers import AutoModelForCausalLM, AutoTokenizer
# Page config with custom branding - 10k Edition 2026st.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 iconsst.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 stateif "messages" not in st.session_state: st.session_state.messages = []
# Model configuration - Using verified public repoMODEL_ID = "dineth554/legion-coder-8m-10k"
# Cache the model loading@st.cache_resourcedef 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
# Headerst.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 Bannerst.markdown("""<div class="death-legion-banner"> MADE WITH BY DEATH LEGION 2026</div>""", unsafe_allow_html=True)
# nvdya-kit Bannerst.markdown("""<div class="nvdya-banner"> Powered by nvdya-kit | Next-Gen AI Infrastructure</div>""", unsafe_allow_html=True)
# Sidebar with 10k Edition specswith 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 sectionst.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 modelmodel, 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 interfacest.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 messagesfor message in st.session_state.messages: with st.chat_message(message["role"]): st.markdown(message["content"])
# Chat inputif 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 hereif __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 brandingst.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)app.pyAdded+529