File size: 2,077 Bytes
1ad83c1
 
 
 
 
a0d022f
1ad83c1
 
a0d022f
1ad83c1
 
a0d022f
1ad83c1
 
a0d022f
1ad83c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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.")