Create realityAI-Assgn
Browse files- realityAI-Assgn +22 -0
realityAI-Assgn
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pip install transformers
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
import torch
|
4 |
+
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("OpenAssistant/falcon-7b-sft-mix-2000")
|
6 |
+
model = AutoModelForCausalLM.from_pretrained("OpenAssistant/falcon-7b-sft-mix-2000")
|
7 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
8 |
+
model.to(device)
|
9 |
+
while True:
|
10 |
+
user_input = input("User: ")
|
11 |
+
if user_input.lower() == "exit":
|
12 |
+
break
|
13 |
+
|
14 |
+
input_text = f"User: {user_input}\nAssistant: "
|
15 |
+
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
16 |
+
input_ids = input_ids.to(device)
|
17 |
+
|
18 |
+
with torch.no_grad():
|
19 |
+
output_ids = model.generate(input_ids, max_length=100, num_return_sequences=1)
|
20 |
+
|
21 |
+
response = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
22 |
+
print("Assistant:", response)
|