Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
tokenizer = AutoTokenizer.from_pretrained("stabilityai/stable-code-3b")
|
| 4 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 5 |
+
"stabilityai/stable-code-3b",
|
| 6 |
+
torch_dtype="auto",
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
codeSnip = """
|
| 11 |
+
Is the following CSS code valid?
|
| 12 |
+
```
|
| 13 |
+
div {
|
| 14 |
+
color: red;
|
| 15 |
+
width: 100px;
|
| 16 |
+
}
|
| 17 |
+
```
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
inputs = tokenizer(codeSnip, return_tensors="pt")
|
| 21 |
+
|
| 22 |
+
tokens = model.generate(
|
| 23 |
+
**inputs,
|
| 24 |
+
max_new_tokens=48,
|
| 25 |
+
temperature=0.2,
|
| 26 |
+
do_sample=True,
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
res = tokenizer.decode(tokens[0], skip_special_tokens=True)
|
| 30 |
+
print(res)
|