Spaces:
Runtime error
Runtime error
File size: 1,254 Bytes
5a15317 edb9c7f 5a15317 edb9c7f 5a15317 a25ed47 5a15317 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import streamlit as st
from transformers import pipeline, set_seed
# Load the text generation pipeline
text_generator = pipeline("text2text-generation", model="google/flan-t5-base")
# Streamlit interface for story generation
st.title("Story Generator")
# Input fields for story parameters
title = st.text_input("Title of the Story:")
character = st.text_input("Character (Hero) Name:")
era = st.selectbox("Era of the Story:", ["Medieval", "Modern", "Future"])
genre = st.selectbox("Genre:", ["Action", "Novelistic", "Love"])
punchline = st.text_area("Punchline (Describe what the story is about):")
story_length = st.slider("Story Length", min_value=100, max_value=2000, step=100)
generate_button = st.button("Generate Story")
# Generate story based on user inputs
if generate_button:
if title and character and punchline:
prompt = f"Write a {genre} story titled '{title}' set in the {era} era. The main character, {character}, faces a {genre} adventure. The story is about '{punchline}'."
set_seed(42)
full_story = text_generator(prompt, max_length=story_length, do_sample=True)[0]["generated_text"]
st.markdown(full_story)
else:
st.warning("Please provide a title, character name, and punchline.")
|