import streamlit as st from transformers import pipeline from responsivevoice import ResponsiveVoice from PIL import Image from diffusers import StableDiffusionPipeline # Text-to-speech model tts_model = ResponsiveVoice() # Text-to-image pipeline sd_pipeline = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4") # Story generation model generator = pipeline("text-generation", model="gpt2") def generate_story(prompt): """ Generates a story based on user input. Args: prompt: A string containing the starting prompt for the story. Returns: A string containing the generated story. """ story = generator(prompt, max_length=1024)[0]["generated_text"] return story def generate_image(prompt): """ Generates an image based on user input. Args: prompt: A string containing the description for the image. Returns: A PIL Image object. """ image = sd_pipeline(prompt).images[0] return image # Streamlit app st.title("Hugging Face Storytelling App") # Prompt input prompt = st.text_input("Start your story with...") # Text-to-speech button if st.button("Speak the Story"): with st.spinner("Speaking the story..."): tts_model.speak(generate_story(prompt)) # Text-to-text button if st.button("Generate Text from Prompt"): with st.spinner("Generating text..."): new_text = generate_story(prompt) st.write(new_text) # Text-to-image button if st.button("Generate Image from Prompt"): with st.spinner("Generating image..."): image = generate_image(prompt) st.image(image) # Questions to answer st.write("**Think about your story and answer these questions:**") st.text_input("What is the main character's name?") st.text_input("Where does the story take place?") st.text_input("What is the problem the character faces?") st.text_input("How does the character solve the problem?") # Disclaimer st.write("* This app is still under development and may not always generate accurate or coherent results.") st.write("* Please be mindful of the content generated by the AI models.")