Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,8 @@ model_name = "CreitinGameplays/bloom-3b-conversational"
|
|
8 |
# Load tokenizer and model
|
9 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
10 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
|
|
|
|
11 |
|
12 |
def generate_text(user_prompt):
|
13 |
"""Generates text using the BLOOM model from Hugging Face Transformers and removes the user prompt."""
|
@@ -15,7 +17,7 @@ def generate_text(user_prompt):
|
|
15 |
prompt = f"<|system|> You are a helpful AI assistant. </s> <|prompter|> {user_prompt} </s> <|assistant|>"
|
16 |
|
17 |
# Encode the entire prompt into tokens
|
18 |
-
prompt_encoded = tokenizer(prompt, return_tensors="pt").
|
19 |
|
20 |
# Generate text with the complete prompt and limit the maximum length to 256 tokens
|
21 |
output = model.generate(
|
|
|
8 |
# Load tokenizer and model
|
9 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
10 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
11 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
12 |
+
model.to(device)
|
13 |
|
14 |
def generate_text(user_prompt):
|
15 |
"""Generates text using the BLOOM model from Hugging Face Transformers and removes the user prompt."""
|
|
|
17 |
prompt = f"<|system|> You are a helpful AI assistant. </s> <|prompter|> {user_prompt} </s> <|assistant|>"
|
18 |
|
19 |
# Encode the entire prompt into tokens
|
20 |
+
prompt_encoded = tokenizer.encode(prompt, return_tensors="pt").to(device)
|
21 |
|
22 |
# Generate text with the complete prompt and limit the maximum length to 256 tokens
|
23 |
output = model.generate(
|