Spaces:
Build error
Build error
File size: 3,922 Bytes
a9da9d6 a988c2e a9da9d6 a988c2e a9da9d6 ffc2ccb a9da9d6 a988c2e a9da9d6 a988c2e a9da9d6 a988c2e ffc2ccb a988c2e a9da9d6 ffc2ccb a9da9d6 a988c2e a9da9d6 a988c2e a9da9d6 a988c2e | 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 | import gradio as gr
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, TextIteratorStreamer
from threading import Thread
MODEL_ID = "BrainboxAI/code-il-E4B-safetensors"
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
model = AutoModelForCausalLM.from_pretrained(
MODEL_ID,
torch_dtype=torch.float32,
device_map="cpu",
low_cpu_mem_usage=True,
)
model.eval()
EXAMPLES = [
["Implement binary search in TypeScript with full edge case handling and JSDoc comments."],
["Build a FastAPI endpoint that accepts a file upload, validates it's a PDF under 10MB, and returns its text content."],
["Write an n8n Code node (JavaScript) that takes input items, deduplicates by 'email' field, and returns the unique ones."],
["讛住讘专 讗转 讛拽讜讚 讛讘讗 讜转爪讬注 砖讬驻讜专讬诐:\n\nfunction calc(arr) {\n let s = 0;\n for (let i = 0; i < arr.length; i++) s += arr[i];\n return s / arr.length;\n}"],
]
def generate(message, history, temperature, max_tokens):
messages = []
for msg in history:
if isinstance(msg, dict):
messages.append({"role": msg["role"], "content": msg["content"]})
else:
user_msg, assistant_msg = msg
messages.append({"role": "user", "content": user_msg})
if assistant_msg:
messages.append({"role": "assistant", "content": assistant_msg})
messages.append({"role": "user", "content": message})
inputs = tokenizer.apply_chat_template(
messages,
return_tensors="pt",
add_generation_prompt=True,
)
streamer = TextIteratorStreamer(
tokenizer, skip_prompt=True, skip_special_tokens=True
)
thread = Thread(target=model.generate, kwargs={
"input_ids": inputs,
"max_new_tokens": max_tokens,
"temperature": temperature,
"top_p": 0.95,
"do_sample": temperature > 0,
"streamer": streamer,
"pad_token_id": tokenizer.eos_token_id,
})
thread.start()
output = ""
for token in streamer:
output += token
yield output
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), title="Code-IL E4B") as demo:
gr.Markdown("""
# code-il-E4B
### 诪讜讚诇 拽讜讚 讬砖专讗诇讬 - 4 诪讬诇讬讗专讚 驻专诪讟专讬诐, 专抓 注诇 诪讞砖讘 谞讬讬讚
诪讜讚诇 诪讘讜住住 Gemma 4 E4B 砖讗讜诪谉 注诇 OpenCodeInstruct 砖诇 NVIDIA + dataset 拽讜讚 注讘专讬-讗谞讙诇讬 诪砖诇讬.
诪转诪讞讛 讘-Python, TypeScript, n8n, 讜转讜诪讱 讘注讘专讬转.
> 鈿狅笍 **讚诪讜 讝讛 专抓 注诇 CPU - 讬拽讞 10-30 砖谞讬讜转 诇转砖讜讘讛.**
> 诇讛专爪讛 诪讛讬专讛 讘诪讞砖讘 砖诇讱: 专讗讛 讛讜专讗讜转 讘转讞转讬转.
**By [BrainboxAI](https://huggingface.co/BrainboxAI)** - Powered by Unsloth
""")
chat = gr.ChatInterface(
fn=generate,
type="messages",
examples=EXAMPLES,
cache_examples=False,
additional_inputs=[
gr.Slider(0.0, 1.0, value=0.2, step=0.05, label="Temperature"),
gr.Slider(64, 512, value=256, step=64, label="Max Tokens (谞诪讜讱 = 诪讛讬专 讬讜转专)"),
],
additional_inputs_accordion=gr.Accordion("鈿欙笍 讛讙讚专讜转 诪转拽讚诪讜转", open=False),
)
gr.Markdown("""
---
### 讛专爪讛 诪拽讜诪讬转 (诪讛讬专讛)
```python
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("BrainboxAI/code-il-E4B-safetensors")
model = AutoModelForCausalLM.from_pretrained("BrainboxAI/code-il-E4B-safetensors",
torch_dtype="auto", device_map="auto")
```
**Training**: NVIDIA OpenCodeInstruct (4.97M) + BrainboxAI/code-training-il (40k) + bleugreen/typescript-instruct (41k)
**Format**: Safetensors 16-bit | **License**: Apache 2.0 | **Languages**: English + 注讘专讬转
""")
if __name__ == "__main__":
demo.queue(max_size=10).launch()
|