Tapash250 commited on
Commit
d788890
·
verified ·
1 Parent(s): e0c75ee

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +10 -8
  2. app.py +57 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,13 +1,15 @@
1
  ---
2
- title: K2 Horizon Demo
3
- emoji: 🐢
4
- colorFrom: pink
5
- colorTo: gray
6
  sdk: gradio
7
- sdk_version: 6.26.0
8
- python_version: '3.12'
9
  app_file: app.py
10
- pinned: false
 
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
1
  ---
2
+ title: K2-Horizon-0.9B-GGUF Demo
3
+ emoji: 🧠
4
+ colorFrom: blue
5
+ colorTo: purple
6
  sdk: gradio
7
+ sdk_version: 5.50.0
 
8
  app_file: app.py
9
+ short_description: Chat with K2-Horizon 0.9B GGUF model
10
+ python_version: "3.12"
11
  ---
12
 
13
+ # K2-Horizon-0.9B-GGUF Demo
14
+
15
+ A Gradio demo for the [IFM/K2-Horizon-0.9B-GGUF](https://huggingface.co/IFM/K2-Horizon-0.9B-GGUF) model — a compact 0.9B reasoning model supporting English and Chinese.
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import spaces
2
+ import torch
3
+ import gradio as gr
4
+ from transformers import AutoModelForCausalLM, AutoTokenizer
5
+
6
+ MODEL_ID = "IFM/K2-Horizon-0.9B-GGUF"
7
+
8
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
9
+ model = AutoModelForCausalLM.from_pretrained(
10
+ MODEL_ID,
11
+ torch_dtype=torch.float16,
12
+ device_map="auto",
13
+ trust_remote_code=True,
14
+ )
15
+
16
+
17
+ @spaces.GPU(duration=60)
18
+ def generate(message, history):
19
+ """Generate a response from the K2-Horizon model."""
20
+ messages = []
21
+ for user_msg, bot_msg in history:
22
+ messages.append({"role": "user", "content": user_msg})
23
+ messages.append({"role": "assistant", "content": bot_msg})
24
+ messages.append({"role": "user", "content": message})
25
+
26
+ inputs = tokenizer.apply_chat_template(
27
+ messages, tokenize=True, add_generation_prompt=True, return_tensors="pt"
28
+ ).to(model.device)
29
+
30
+ with torch.no_grad():
31
+ outputs = model.generate(
32
+ inputs,
33
+ max_new_tokens=1024,
34
+ temperature=0.7,
35
+ top_p=0.9,
36
+ do_sample=True,
37
+ )
38
+
39
+ response = tokenizer.decode(outputs[0][inputs.shape[1] :], skip_special_tokens=True)
40
+ return response
41
+
42
+
43
+ demo = gr.ChatInterface(
44
+ fn=generate,
45
+ title="K2-Horizon-0.9B-GGUF",
46
+ description="Chat with the K2-Horizon 0.9B reasoning model (GGUF quantized).",
47
+ examples=[
48
+ ["Who are you?"],
49
+ ["What is 84 * 3 / 2?"],
50
+ ["Tell me an interesting fact about the universe!"],
51
+ ["Explain quantum computing in simple terms."],
52
+ ],
53
+ cache_examples=True,
54
+ )
55
+
56
+ if __name__ == "__main__":
57
+ demo.launch(mcp_server=True)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ accelerate
3
+ sentencepiece