Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,19 +2,23 @@ import torch
|
|
2 |
import gradio as gr
|
3 |
from transformers import AutoTokenizer, AutoModelForCausalLM, set_seed, pipeline
|
4 |
|
5 |
-
device =
|
6 |
|
7 |
title = "Santacoder 🎅 bash/shell 🐚 Completion"
|
8 |
description = "This is a subspace to make code generation with [SantaCoder fine-tuned on The Stack bash/shell](https://huggingface.co/mrm8488/santacoder-finetuned-the-stack-bash-4)"
|
9 |
EXAMPLE_0 = "#!/bin/bash\n# This script removes files larger than 2MB in the current folder\nfind ."
|
10 |
-
|
|
|
|
|
|
|
|
|
11 |
tokenizer = AutoTokenizer.from_pretrained("mrm8488/santacoder-finetuned-the-stack-bash-4")
|
12 |
model = AutoModelForCausalLM.from_pretrained("mrm8488/santacoder-finetuned-the-stack-bash-4", trust_remote_code=True).to(device)
|
13 |
|
14 |
|
15 |
def code_generation(gen_prompt, max_tokens, temperature=0.6, seed=42):
|
16 |
set_seed(seed)
|
17 |
-
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
18 |
generated_text = pipe(gen_prompt, do_sample=True, top_p=0.95, temperature=temperature, max_new_tokens=max_tokens)[0]['generated_text']
|
19 |
return generated_text
|
20 |
|
|
|
2 |
import gradio as gr
|
3 |
from transformers import AutoTokenizer, AutoModelForCausalLM, set_seed, pipeline
|
4 |
|
5 |
+
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
6 |
|
7 |
title = "Santacoder 🎅 bash/shell 🐚 Completion"
|
8 |
description = "This is a subspace to make code generation with [SantaCoder fine-tuned on The Stack bash/shell](https://huggingface.co/mrm8488/santacoder-finetuned-the-stack-bash-4)"
|
9 |
EXAMPLE_0 = "#!/bin/bash\n# This script removes files larger than 2MB in the current folder\nfind ."
|
10 |
+
EXAMPLE_1 = "#!/bin/bash\n\n# This script send an email\nto=”admin@example.com”\nsubject=”Greeting”\nmsg=”Welcome to our site”\n"
|
11 |
+
EXAMPLE_3 = "#!/bin/bash\n# This script convert avi files to mp4\nfor filename in $(ls *.avi); do\n"
|
12 |
+
EXAMPLE_4 = "#!/bin/bash\nsource=$1\ndest=$2\n"
|
13 |
+
|
14 |
+
examples = [[EXAMPLE_0, 14, 0.6, 42], [EXAMPLE_1, 28, 0.6, 42], [EXAMPLE_3, 46, 0.6, 42], [EXAMPLE_4, 46, 0.6, 43]]
|
15 |
tokenizer = AutoTokenizer.from_pretrained("mrm8488/santacoder-finetuned-the-stack-bash-4")
|
16 |
model = AutoModelForCausalLM.from_pretrained("mrm8488/santacoder-finetuned-the-stack-bash-4", trust_remote_code=True).to(device)
|
17 |
|
18 |
|
19 |
def code_generation(gen_prompt, max_tokens, temperature=0.6, seed=42):
|
20 |
set_seed(seed)
|
21 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, device=device)
|
22 |
generated_text = pipe(gen_prompt, do_sample=True, top_p=0.95, temperature=temperature, max_new_tokens=max_tokens)[0]['generated_text']
|
23 |
return generated_text
|
24 |
|