Downloads · 30 days
6
4% of all-time downloads
GhulamMustafa0/children-story-generator
children-story-generator is a text generation model from GhulamMustafa0. Use it when you need the model to write or continue text. It is set up for peft. The card lists the license as llama2.
This is a fine-tuned LoRA adapter for personalized children's story generation, based on Llama 2 7B Chat.
Downloads · 30 days
6
4% of all-time downloads
All-time downloads
146
Public
Repo size
135 MB
Likes
1
Public
Click a slice to open those files.
.safetensors134 MB · 97%
From the Hugging Face model README
This is a fine-tuned LoRA adapter for personalized children's story generation, based on Llama 2 7B Chat.
This model generates personalized stories for children based on:
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import PeftModel
# Load base model with 4-bit quantization
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.float16,
)
base_model = AutoModelForCausalLM.from_pretrained(
"NousResearch/llama-2-7b-chat-hf",
quantization_config=bnb_config,
device_map="auto",
torch_dtype=torch.float16,
)
# Load LoRA adapter
model = PeftModel.from_pretrained(base_model, "GhulamMustafa0/children-story-generator")
tokenizer = AutoTokenizer.from_pretrained("NousResearch/llama-2-7b-chat-hf")
# Generate story
prompt = "<s>[INST] Generate a story for Emma, age 6, mood: curious, favorite animal: fox [/INST]"
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=500, temperature=0.7)
story = tokenizer.decode(outputs[0], skip_special_tokens=True)
import requests
API_URL = "https://api-inference.huggingface.co/models/GhulamMustafa0/children-story-generator"
headers = {"Authorization": "Bearer YOUR_HF_TOKEN"}
def generate_story(name, age, mood, animal):
prompt = f"<s>[INST] Generate a story for {name}, age {age}, mood: {mood}, favorite animal: {animal} [/INST]"
response = requests.post(
API_URL,
headers=headers,
json={
"inputs": prompt,
"parameters": {
"max_new_tokens": 500,
"temperature": 0.7,
"top_p": 0.9,
"do_sample": True
}
}
)
return response.json()[0]['generated_text']
# Generate a story
story = generate_story("Alex", "6", "brave", "lion")
print(story)
This model inherits the Llama 2 license from the base model.