Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,33 +8,21 @@ from huggingface_hub import snapshot_download
|
|
| 8 |
# Ensure your Hugging Face token is set
|
| 9 |
TOKEN = os.getenv('HF_TOKEN')
|
| 10 |
|
| 11 |
-
|
| 12 |
-
mistral_models_path = Path.home().joinpath('mistral_models', 'Meta-Llama-3.1-8B-Instruct')
|
| 13 |
-
mistral_models_path.mkdir(parents=True, exist_ok=True)
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
llama_model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=torch.bfloat16, device_map="auto")
|
| 23 |
-
llama_tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 24 |
|
| 25 |
# Define the respond function to generate test cases for a code solution
|
| 26 |
-
def respond(code_problem, code_solution, max_tokens
|
| 27 |
prompt = f"Generate test cases to test the following code solution:\n\nProblem:\n{code_problem}\n\nSolution:\n{code_solution}\n\nTest Cases:"
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
inputs["input_ids"],
|
| 31 |
-
max_new_tokens=max_tokens,
|
| 32 |
-
do_sample=True,
|
| 33 |
-
temperature=temperature,
|
| 34 |
-
top_p=top_p
|
| 35 |
-
)
|
| 36 |
-
result = llama_tokenizer.decode(generated_ids[0], skip_special_tokens=True)
|
| 37 |
-
return result
|
| 38 |
|
| 39 |
# Define Gradio interface
|
| 40 |
interface = gr.Interface(
|
|
@@ -43,8 +31,6 @@ interface = gr.Interface(
|
|
| 43 |
gr.Textbox(lines=10, placeholder="Describe the code problem here...", label="Code Problem"),
|
| 44 |
gr.Textbox(lines=10, placeholder="Provide the code solution here...", label="Code Solution"),
|
| 45 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 46 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 47 |
-
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
| 48 |
],
|
| 49 |
outputs=gr.Textbox(lines=20, label="Generated Test Cases"),
|
| 50 |
title="Code Test Case Generator",
|
|
|
|
| 8 |
# Ensure your Hugging Face token is set
|
| 9 |
TOKEN = os.getenv('HF_TOKEN')
|
| 10 |
|
| 11 |
+
model_id = "meta-llama/Meta-Llama-3.1-8B-Instruct"
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
pipeline = transformers.pipeline(
|
| 14 |
+
"text-generation",
|
| 15 |
+
model=model_id,
|
| 16 |
+
model_kwargs={"torch_dtype": torch.bfloat16},
|
| 17 |
+
device_map="auto",
|
| 18 |
+
token=TOKEN
|
| 19 |
+
)
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# Define the respond function to generate test cases for a code solution
|
| 22 |
+
def respond(code_problem, code_solution, max_tokens):
|
| 23 |
prompt = f"Generate test cases to test the following code solution:\n\nProblem:\n{code_problem}\n\nSolution:\n{code_solution}\n\nTest Cases:"
|
| 24 |
+
outputs = pipeline(prompt, max_new_tokens=max)
|
| 25 |
+
return outputs[0]["generated_text"][-1]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# Define Gradio interface
|
| 28 |
interface = gr.Interface(
|
|
|
|
| 31 |
gr.Textbox(lines=10, placeholder="Describe the code problem here...", label="Code Problem"),
|
| 32 |
gr.Textbox(lines=10, placeholder="Provide the code solution here...", label="Code Solution"),
|
| 33 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
|
|
|
|
|
|
| 34 |
],
|
| 35 |
outputs=gr.Textbox(lines=20, label="Generated Test Cases"),
|
| 36 |
title="Code Test Case Generator",
|