pjq626 commited on
Commit
d4fae4d
·
verified ·
1 Parent(s): b932c44

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -5
app.py CHANGED
@@ -57,19 +57,17 @@ def generate_story(caption, model, tokenizer):
57
  model: GPT-2 model.
58
  tokenizer: GPT-2 tokenizer.
59
  Returns:
60
- story: Generated story as a string.
61
  """
62
  # Add a child-friendly story prompt
63
  story_prompt = (
64
  f"Once upon a time, in a magical land, {caption}. "
65
- "This is the story of what happened next: "
66
- "There was a little hero who loved adventures. "
67
- "One day, something amazing happened! "
68
  )
69
  input_ids = tokenizer.encode(story_prompt, return_tensors="pt")
70
  output = model.generate(
71
  input_ids,
72
- max_length=100,
73
  num_return_sequences=1,
74
  no_repeat_ngram_size=2,
75
  temperature=0.9, # Add randomness for creativity
 
57
  model: GPT-2 model.
58
  tokenizer: GPT-2 tokenizer.
59
  Returns:
60
+ story: Generated story as a string (100 words or less).
61
  """
62
  # Add a child-friendly story prompt
63
  story_prompt = (
64
  f"Once upon a time, in a magical land, {caption}. "
65
+ "One sunny day, something magical happened! "
 
 
66
  )
67
  input_ids = tokenizer.encode(story_prompt, return_tensors="pt")
68
  output = model.generate(
69
  input_ids,
70
+ max_length=100, # Limit story length to 100 words
71
  num_return_sequences=1,
72
  no_repeat_ngram_size=2,
73
  temperature=0.9, # Add randomness for creativity