Spaces:
Runtime error
Runtime error
Update src/demo.py
Browse files- src/demo.py +14 -2
src/demo.py
CHANGED
@@ -27,8 +27,20 @@ model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16
|
|
27 |
# type2dataset = {}
|
28 |
|
29 |
|
30 |
-
def generate():
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
|
34 |
def random_examples(dataset_key) -> str:
|
|
|
27 |
# type2dataset = {}
|
28 |
|
29 |
|
30 |
+
def generate(input_text, sys_prompt) -> str:
|
31 |
+
sys_prompt = f'''[INST] <<SYS>>
|
32 |
+
{sys_prompt}
|
33 |
+
<</SYS>>
|
34 |
+
|
35 |
+
'''
|
36 |
+
input_str = sys_prompt + input_text + " [/INST]"
|
37 |
+
|
38 |
+
input_ids = tokenizer(input_str, return_tensors="pt").input_ids
|
39 |
+
outputs = model.generate(input_ids, max_length=512)
|
40 |
+
|
41 |
+
result = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
|
42 |
+
|
43 |
+
return result
|
44 |
|
45 |
|
46 |
def random_examples(dataset_key) -> str:
|