image2story / gpt2_story_gen.py
bipin
added more than single story option
70b2a7d
raw
history blame
400 Bytes
from transformers import pipeline
def generate_story(image_caption, image, genre, n_stories):
story_gen = pipeline(
"text-generation",
"pranavpsv/genre-story-generator-v2"
)
input = f"<BOS> <{genre}> {image_caption}"
stories = '\n'.join([f"Story {i+1}\n{story_gen(input)[0]['generated_text'].strip(input)}" for i in range(n_stories)])
return stories