| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta charset="utf-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1"> |
| <title>ClokCEM - Customer Executive Model</title> |
| <meta name="description" content="354M parameter model for enterprise customer support"> |
|
|
| <script type="module" crossorigin src="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.js"></script> |
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css" /> |
|
|
| <style> |
| html, body { |
| margin: 0; |
| padding: 0; |
| height: 100%; |
| } |
| </style> |
| </head> |
| <body> |
| <gradio-lite> |
| <gradio-file name="app.py" entrypoint> |
| import gradio as gr |
| import torch |
| from huggingface_hub import hf_hub_download |
| from safetensors.torch import load_file |
|
|
| MODEL_REPO = "clokai/CLOK-CEM" |
|
|
| print("Loading model...") |
|
|
| from configuration_clokcem import ClokcemConfig |
| from modeling_clokcem import ClokcemForCausalLM |
| from transformers import AutoTokenizer |
|
|
| config = ClokcemConfig() |
| model = ClokcemForCausalLM(config) |
|
|
| weights_path = hf_hub_download(repo_id=MODEL_REPO, filename="model.safetensors") |
| sd = load_file(weights_path) |
| model.load_state_dict(sd, strict=False) |
| model.eval() |
|
|
| tokenizer = AutoTokenizer.from_pretrained(MODEL_REPO) |
| print("Model ready!") |
|
|
| def chat(message, history, temperature, max_tokens): |
| device = next(model.parameters()).device |
| formatted = f"<|system|>You are a helpful customer care assistant.<|user|>{message}<|assistant|>" |
| inputs = tokenizer(formatted, return_tensors="pt").to(device) |
| |
| generated = [] |
| input_ids = inputs["input_ids"] |
| |
| for _ in range(max_tokens): |
| with torch.no_grad(): |
| logits = model(input_ids).logits |
| probs = torch.softmax(logits[:, -1, :] / temperature, dim=-1) |
| next_token = torch.multinomial(probs, num_samples=1) |
| if next_token.item() == tokenizer.eos_token_id: |
| break |
| generated.append(next_token.item()) |
| input_ids = torch.cat([input_ids, next_token], dim=-1) |
| |
| return tokenizer.decode(generated, skip_special_tokens=True) |
|
|
| demo = gr.ChatInterface( |
| fn=chat, |
| title="ClokCEM - Customer Executive Model", |
| description="354M parameter model for enterprise customer support", |
| additional_inputs=[ |
| gr.Slider(0.1, 2.0, value=0.6, step=0.1, label="Temperature"), |
| gr.Slider(50, 500, value=200, step=50, label="Max Tokens"), |
| ], |
| ) |
|
|
| demo.launch() |
| </gradio-file> |
|
|
| <gradio-file name="configuration_clokcem.py" url="https://huggingface.co/clokai/CLOK-CEM/resolve/main/configuration_clokcem.py" /> |
| <gradio-file name="modeling_clokcem.py" url="https://huggingface.co/clokai/CLOK-CEM/resolve/main/modeling_clokcem.py" /> |
|
|
| <gradio-requirements> |
| torch |
| transformers |
| safetensors |
| huggingface_hub |
| gradio |
| </gradio-requirements> |
| </gradio-lite> |
| </body> |
| </html> |