Spaces:
Runtime error
Runtime error
Update getans.py
Browse files
getans.py
CHANGED
@@ -1,20 +1,19 @@
|
|
1 |
-
from mmap import mmap
|
2 |
-
|
3 |
-
import torch
|
4 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
5 |
-
from huggingface_hub import login
|
6 |
-
token1="hf_"
|
7 |
-
token2="
|
8 |
-
login(token=token1+token2)
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
response
|
19 |
-
ans
|
20 |
-
return ans
|
|
|
1 |
+
from mmap import mmap
|
2 |
+
|
3 |
+
import torch
|
4 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
5 |
+
from huggingface_hub import login
|
6 |
+
token1="hf_"
|
7 |
+
token2="vWSzjVPShXPbgmylDJduWwHinTfHNqZVpj"
|
8 |
+
login(token=token1+token2,add_to_git_credential=True)
|
9 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
10 |
+
mm="finetuning/output/pytorch_model.bin"
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained(mm)
|
12 |
+
model = AutoModelForCausalLM.from_pretrained(mm)
|
13 |
+
|
14 |
+
def get_response(prompt, max_new_tokens=50):
|
15 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
16 |
+
outputs = model.generate(**inputs, max_new_tokens=max_new_tokens, temperature=0.0001, do_sample=True)
|
17 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True) # Use indexing instead of calling
|
18 |
+
ans=response.toString()
|
19 |
+
return ans
|
|