Spaces:
Sleeping
Sleeping
Leetmonkey In Action. Darn LeetMonkey these days
Browse files
app.py
CHANGED
@@ -89,27 +89,41 @@ def extract_and_format_code(text):
|
|
89 |
dataset = load_dataset("sugiv/leetmonkey_python_dataset")
|
90 |
val_dataset = dataset["train"].train_test_split(test_size=0.1)["test"]
|
91 |
|
92 |
-
def gradio_interface(
|
93 |
-
|
94 |
sample = random.choice(val_dataset)
|
95 |
instruction = sample['instruction']
|
96 |
original_output = sample['output']
|
97 |
|
|
|
98 |
generated_output = generate_solution(instruction, model)
|
99 |
python_code = extract_and_format_code(generated_output)
|
100 |
|
101 |
-
return instruction, python_code, original_output
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
gr.
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
)
|
114 |
-
|
115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
dataset = load_dataset("sugiv/leetmonkey_python_dataset")
|
90 |
val_dataset = dataset["train"].train_test_split(test_size=0.1)["test"]
|
91 |
|
92 |
+
def gradio_interface(btn):
|
93 |
+
model_name = gr.Dropdown.update(choices=list(gguf_models.keys()), label="Select GGUF Model")
|
94 |
sample = random.choice(val_dataset)
|
95 |
instruction = sample['instruction']
|
96 |
original_output = sample['output']
|
97 |
|
98 |
+
model = load_model(gguf_models[model_name])
|
99 |
generated_output = generate_solution(instruction, model)
|
100 |
python_code = extract_and_format_code(generated_output)
|
101 |
|
102 |
+
return instruction, python_code, original_output, model_name
|
103 |
+
|
104 |
+
with gr.Blocks() as demo:
|
105 |
+
gr.Markdown("# LeetMonkey Problem Solver")
|
106 |
+
|
107 |
+
with gr.Row():
|
108 |
+
with gr.Column():
|
109 |
+
problem_display = gr.Textbox(label="LeetCode Problem", lines=10)
|
110 |
+
select_problem_btn = gr.Button("Select Random Problem")
|
111 |
+
|
112 |
+
with gr.Column():
|
113 |
+
model_dropdown = gr.Dropdown(choices=list(gguf_models.keys()), label="Select GGUF Model", value="Exact Copy")
|
114 |
+
solution_display = gr.Code(label="Generated Solution", language="python")
|
115 |
+
original_solution_display = gr.Code(label="Original Solution", language="python")
|
116 |
+
generate_btn = gr.Button("Generate Solution")
|
117 |
+
|
118 |
+
select_problem_btn.click(
|
119 |
+
lambda: random.choice(val_dataset)['instruction'],
|
120 |
+
outputs=problem_display
|
121 |
+
)
|
122 |
+
|
123 |
+
generate_btn.click(
|
124 |
+
gradio_interface,
|
125 |
+
inputs=[model_dropdown, problem_display],
|
126 |
+
outputs=[problem_display, solution_display, original_solution_display, model_dropdown]
|
127 |
+
)
|
128 |
+
|
129 |
+
demo.launch(share=True)
|