launch-calcium commited on
Commit
9ac15f3
·
verified ·
1 Parent(s): df06e88

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -22,7 +22,7 @@ tokenizer = AutoTokenizer.from_pretrained(
22
  print(f"[startup] Loading model {MODEL_ID}...", flush=True)
23
  model = AutoModelForCausalLM.from_pretrained(
24
  MODEL_ID,
25
- torch_dtype=torch.float32,
26
  device_map="cpu",
27
  low_cpu_mem_usage=True,
28
  trust_remote_code=True,
@@ -34,7 +34,7 @@ print("[startup] Model loaded successfully!", flush=True)
34
 
35
  def chat_response(
36
  message: str,
37
- history: list[dict[str, str]],
38
  system_prompt: str,
39
  temperature: float,
40
  top_p: float,
@@ -45,8 +45,11 @@ def chat_response(
45
  if system_prompt.strip():
46
  messages.append({"role": "system", "content": system_prompt})
47
 
48
- for item in history:
49
- messages.append(item)
 
 
 
50
 
51
  messages.append({"role": "user", "content": message})
52
 
@@ -93,7 +96,6 @@ def chat_response(
93
 
94
  demo = gr.ChatInterface(
95
  fn=chat_response,
96
- type="messages",
97
  title="K2-Horizon-0.9B Chat Demo",
98
  description="Interactive demo for [IFM/K2-Horizon-0.9B](https://huggingface.co/IFM/K2-Horizon-0.9B) using PyTorch and Transformers on CPU.",
99
  additional_inputs=[
 
22
  print(f"[startup] Loading model {MODEL_ID}...", flush=True)
23
  model = AutoModelForCausalLM.from_pretrained(
24
  MODEL_ID,
25
+ dtype=torch.float32,
26
  device_map="cpu",
27
  low_cpu_mem_usage=True,
28
  trust_remote_code=True,
 
34
 
35
  def chat_response(
36
  message: str,
37
+ history: list[list[str]],
38
  system_prompt: str,
39
  temperature: float,
40
  top_p: float,
 
45
  if system_prompt.strip():
46
  messages.append({"role": "system", "content": system_prompt})
47
 
48
+ for user_msg, assistant_msg in history:
49
+ if user_msg:
50
+ messages.append({"role": "user", "content": user_msg})
51
+ if assistant_msg:
52
+ messages.append({"role": "assistant", "content": assistant_msg})
53
 
54
  messages.append({"role": "user", "content": message})
55
 
 
96
 
97
  demo = gr.ChatInterface(
98
  fn=chat_response,
 
99
  title="K2-Horizon-0.9B Chat Demo",
100
  description="Interactive demo for [IFM/K2-Horizon-0.9B](https://huggingface.co/IFM/K2-Horizon-0.9B) using PyTorch and Transformers on CPU.",
101
  additional_inputs=[