astegaras commited on
Commit
1f2ea00
·
verified ·
1 Parent(s): bbe2c8f

Updated for code responses

Browse files
Files changed (1) hide show
  1. app.py +37 -20
app.py CHANGED
@@ -4,7 +4,7 @@ from huggingface_hub import hf_hub_download
4
 
5
  # Download your GGUF model from HF Hub
6
  model_path = hf_hub_download(
7
- repo_id="astegaras/lora_merged",
8
  filename="llama-3.2-3b-instruct.Q2_K.gguf"
9
  )
10
 
@@ -21,33 +21,50 @@ llm = Llama(
21
  verbose=False
22
  )
23
 
24
- def chat_fn(message, history):
25
- # Reformat history for llama.cpp chat template
26
- messages = []
27
- for user, assistant in history:
28
- messages.append({"role": "user", "content": user})
29
- messages.append({"role": "assistant", "content": assistant})
30
 
31
- messages.append({"role": "user", "content": message})
32
-
33
- output = llm.create_chat_completion(
34
  messages=messages,
35
- max_tokens=256,
36
  temperature=0.2,
37
  top_p=0.5
38
  )
39
 
40
- reply = output["choices"][0]["message"]["content"]
41
- return reply
42
 
 
 
 
 
 
 
43
 
44
- # Gradio UI
45
- chatbot = gr.ChatInterface(
46
- fn=chat_fn,
47
- title="Merged Kaggle Model (GGUF)",
48
- description="Running llama.cpp inference on GGUF model",
49
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
- chatbot.launch()
52
 
53
 
 
4
 
5
  # Download your GGUF model from HF Hub
6
  model_path = hf_hub_download(
7
+ repo_id="astegaras/lora_python_converter",
8
  filename="llama-3.2-3b-instruct.Q2_K.gguf"
9
  )
10
 
 
21
  verbose=False
22
  )
23
 
24
+ def generate_code(instruction):
25
+ messages = [
26
+ {"role": "system", "content": "You are a Python code generator. Return only code."},
27
+ {"role": "user", "content": instruction},
28
+ ]
 
29
 
30
+ out = llm.create_chat_completion(
 
 
31
  messages=messages,
32
+ max_tokens=512,
33
  temperature=0.2,
34
  top_p=0.5
35
  )
36
 
37
+ return out["choices"][0]["message"]["content"]
 
38
 
39
+ # ---- GRADIO UI ----
40
+ with gr.Blocks(theme="gradio/soft") as demo:
41
+ gr.Markdown(
42
+ """
43
+ # Python Code Generator
44
+ Enter a task in plain English and receive executable Python code.
45
 
46
+ Example:
47
+ *"Help me set up my to-do list"*
48
+ """
49
+ )
50
+
51
+ with gr.Row():
52
+ with gr.Column(scale=1):
53
+ instruction = gr.Textbox(
54
+ label="Describe what you want to build",
55
+ placeholder="Example: Help me set up my to-do list",
56
+ lines=3,
57
+ )
58
+ submit = gr.Button("Generate Python Code", variant="primary")
59
+
60
+ with gr.Column(scale=1):
61
+ code_output = gr.Code(
62
+ label="Generated Python Code",
63
+ language="python"
64
+ )
65
+
66
+ submit.click(fn=generate_code, inputs=instruction, outputs=code_output)
67
 
68
+ demo.launch()
69
 
70