import streamlit as st from transformers import pipeline # Create a text2text-generation pipeline with the "google/flan-t5-base" model text_generator = pipeline("text2text-generation", model="google/flan-t5-base") st.title("Story Generator") 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"]) ending = st.selectbox("Ending:", ["Happy", "Sad"]) if st.button("Generate Story"): if title and character: # Generate story elements using the model setting = text_generator(f"Create the setting for a story set in the {era} era.") conflict = text_generator(f"Describe the main conflict faced by the character {character}.") resolution = text_generator(f"Provide a resolution for the {ending} ending.") # Combine the elements into a full story story = f"# {title}\n\nOnce upon a time, in the {era} era, there was a character named {character}. " story += f"This is a {genre} story of {character}, a tale filled with {setting}, a story of {conflict}. " story += f"In the end, a {resolution}." st.markdown(story) else: st.warning("Please provide a title and character name.")