Updated for code responses
Browse files
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/
|
| 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
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
messages.append({"role": "assistant", "content": assistant})
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
output = llm.create_chat_completion(
|
| 34 |
messages=messages,
|
| 35 |
-
max_tokens=
|
| 36 |
temperature=0.2,
|
| 37 |
top_p=0.5
|
| 38 |
)
|
| 39 |
|
| 40 |
-
|
| 41 |
-
return reply
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
| 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 |
|