Update index.html
Browse files- index.html +57 -22
index.html
CHANGED
|
@@ -3,8 +3,8 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="utf-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 6 |
-
<title>
|
| 7 |
-
<meta name="description" content="
|
| 8 |
|
| 9 |
<script type="module" crossorigin src="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.js"></script>
|
| 10 |
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css" />
|
|
@@ -21,36 +21,71 @@
|
|
| 21 |
<gradio-lite>
|
| 22 |
<gradio-file name="app.py" entrypoint>
|
| 23 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
|
| 27 |
-
|
| 28 |
-
output_image = as_gray(input_image)
|
| 29 |
-
return output_image
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
"image",
|
| 35 |
-
examples=["lion.jpg", "logo.png"],
|
| 36 |
-
)
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
|
| 44 |
-
def
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
</gradio-file>
|
| 47 |
|
| 48 |
-
<gradio-file name="
|
| 49 |
-
<gradio-file name="
|
| 50 |
|
| 51 |
<gradio-requirements>
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
| 54 |
</gradio-requirements>
|
| 55 |
</gradio-lite>
|
| 56 |
</body>
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="utf-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 6 |
+
<title>ClokCEM - Customer Executive Model</title>
|
| 7 |
+
<meta name="description" content="354M parameter model for enterprise customer support">
|
| 8 |
|
| 9 |
<script type="module" crossorigin src="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.js"></script>
|
| 10 |
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css" />
|
|
|
|
| 21 |
<gradio-lite>
|
| 22 |
<gradio-file name="app.py" entrypoint>
|
| 23 |
import gradio as gr
|
| 24 |
+
import torch
|
| 25 |
+
from huggingface_hub import hf_hub_download
|
| 26 |
+
from safetensors.torch import load_file
|
| 27 |
|
| 28 |
+
MODEL_REPO = "clokai/CLOK-CEM"
|
| 29 |
|
| 30 |
+
print("Loading model...")
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
from configuration_clokcem import ClokcemConfig
|
| 33 |
+
from modeling_clokcem import ClokcemForCausalLM
|
| 34 |
+
from transformers import AutoTokenizer
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
config = ClokcemConfig()
|
| 37 |
+
model = ClokcemForCausalLM(config)
|
| 38 |
+
|
| 39 |
+
weights_path = hf_hub_download(repo_id=MODEL_REPO, filename="model.safetensors")
|
| 40 |
+
sd = load_file(weights_path)
|
| 41 |
+
model.load_state_dict(sd, strict=False)
|
| 42 |
+
model.eval()
|
| 43 |
|
| 44 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_REPO)
|
| 45 |
+
print("Model ready!")
|
| 46 |
|
| 47 |
+
def chat(message, history, temperature, max_tokens):
|
| 48 |
+
device = next(model.parameters()).device
|
| 49 |
+
formatted = f"<|system|>You are a helpful customer care assistant.<|user|>{message}<|assistant|>"
|
| 50 |
+
inputs = tokenizer(formatted, return_tensors="pt").to(device)
|
| 51 |
+
|
| 52 |
+
generated = []
|
| 53 |
+
input_ids = inputs["input_ids"]
|
| 54 |
+
|
| 55 |
+
for _ in range(max_tokens):
|
| 56 |
+
with torch.no_grad():
|
| 57 |
+
logits = model(input_ids).logits
|
| 58 |
+
probs = torch.softmax(logits[:, -1, :] / temperature, dim=-1)
|
| 59 |
+
next_token = torch.multinomial(probs, num_samples=1)
|
| 60 |
+
if next_token.item() == tokenizer.eos_token_id:
|
| 61 |
+
break
|
| 62 |
+
generated.append(next_token.item())
|
| 63 |
+
input_ids = torch.cat([input_ids, next_token], dim=-1)
|
| 64 |
+
|
| 65 |
+
return tokenizer.decode(generated, skip_special_tokens=True)
|
| 66 |
+
|
| 67 |
+
demo = gr.ChatInterface(
|
| 68 |
+
fn=chat,
|
| 69 |
+
title="ClokCEM - Customer Executive Model",
|
| 70 |
+
description="354M parameter model for enterprise customer support",
|
| 71 |
+
additional_inputs=[
|
| 72 |
+
gr.Slider(0.1, 2.0, value=0.6, step=0.1, label="Temperature"),
|
| 73 |
+
gr.Slider(50, 500, value=200, step=50, label="Max Tokens"),
|
| 74 |
+
],
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
demo.launch()
|
| 78 |
</gradio-file>
|
| 79 |
|
| 80 |
+
<gradio-file name="configuration_clokcem.py" url="https://huggingface.co/clokai/CLOK-CEM/resolve/main/configuration_clokcem.py" />
|
| 81 |
+
<gradio-file name="modeling_clokcem.py" url="https://huggingface.co/clokai/CLOK-CEM/resolve/main/modeling_clokcem.py" />
|
| 82 |
|
| 83 |
<gradio-requirements>
|
| 84 |
+
torch
|
| 85 |
+
transformers
|
| 86 |
+
safetensors
|
| 87 |
+
huggingface_hub
|
| 88 |
+
gradio
|
| 89 |
</gradio-requirements>
|
| 90 |
</gradio-lite>
|
| 91 |
</body>
|