Views
No views yet
Midway and Conclusion. It uses the prompt as strong guidance rather than absolute constraints.max_length should be controlled).Keywords, Characters, Beginning, Midway, Conclusion) starts on a new line.1from transformers import pipeline
2
3# Replace '[your-huggingface-username/your-model-name]' with your actual model ID on the Hub
4generator = pipeline('text-generation', model='[your-huggingface-username/your-model-name]')
5
6prompt = """Keywords: castle, dragon, sword
7Characters: A dragon named Ignis, a brave knight Sir Kaelan
8Beginning: Sir Kaelan heard tales of a fierce dragon, Ignis, guarding an ancient castle and decided to investigate.
9Midway: Upon meeting Ignis, Sir Kaelan discovered the dragon was misunderstood and lonely. They formed an unlikely friendship, exploring the castle's secrets together.
10Conclusion: When a shadow army threatened the kingdom, Sir Kaelan, riding Ignis, led the charge, saving the realm and proving friendship is stronger than fear."""
11
12# It's recommended to specify max_length and potentially other parameters
13# Adjust max_length based on expected story size
14generated_stories = generator(
15 prompt,
16 max_length=500, # Adjust as needed
17 num_return_sequences=1,
18 # Add other parameters like do_sample=True, temperature=0.7, top_k=50 if desired
19)
20
21for story in generated_stories:
22 print(story['generated_text'])
23
24# The output will start with the prompt, followed by the generated story.
25# You might need to process the output string to separate the prompt from the generation.