ciphermosaic commited on
Commit
696e2b8
·
verified ·
1 Parent(s): 66b6f02

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -8
app.py CHANGED
@@ -2,12 +2,13 @@ import gradio as gr
2
  from llama_cpp import Llama
3
  from huggingface_hub import hf_hub_download
4
 
5
- # Load model
6
  model_path = hf_hub_download(
7
  repo_id="ciphermosaic/qwen-alpaca-gguf",
8
- filename="Qwen2.5-0.5B-Instruct.Q4_K_M.gguf"
9
  )
10
 
 
11
  llm = Llama(
12
  model_path=model_path,
13
  n_ctx=2048,
@@ -15,27 +16,37 @@ llm = Llama(
15
  verbose=False,
16
  )
17
 
 
18
  def chat(message, history):
19
  messages = []
20
 
21
- for user_msg, assistant_msg in history:
22
- messages.append({"role": "user", "content": user_msg})
23
- messages.append({"role": "assistant", "content": assistant_msg})
24
 
25
- messages.append({"role": "user", "content": message})
 
 
 
 
26
 
 
27
  response = llm.create_chat_completion(
28
- messages=messages
 
 
29
  )
30
 
31
  reply = response["choices"][0]["message"]["content"]
32
 
33
  return reply
34
 
 
35
  demo = gr.ChatInterface(
36
  fn=chat,
 
37
  title="🤖 Qwen Alpaca Chatbot",
38
- description="A fine-tuned Qwen 0.5B GGUF model running with llama.cpp"
39
  )
40
 
41
  demo.launch()
 
2
  from llama_cpp import Llama
3
  from huggingface_hub import hf_hub_download
4
 
5
+ # Download the GGUF model
6
  model_path = hf_hub_download(
7
  repo_id="ciphermosaic/qwen-alpaca-gguf",
8
+ filename="qwen-alpaca-q4_k_m.gguf"
9
  )
10
 
11
+ # Load the model
12
  llm = Llama(
13
  model_path=model_path,
14
  n_ctx=2048,
 
16
  verbose=False,
17
  )
18
 
19
+ # Chat function
20
  def chat(message, history):
21
  messages = []
22
 
23
+ # Add previous conversation
24
+ if history:
25
+ messages.extend(history)
26
 
27
+ # Add current user message
28
+ messages.append({
29
+ "role": "user",
30
+ "content": message
31
+ })
32
 
33
+ # Generate response
34
  response = llm.create_chat_completion(
35
+ messages=messages,
36
+ temperature=0.7,
37
+ max_tokens=256,
38
  )
39
 
40
  reply = response["choices"][0]["message"]["content"]
41
 
42
  return reply
43
 
44
+ # Gradio interface
45
  demo = gr.ChatInterface(
46
  fn=chat,
47
+ type="messages",
48
  title="🤖 Qwen Alpaca Chatbot",
49
+ description="A fine-tuned Qwen 0.5B GGUF model running with llama.cpp",
50
  )
51
 
52
  demo.launch()