Spaces:
Runtime error
Runtime error
Update app.py
Browse fileschanged model to llama 7b
app.py
CHANGED
@@ -1,26 +1,29 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
import torch
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
-
model = AutoModelForCausalLM.from_pretrained(model_name).to("cpu")
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
15 |
|
16 |
-
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
outputs=gr.Textbox(label="Generated Manim Code"),
|
22 |
-
title="π¬ Manim Code Generator",
|
23 |
-
description=description
|
24 |
-
)
|
25 |
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from llama_cpp import Llama
|
|
|
3 |
|
4 |
+
# Path to model (downloaded automatically from HF hub)
|
5 |
+
MODEL_PATH = "TheBloke/CodeLlama-7B-Instruct-GGUF"
|
|
|
|
|
6 |
|
7 |
+
# Load LLM (first time takes time)
|
8 |
+
llm = Llama.from_pretrained(
|
9 |
+
repo_id=MODEL_PATH,
|
10 |
+
filename="codellama-7b-instruct.Q4_K_M.gguf", # 4-bit quantized version
|
11 |
+
n_ctx=2048,
|
12 |
+
verbose=True
|
13 |
+
)
|
14 |
|
15 |
+
# Prompt wrapper
|
16 |
+
def build_prompt(user_prompt):
|
17 |
+
return f"[INST] Write Python code using the Manim library: {user_prompt} [/INST]"
|
18 |
|
19 |
+
def generate_code(prompt):
|
20 |
+
result = llm(build_prompt(prompt), max_tokens=512, temperature=0.7, stop=["</s>"])
|
21 |
+
return result["choices"][0]["text"]
|
|
|
|
|
|
|
|
|
22 |
|
23 |
+
gr.Interface(
|
24 |
+
fn=generate_code,
|
25 |
+
inputs=gr.Textbox(label="Prompt", placeholder="e.g., Animate a bouncing ball in Manim"),
|
26 |
+
outputs=gr.Textbox(label="Generated Python Code"),
|
27 |
+
title="π Manim Code Generator - Code Llama 7B",
|
28 |
+
description="Powered by llama-cpp and Code Llama 7B (Quantized). Runs on CPU!"
|
29 |
+
).launch()
|