# app.py
import streamlit as st
import requests
import time
import os
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Set up the page
st.set_page_config(
page_title="CodeTales ✨",
page_icon="🚀",
layout="wide",
initial_sidebar_state="expanded"
)
# Custom CSS
st.markdown("""
""", unsafe_allow_html=True)
# Header section
st.markdown('
', unsafe_allow_html=True)
st.markdown('', unsafe_allow_html=True)
st.markdown('Turn wild stories into playable games with AI magic!
', unsafe_allow_html=True)
# How it works section
with st.expander("✨ How It Works (Like Baking a Cake) 🎂"):
st.markdown("""
**1. Kids Write a Story (The Recipe)**
Example: *"The spaceship zooms past aliens and shoots lasers!"*
**2. AI is the Magic Oven 🔮**
We turn words into code (like translating English to Computer)
**3. Animation Pops Out (The Cake!) 🎮**
See your spaceship flying and shooting instantly!
**4. Robot Teacher Explains 🤖**
Tavus shows: *"See? 'spaceship.move_right()' makes it fly! That's coding!"*
""")
# Main content
col1, col2 = st.columns([1, 1])
with col1:
st.markdown('', unsafe_allow_html=True)
st.markdown("### 📖 Write Your Story Here:")
story_text = st.text_area(
"Tell your adventure story...",
height=200,
placeholder="Once upon a time, a brave spaceship zoomed through space, shooting lasers at alien spaceships...",
label_visibility="collapsed"
)
# Generate button with animation
if st.button("✨ Generate Animation!", use_container_width=True, key="generate", type="primary"):
st.session_state.generate_clicked = True
st.markdown('
', unsafe_allow_html=True)
with col2:
st.markdown('', unsafe_allow_html=True)
st.markdown("### 🎮 Your Game Animation")
if 'generate_clicked' in st.session_state and story_text:
with st.spinner("🧙♂️ Cooking your story in the magic oven..."):
# Simulate processing time
time.sleep(3)
# Generate animation (would use actual API call in production)
st.session_state.animation_generated = True
st.session_state.story_text = story_text
# Display animation placeholder
st.video("https://cdn.pixabay.com/video/2023/01/20/155564-810349295_large.mp4")
st.success("🎉 Your animation is ready! Tavus will explain the magic now!")
elif 'animation_generated' in st.session_state:
st.video("https://cdn.pixabay.com/video/2023/01/20/155564-810349295_large.mp4")
else:
st.image("https://img.freepik.com/free-vector/hand-drawn-colorful-space-background_23-2148821798.jpg", use_column_width=True)
st.info("👆 Write your story and click Generate to see the magic!")
st.markdown('
', unsafe_allow_html=True)
# Tavus explanation section
if 'animation_generated' in st.session_state and 'story_text' in st.session_state:
st.markdown('', unsafe_allow_html=True)
st.markdown("### 🤖 Tavus the Robot Teacher says:")
# Extract action words from story
action_words = ["zoom", "shoot", "fly", "move", "jump", "run", "attack"]
found_actions = [word for word in action_words if word in st.session_state.story_text.lower()]
if found_actions:
action = found_actions[0]
explanation = {
"zoom": "makes your spaceship move super fast!",
"shoot": "creates laser beams to defeat enemies!",
"fly": "keeps your character moving through the air!",
"move": "changes position on the screen!",
"jump": "makes your character leap upwards!",
"run": "makes your character move faster!",
"attack": "lets your hero fight the bad guys!"
}
code_snippet = {
"zoom": "spaceship.accelerate(speed=10)",
"shoot": "laser = spaceship.fire_weapon()",
"fly": "character.apply_gravity(False)",
"move": "player.move(direction='right')",
"jump": "hero.jump(height=100)",
"run": "player.speed = player.speed * 2",
"attack": "sword.swing(damage=15)"
}
st.markdown(f"See how your story became real code? When you said **'{action}'**, we used:")
st.markdown(f'
{code_snippet[action]}
', unsafe_allow_html=True)
st.markdown(f"This code {explanation[action]} That's the magic of coding - turning words into actions!")
else:
st.markdown("I see you created an awesome story! Every word you write can become game code. Try adding action words like 'jump', 'run', or 'shoot' next time!")
st.markdown("
", unsafe_allow_html=True)
# Benefits section
st.markdown("""
## ❤ Why Everyone Will Love CodeTales
| For Kids 👧👦 | For Parents & Teachers 👪👩🏫 |
|--------------|----------------------------|
| ✨ Feels like playing, not learning | 🧠 Secretly teaches programming concepts |
| 🚀 Brings imagination to life | 🔍 Develops logical thinking skills |
| 🎮 Creates personal video games | ➗ Reinforces math fundamentals |
| 😄 Makes learning fun and exciting | 🧩 Encourages problem-solving abilities |
""")
# Footer
st.markdown("---")
st.markdown("""
✨ Made with magic by CodeTales Team ✨
Transforming stories into games since 2023
""", unsafe_allow_html=True)