Home

AI Story Generator

import torch
from transformers import GPT2LMHeadModel, GPT2Tokenizer

# Load the pre-trained GPT-2 model and tokenizer
model_name = "gpt2-medium"  # Choose model size
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
model = GPT2LMHeadModel.from_pretrained(model_name)

# Set the model to evaluation mode
model.eval()

# Function to generate story
def generate_story(prompt, max_length=1000, temperature=1.0):
    # Tokenize the user-provided story prompt and convert it into input_ids
    input_ids = tokenizer.encode(prompt, return_tensors="pt")
    
    # Generate a story based on the input_ids (prompt)
    output = model.generate(
        input_ids,
        max_length=max_length,
        temperature=temperature,
        num_return_sequences=1,  # Generate a single sequence
        pad_token_id=50256,      # Specify the padding token ID for GPT-2
        do_sample=True,          # Allow for sampling to introduce randomness
    )
    
    # Decode the generated output into human-readable text, skipping special tokens
    story = tokenizer.decode(output[0], skip_special_tokens=True)
    return story

# Prompt the user to enter a story prompt
prompt = input("Enter a story prompt: ")

# Generate a story based on the user-provided prompt using the generate_story function
story = generate_story(prompt)

# Print the generated story
print(story)

In a small, colorful village nestled in the hills, there lived a curious young explorer named Lily. One sunny morning, she stumbled upon a mysterious, glowing object in the forest, which had an eerie glow emanating from it.

Lily knew it was something, but she had no idea what it was. She did find the creature, which appeared to be a human, inside the object, and that it was still glowing. She tried to contact the thing, but she couldn't reach it. She finally came across the village of Marienburg when she had to find her father in the forest. He found her out there, just a step away!

But it turned out that the glowing thing that Lily had seen was quite different from the human she was in the forest, and she had the distinct possibility that it was something else. So she got the other villagers to help her in doing research to see if there was anything to this strange glowing object or why it was glowing.

The villagers were thrilled to be able to help her, and the only one who didn't find the object as it had previously occurred to her was the mysterious man who appeared in her vision. He had been there, and his voice was hauntingly familiar despite its strangeness!

Lily was soon on an expedition to investigate the mysterious object, but when she finally stumbled into the village of Marienburg... the village was now in shambles! The villagers were fighting, and Lily was afraid for her life!

She was going to be murdered by these two people...! Not only that, she was going to have to do some serious thinking if she desired to save her life! She was going off on a new adventure all of her own, with no one to look out for her. She knew her life was in peril, but she was determined to save it! So she became an adventurer as her last act in an old adventure adventure!

Who Are The Villages Of Marienburg?
© 2024    •  Powered by Soopr   •  Theme  Moonwalk