Update app.py
Browse files
app.py
CHANGED
@@ -1,53 +1,52 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
-
from responsivevoice import ResponsiveVoice
|
4 |
-
import random
|
5 |
|
6 |
-
#
|
7 |
-
|
|
|
|
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
|
12 |
-
#
|
13 |
-
|
14 |
-
|
15 |
-
# Define supported languages
|
16 |
-
languages = ["en", "fr", "es", "de", "it"]
|
17 |
-
|
18 |
-
def translate_text(text, target_language):
|
19 |
-
translator = Translator()
|
20 |
-
translated_text = translator.translate(text, dest=target_language).text
|
21 |
-
return translated_text
|
22 |
-
|
23 |
-
def generate_and_narrate_story(prompt, language):
|
24 |
-
# Generate story based on prompt
|
25 |
-
story = generator(prompt, max_length=1024)[0]["generated_text"]
|
26 |
-
|
27 |
-
# Translate story to chosen language
|
28 |
-
if language != "en":
|
29 |
-
translated_story = translate_text(story, language)
|
30 |
-
else:
|
31 |
-
translated_story = story
|
32 |
-
|
33 |
-
# Speak the story using the text-to-speech model
|
34 |
-
tts_model.speak(translated_story, language)
|
35 |
-
|
36 |
-
# Streamlit app initialization
|
37 |
-
st.title("AI Storytelling App")
|
38 |
-
|
39 |
-
# Prompt input
|
40 |
-
prompt = st.text_input("Start your story with...")
|
41 |
-
|
42 |
-
# Language selector
|
43 |
-
language = st.selectbox("Choose narration language:", languages)
|
44 |
|
45 |
# Generate story button
|
46 |
-
if st.button("Generate
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
st.write("
|
52 |
-
|
|
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
|
|
|
|
3 |
|
4 |
+
# Load Hugging Face pipelines
|
5 |
+
text_generator = pipeline("text-generation")
|
6 |
+
text_to_speech = pipeline("text-to-speech")
|
7 |
+
text_to_image = pipeline("text2image")
|
8 |
|
9 |
+
# Streamlit app
|
10 |
+
st.title("Children's Storytelling App")
|
11 |
|
12 |
+
# Input prompt for story
|
13 |
+
story_prompt = st.text_area("Write the beginning of your story:")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
# Generate story button
|
16 |
+
if st.button("Generate Story"):
|
17 |
+
if story_prompt:
|
18 |
+
# Generate text
|
19 |
+
generated_story = text_generator(story_prompt, max_length=100, num_return_sequences=1)
|
20 |
+
st.write("Here's your story:")
|
21 |
+
st.write(generated_story[0]["generated_text"])
|
22 |
+
else:
|
23 |
+
st.warning("Please enter a story prompt.")
|
24 |
|
25 |
+
# Text-to-speech button
|
26 |
+
if st.button("Text to Speech"):
|
27 |
+
if story_prompt:
|
28 |
+
# Convert text to speech
|
29 |
+
st.audio(text_to_speech(story_prompt)[0]["audio"], format="audio/wav")
|
30 |
+
else:
|
31 |
+
st.warning("Please enter a story prompt.")
|
32 |
+
|
33 |
+
# Text-to-text button
|
34 |
+
if st.button("Text to Text"):
|
35 |
+
if story_prompt:
|
36 |
+
# Convert text to a different text
|
37 |
+
transformed_text = text_to_image(story_prompt)[0]["generated_text"]
|
38 |
+
st.write("Transformed text:")
|
39 |
+
st.write(transformed_text)
|
40 |
+
else:
|
41 |
+
st.warning("Please enter a story prompt.")
|
42 |
+
|
43 |
+
# Text-to-image
|
44 |
+
st.sidebar.title("Text to Image")
|
45 |
+
image_prompt = st.sidebar.text_area("Enter text for image:")
|
46 |
+
if st.sidebar.button("Generate Image"):
|
47 |
+
if image_prompt:
|
48 |
+
# Convert text to image
|
49 |
+
image = text_to_image(image_prompt)[0]["image"]
|
50 |
+
st.sidebar.image(image, caption="Generated Image", use_column_width=True)
|
51 |
+
else:
|
52 |
+
st.sidebar.warning("Please enter text for the image.")
|