fcesc-code commited on
Commit
286112a
β€’
1 Parent(s): 2304fa9

Update front.py

Browse files
Files changed (1) hide show
  1. front.py +46 -1
front.py CHANGED
@@ -1 +1,46 @@
1
- # Mock frontend
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Mock frontend
2
+ import streamlit as st
3
+ from transformers import pipeline
4
+
5
+ # Set up the Streamlit app
6
+ st.title("πŸ§šβ€β™€οΈ Magic Story Buddy πŸ“š")
7
+ st.markdown("Let's create a magical story just for you!")
8
+
9
+ # Initialize the model
10
+ @st.cache_resource
11
+ def load_model():
12
+ return pipeline("text-generation", model="ajibawa-2023/Young-Children-Storyteller-Mistral-7B")
13
+
14
+ model = load_model()
15
+
16
+ # User input
17
+ child_name = st.text_input("What's your name, young storyteller?")
18
+ story_theme = st.selectbox("What would you like your story to be about?",
19
+ ["Space Adventure", "Magical Forest", "Underwater World", "Dinosaur Discovery"])
20
+
21
+ # Additional options
22
+ story_length = st.slider("How long should the story be?", 50, 200, 100)
23
+ include_moral = st.checkbox("Include a moral lesson?")
24
+
25
+ if st.button("Create My Story!"):
26
+ if child_name and story_theme:
27
+ # Construct the prompt
28
+ prompt = f"[CHILDREN'S STORY] Once upon a time, in a {story_theme.lower()}, there was a brave child named {child_name}. "
29
+ if include_moral:
30
+ prompt += "This story teaches us that "
31
+
32
+ # Generate the story
33
+ story = model(prompt, max_length=story_length, num_return_sequences=1)[0]['generated_text']
34
+
35
+ # Display the story
36
+ st.markdown("## Your Magical Story")
37
+ st.write(story)
38
+
39
+ # Add a fun element
40
+ st.balloons()
41
+ else:
42
+ st.warning("Please tell me your name and choose a story theme.")
43
+
44
+ # Add some child-friendly decorations
45
+ st.markdown("---")
46
+ st.markdown("🌟 Remember, you're the star of every story! 🌟")