Spaces:
Sleeping
Sleeping
Leetmonkey In Action. Darn LeetMonkey these days
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ import random
|
|
7 |
import logging
|
8 |
import os
|
9 |
import autopep8
|
|
|
10 |
|
11 |
# Set up logging
|
12 |
logging.basicConfig(level=logging.INFO)
|
@@ -14,7 +15,7 @@ logger = logging.getLogger(__name__)
|
|
14 |
|
15 |
# Define the model options
|
16 |
gguf_models = {
|
17 |
-
"Q8_0": "leetmonkey_peft__q8_0.gguf",
|
18 |
"Exact Copy": "leetmonkey_peft_exact_copy.gguf",
|
19 |
"F16": "leetmonkey_peft_f16.gguf",
|
20 |
"Super Block Q6": "leetmonkey_peft_super_block_q6.gguf"
|
@@ -32,10 +33,8 @@ def download_model(model_name):
|
|
32 |
logger.info(f"Model downloaded: {model_path}")
|
33 |
return model_path
|
34 |
|
35 |
-
# Download the 8-bit model at startup
|
36 |
-
q8_model_path = download_model(gguf_models["Q8_0"])
|
37 |
-
|
38 |
-
# Load the 8-bit model
|
39 |
llm = Llama(
|
40 |
model_path=q8_model_path,
|
41 |
n_ctx=2048,
|
@@ -43,12 +42,11 @@ llm = Llama(
|
|
43 |
n_gpu_layers=0,
|
44 |
verbose=False
|
45 |
)
|
46 |
-
|
47 |
logger.info("8-bit model loaded successfully")
|
48 |
|
49 |
# Load the dataset
|
50 |
dataset = load_dataset("sugiv/leetmonkey_python_dataset")
|
51 |
-
|
52 |
|
53 |
# Generation parameters
|
54 |
generation_kwargs = {
|
@@ -114,13 +112,18 @@ def extract_and_format_code(text):
|
|
114 |
except:
|
115 |
return formatted_code
|
116 |
|
117 |
-
def
|
118 |
-
|
119 |
-
return sample['instruction']
|
120 |
|
121 |
-
def update_solution(problem):
|
122 |
-
|
123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
formatted_code = extract_and_format_code(generated_output)
|
125 |
logger.info("Solution generated successfully")
|
126 |
return formatted_code
|
@@ -134,12 +137,13 @@ with gr.Blocks() as demo:
|
|
134 |
select_problem_btn = gr.Button("Select Random Problem")
|
135 |
|
136 |
with gr.Column():
|
|
|
137 |
solution_display = gr.Code(label="Generated Solution", language="python", lines=25)
|
138 |
generate_btn = gr.Button("Generate Solution")
|
139 |
|
140 |
-
select_problem_btn.click(
|
141 |
-
generate_btn.click(update_solution, inputs=[problem_display], outputs=solution_display)
|
142 |
|
143 |
if __name__ == "__main__":
|
144 |
logger.info("Starting Gradio interface")
|
145 |
-
demo.launch(share=True)
|
|
|
7 |
import logging
|
8 |
import os
|
9 |
import autopep8
|
10 |
+
import textwrap
|
11 |
|
12 |
# Set up logging
|
13 |
logging.basicConfig(level=logging.INFO)
|
|
|
15 |
|
16 |
# Define the model options
|
17 |
gguf_models = {
|
18 |
+
"Q8_0 (8-bit)": "leetmonkey_peft__q8_0.gguf",
|
19 |
"Exact Copy": "leetmonkey_peft_exact_copy.gguf",
|
20 |
"F16": "leetmonkey_peft_f16.gguf",
|
21 |
"Super Block Q6": "leetmonkey_peft_super_block_q6.gguf"
|
|
|
33 |
logger.info(f"Model downloaded: {model_path}")
|
34 |
return model_path
|
35 |
|
36 |
+
# Download and load the 8-bit model at startup
|
37 |
+
q8_model_path = download_model(gguf_models["Q8_0 (8-bit)"])
|
|
|
|
|
38 |
llm = Llama(
|
39 |
model_path=q8_model_path,
|
40 |
n_ctx=2048,
|
|
|
42 |
n_gpu_layers=0,
|
43 |
verbose=False
|
44 |
)
|
|
|
45 |
logger.info("8-bit model loaded successfully")
|
46 |
|
47 |
# Load the dataset
|
48 |
dataset = load_dataset("sugiv/leetmonkey_python_dataset")
|
49 |
+
train_dataset = dataset["train"]
|
50 |
|
51 |
# Generation parameters
|
52 |
generation_kwargs = {
|
|
|
112 |
except:
|
113 |
return formatted_code
|
114 |
|
115 |
+
def select_random_problem():
|
116 |
+
return random.choice(train_dataset)['instruction']
|
|
|
117 |
|
118 |
+
def update_solution(problem, model_name):
|
119 |
+
if model_name == "Q8_0 (8-bit)":
|
120 |
+
model = llm
|
121 |
+
else:
|
122 |
+
model_path = download_model(gguf_models[model_name])
|
123 |
+
model = Llama(model_path=model_path, n_ctx=2048, n_threads=4, n_gpu_layers=0, verbose=False)
|
124 |
+
|
125 |
+
logger.info(f"Generating solution using {model_name} model")
|
126 |
+
generated_output = generate_solution(problem, model)
|
127 |
formatted_code = extract_and_format_code(generated_output)
|
128 |
logger.info("Solution generated successfully")
|
129 |
return formatted_code
|
|
|
137 |
select_problem_btn = gr.Button("Select Random Problem")
|
138 |
|
139 |
with gr.Column():
|
140 |
+
model_dropdown = gr.Dropdown(choices=list(gguf_models.keys()), label="Select GGUF Model", value="Q8_0 (8-bit)")
|
141 |
solution_display = gr.Code(label="Generated Solution", language="python", lines=25)
|
142 |
generate_btn = gr.Button("Generate Solution")
|
143 |
|
144 |
+
select_problem_btn.click(select_random_problem, outputs=problem_display)
|
145 |
+
generate_btn.click(update_solution, inputs=[problem_display, model_dropdown], outputs=solution_display)
|
146 |
|
147 |
if __name__ == "__main__":
|
148 |
logger.info("Starting Gradio interface")
|
149 |
+
demo.launch(share=True)
|