File size: 3,013 Bytes
eee66aa
 
 
 
 
be5cf1f
 
eee66aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
be5cf1f
 
 
eee66aa
be5cf1f
eee66aa
be5cf1f
eee66aa
be5cf1f
 
 
eee66aa
be5cf1f
 
 
 
 
 
 
eee66aa
be5cf1f
 
eee66aa
be5cf1f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eee66aa
 
be5cf1f
 
eee66aa
 
be5cf1f
 
 
 
 
eee66aa
 
 
 
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
<!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>