Update app.py
Browse files
app.py
CHANGED
@@ -1,52 +1,12 @@
|
|
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 |
-
|
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 |
-
|
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 |
-
#
|
34 |
-
|
35 |
-
|
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 |
-
#
|
44 |
-
|
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.")
|
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
+
text_generator = pipeline("text-generation", model="EleutherAI/gpt-neo-1.3B", device=0) # You can choose a different model if needed
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
# Generate text
|
8 |
+
prompt = "Once upon a time"
|
9 |
+
generated_text = text_generator(prompt, max_length=100, num_return_sequences=1)[0]['generated_text']
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
# Print the generated text
|
12 |
+
print(generated_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|