TomMoule91 commited on
Commit
4769745
1 Parent(s): 44ce81a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Load the text generation pipeline
5
+ generator = pipeline("text-generation")
6
+
7
+ def generate_bedtime_story(name, interests, friends):
8
+ story_prompt = f"Once upon a time, there was a child named {name}. {name} loved {', '.join(interests)} and had many friends including {', '.join(friends)}."
9
+ story = generator(story_prompt, max_length=100)[0]['generated_text']
10
+ return story
11
+
12
+ def main():
13
+ st.title("Bedtime Story Generator")
14
+
15
+ name = st.text_input("Enter the name of the person you're reading to:")
16
+ interests = st.multiselect("Enter the interests of the person:", ["Adventure", "Magic", "Animals", "Science"])
17
+ friends = st.text_input("Enter the names of some friends:")
18
+
19
+ if st.button("Generate Story"):
20
+ if name and interests and friends:
21
+ story = generate_bedtime_story(name, interests, friends.split(","))
22
+ st.write(story)
23
+ else:
24
+ st.warning("Please fill in all the inputs.")
25
+
26
+ if __name__ == "__main__":
27
+ main()