Spaces:
Runtime error
Runtime error
Update getans.py
Browse files
getans.py
CHANGED
@@ -1,14 +1,15 @@
|
|
1 |
-
import torch
|
2 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
-
|
4 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
5 |
-
|
6 |
-
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-chat-hf")
|
7 |
-
model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-2-7b-chat-hf")
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
1 |
+
import torch
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
|
4 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
5 |
+
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-chat-hf")
|
7 |
+
model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-2-7b-chat-hf")
|
8 |
+
|
9 |
+
model.to(device)
|
10 |
+
|
11 |
+
def get_response(prompt, max_new_tokens=50):
|
12 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
13 |
+
outputs = model.generate(**inputs, max_new_tokens=max_new_tokens, temperature=0.0001, do_sample=True)
|
14 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True) # Use indexing instead of calling
|
15 |
+
return response
|