ghosthets commited on
Commit
2208ddd
·
verified ·
1 Parent(s): ef62fc5

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +0 -2
  2. app.py +15 -22
  3. requirements.txt +1 -2
README.md CHANGED
@@ -4,9 +4,7 @@ emoji: 🤖
4
  colorFrom: blue
5
  colorTo: purple
6
  sdk: gradio
7
- sdk_version: 4.44.0
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
11
- hardware: zero-gpu
12
  ---
 
4
  colorFrom: blue
5
  colorTo: purple
6
  sdk: gradio
 
7
  app_file: app.py
8
  pinned: false
9
  license: apache-2.0
 
10
  ---
app.py CHANGED
@@ -1,37 +1,30 @@
1
- import spaces
2
  import torch
3
  import gradio as gr
4
  from huggingface_hub import hf_hub_download
5
  from safetensors.torch import load_file
6
 
7
  MODEL_REPO = "ClokAI/ci-base"
 
8
 
9
- @spaces.GPU
10
- def load_model():
11
- from clokai import CiModel, CiConfig
12
- from transformers import AutoTokenizer
13
-
14
- config = CiConfig()
15
- model = CiModel(config)
16
-
17
- weights_path = hf_hub_download(repo_id=MODEL_REPO, filename="model.safetensors")
18
- sd = load_file(weights_path)
19
- model.load_state_dict(sd, strict=False)
20
- model.eval()
21
-
22
- tokenizer = AutoTokenizer.from_pretrained(MODEL_REPO)
23
- return model, tokenizer
24
 
25
- print("Loading model...")
26
- model, tokenizer = load_model()
 
 
 
 
 
 
 
27
  print("Model ready!")
28
 
29
- @spaces.GPU
30
  def chat(message, history, temperature, max_tokens):
31
- device = next(model.parameters()).device
32
-
33
  formatted = f"<s> User: {message} Assistant:"
34
- inputs = tokenizer(formatted, return_tensors="pt").to(device)
35
 
36
  generated = []
37
  input_ids = inputs["input_ids"]
 
 
1
  import torch
2
  import gradio as gr
3
  from huggingface_hub import hf_hub_download
4
  from safetensors.torch import load_file
5
 
6
  MODEL_REPO = "ClokAI/ci-base"
7
+ DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
8
 
9
+ print(f"Loading model on {DEVICE}...")
10
+
11
+ from clokai import CiModel, CiConfig
12
+ from transformers import AutoTokenizer
 
 
 
 
 
 
 
 
 
 
 
13
 
14
+ config = CiConfig()
15
+ model = CiModel(config).to(DEVICE)
16
+
17
+ weights_path = hf_hub_download(repo_id=MODEL_REPO, filename="model.safetensors")
18
+ sd = load_file(weights_path)
19
+ model.load_state_dict(sd, strict=False)
20
+ model.eval()
21
+
22
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_REPO)
23
  print("Model ready!")
24
 
 
25
  def chat(message, history, temperature, max_tokens):
 
 
26
  formatted = f"<s> User: {message} Assistant:"
27
+ inputs = tokenizer(formatted, return_tensors="pt").to(DEVICE)
28
 
29
  generated = []
30
  input_ids = inputs["input_ids"]
requirements.txt CHANGED
@@ -2,6 +2,5 @@ torch>=2.0.0
2
  transformers>=4.35.0
3
  safetensors>=0.4.0
4
  huggingface_hub>=0.20.0
5
- gradio>=4.44.0
6
  clokai>=1.1.1
7
- spaces>=0.30.0
 
2
  transformers>=4.35.0
3
  safetensors>=0.4.0
4
  huggingface_hub>=0.20.0
5
+ gradio>=4.0.0
6
  clokai>=1.1.1