|
import streamlit as st |
|
from transformers import pipeline |
|
from responsivevoice import ResponsiveVoice |
|
from PIL import Image |
|
from diffusers import StableDiffusionPipeline |
|
|
|
|
|
tts_model = ResponsiveVoice() |
|
|
|
|
|
sd_pipeline = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4") |
|
|
|
|
|
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 |
|
|
|
|
|
st.title("Hugging Face Storytelling App") |
|
|
|
|
|
prompt = st.text_input("Start your story with...") |
|
|
|
|
|
if st.button("Speak the Story"): |
|
with st.spinner("Speaking the story..."): |
|
tts_model.speak(generate_story(prompt)) |
|
|
|
|
|
if st.button("Generate Text from Prompt"): |
|
with st.spinner("Generating text..."): |
|
new_text = generate_story(prompt) |
|
st.write(new_text) |
|
|
|
|
|
if st.button("Generate Image from Prompt"): |
|
with st.spinner("Generating image..."): |
|
image = generate_image(prompt) |
|
st.image(image) |
|
|
|
|
|
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?") |
|
|
|
|
|
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.") |
|
|