astegaras commited on
Commit
805934c
·
verified ·
1 Parent(s): 2fb80ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -27
app.py CHANGED
@@ -2,55 +2,42 @@ import gradio as gr
2
  from llama_cpp import Llama
3
  from huggingface_hub import hf_hub_download
4
 
5
- # Download GGUF from your HF repo
6
  model_path = hf_hub_download(
7
  repo_id="astegaras/Llama3.2_3B",
8
- filename="model-Q2_K.gguf"
9
  )
10
 
11
- # Load model (llama.cpp)
12
  llm = Llama(
13
  model_path=model_path,
14
  n_ctx=4096,
15
- chat_format=None,
16
  n_gpu_layers=0,
 
17
  add_bos_token=False,
18
  add_eos_token=False,
19
  )
20
 
21
- # Build inference prompt according to your dataset format
22
- def format_prompt(user_message):
23
- return (
24
- "<|begin_of_text|>"
25
- "<|start_header_id|>system<|end_header_id|>\n"
26
- "You are a helpful assistant.\n"
27
- "<|start_header_id|>user<|end_header_id|>\n"
28
- f"{user_message}\n"
29
- "<|start_header_id|>assistant<|end_header_id|>\n"
30
- )
31
-
32
-
33
  def respond(user_input):
34
- prompt = format_prompt(user_input)
35
-
36
  output = llm(
37
- prompt,
38
- max_tokens=512,
39
  temperature=0.7,
40
  top_p=0.9,
41
- stop=["<|user|>", "<|system|>"], # avoid looping
42
  )
 
 
43
 
44
- return output["choices"][0]["text"]
45
-
46
- # Gradio UI
47
  gr.Interface(
48
  fn=respond,
49
- inputs=gr.components.Textbox(label="Ask"),
50
- outputs=gr.components.Textbox(label="Answer"),
51
- title="Llama3.2-3B Fine-tuned Assistant"
52
  ).launch()
53
 
54
 
55
 
56
 
 
 
2
  from llama_cpp import Llama
3
  from huggingface_hub import hf_hub_download
4
 
5
+ # Download GGUF file from HuggingFace
6
  model_path = hf_hub_download(
7
  repo_id="astegaras/Llama3.2_3B",
8
+ filename="model-Q2_K.gguf",
9
  )
10
 
11
+ # Load model
12
  llm = Llama(
13
  model_path=model_path,
14
  n_ctx=4096,
 
15
  n_gpu_layers=0,
16
+ chat_format=None,
17
  add_bos_token=False,
18
  add_eos_token=False,
19
  )
20
 
21
+ # EXACT SAME BEHAVIOR AS mlx_lm.generate
 
 
 
 
 
 
 
 
 
 
 
22
  def respond(user_input):
 
 
23
  output = llm(
24
+ user_input, # <-- only this!
25
+ max_tokens=256,
26
  temperature=0.7,
27
  top_p=0.9,
28
+ stop=None,
29
  )
30
+
31
+ return output["choices"][0]["text"].strip()
32
 
 
 
 
33
  gr.Interface(
34
  fn=respond,
35
+ inputs="text",
36
+ outputs="text",
37
+ title="Llama3.2-3B Fine-tuned Model"
38
  ).launch()
39
 
40
 
41
 
42
 
43
+