Update README.md
Browse files
README.md
CHANGED
|
@@ -33,23 +33,30 @@ Context Length 2048 tokens
|
|
| 33 |
#
|
| 34 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 35 |
import torch
|
| 36 |
-
|
| 37 |
# Load tokenizer & model
|
| 38 |
tokenizer = AutoTokenizer.from_pretrained("Kavyaah/copywriting-llm")
|
| 39 |
model = AutoModelForCausalLM.from_pretrained("Kavyaah/copywriting-llm", torch_dtype="auto")
|
| 40 |
model.eval()
|
| 41 |
-
|
| 42 |
# Function to generate push notification
|
| 43 |
def generate_copy(brand, offer, tone="fun", max_new_tokens=40):
|
| 44 |
prompt = f"""You are an expert marketing copywriter.
|
| 45 |
Write a short, catchy push notification in a {tone} tone.
|
| 46 |
It should promote {brand}'s offer: "{offer}".
|
| 47 |
Keep it under 20 words, engaging, and persuasive."""
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
# Example
|
| 54 |
print(generate_copy("Zomato", "Flat 60% off on dinner combos this weekend!"))
|
| 55 |
#
|
|
|
|
| 33 |
#
|
| 34 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 35 |
import torch
|
| 36 |
+
|
| 37 |
# Load tokenizer & model
|
| 38 |
tokenizer = AutoTokenizer.from_pretrained("Kavyaah/copywriting-llm")
|
| 39 |
model = AutoModelForCausalLM.from_pretrained("Kavyaah/copywriting-llm", torch_dtype="auto")
|
| 40 |
model.eval()
|
| 41 |
+
|
| 42 |
# Function to generate push notification
|
| 43 |
def generate_copy(brand, offer, tone="fun", max_new_tokens=40):
|
| 44 |
prompt = f"""You are an expert marketing copywriter.
|
| 45 |
Write a short, catchy push notification in a {tone} tone.
|
| 46 |
It should promote {brand}'s offer: "{offer}".
|
| 47 |
Keep it under 20 words, engaging, and persuasive."""
|
| 48 |
+
|
| 49 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 50 |
+
with torch.no_grad():
|
| 51 |
+
outputs = model.generate(
|
| 52 |
+
**inputs,
|
| 53 |
+
max_new_tokens=max_new_tokens,
|
| 54 |
+
temperature=0.9,
|
| 55 |
+
top_p=0.9,
|
| 56 |
+
do_sample=True
|
| 57 |
+
)
|
| 58 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 59 |
+
|
| 60 |
# Example
|
| 61 |
print(generate_copy("Zomato", "Flat 60% off on dinner combos this weekend!"))
|
| 62 |
#
|