Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,62 +1,227 @@
|
|
1 |
# app.py
|
2 |
-
|
3 |
import streamlit as st
|
|
|
|
|
|
|
|
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
-
|
8 |
-
# Explanation of Criteria
|
9 |
-
st.write("""
|
10 |
-
### Qualification Criteria:
|
11 |
-
To qualify for the **Gen AI Training Success Certificate**, you must achieve a minimum of **50%** overall score.
|
12 |
-
Your final score is calculated with the following weightage:
|
13 |
-
- **Quiz 1:** 5%
|
14 |
-
- **Quiz 2:** 5%
|
15 |
-
- **Quiz 3:** 10%
|
16 |
-
- **Quiz 4:** 15%
|
17 |
-
- **Quiz 5:** 15%
|
18 |
-
- **Grand Quiz (Final Exam):** 50%
|
19 |
-
|
20 |
-
Enter your scores below to check if you qualify!
|
21 |
-
""")
|
22 |
|
23 |
-
#
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
# Calculate Final Weighted Score
|
32 |
-
if st.button("Check Qualification"):
|
33 |
-
# Convert scores out of 60 to percentage
|
34 |
-
weighted_score = (
|
35 |
-
(quiz1 / 60) * 5 +
|
36 |
-
(quiz2 / 60) * 5 +
|
37 |
-
(quiz3 / 60) * 10 +
|
38 |
-
(quiz4 / 60) * 15 +
|
39 |
-
(quiz5 / 60) * 15 +
|
40 |
-
(grand_quiz / 60) * 50
|
41 |
-
)
|
42 |
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
else:
|
59 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
-
#
|
62 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
# app.py
|
|
|
2 |
import streamlit as st
|
3 |
+
import requests
|
4 |
+
import time
|
5 |
+
import os
|
6 |
+
from dotenv import load_dotenv
|
7 |
|
8 |
+
# Load environment variables
|
9 |
+
load_dotenv()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
# Set up the page
|
12 |
+
st.set_page_config(
|
13 |
+
page_title="CodeTales โจ",
|
14 |
+
page_icon="๐",
|
15 |
+
layout="wide",
|
16 |
+
initial_sidebar_state="expanded"
|
17 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
# Custom CSS
|
20 |
+
st.markdown("""
|
21 |
+
<style>
|
22 |
+
@import url('https://fonts.googleapis.com/css2?family=Comic+Neue:wght@700&display=swap');
|
23 |
+
|
24 |
+
.stApp {
|
25 |
+
background: linear-gradient(135deg, #6e8efb, #a777e3);
|
26 |
+
}
|
27 |
+
|
28 |
+
.header {
|
29 |
+
font-family: 'Comic Neue', cursive;
|
30 |
+
color: white;
|
31 |
+
text-align: center;
|
32 |
+
font-size: 3.5rem;
|
33 |
+
text-shadow: 3px 3px 0 #000;
|
34 |
+
padding: 1rem;
|
35 |
+
}
|
36 |
+
|
37 |
+
.subheader {
|
38 |
+
font-family: 'Comic Neue', cursive;
|
39 |
+
color: #ffeb3b;
|
40 |
+
text-align: center;
|
41 |
+
font-size: 1.8rem;
|
42 |
+
margin-bottom: 2rem;
|
43 |
+
}
|
44 |
+
|
45 |
+
.story-box {
|
46 |
+
background-color: rgba(255, 255, 255, 0.9);
|
47 |
+
border-radius: 20px;
|
48 |
+
padding: 2rem;
|
49 |
+
box-shadow: 0 8px 16px rgba(0,0,0,0.2);
|
50 |
+
margin-bottom: 2rem;
|
51 |
+
}
|
52 |
+
|
53 |
+
.robot-speech {
|
54 |
+
background-color: #4caf50;
|
55 |
+
color: white;
|
56 |
+
border-radius: 20px;
|
57 |
+
padding: 1.5rem;
|
58 |
+
font-size: 1.2rem;
|
59 |
+
position: relative;
|
60 |
+
margin-top: 2rem;
|
61 |
+
}
|
62 |
+
|
63 |
+
.robot-speech:after {
|
64 |
+
content: '';
|
65 |
+
position: absolute;
|
66 |
+
top: -20px;
|
67 |
+
left: 50px;
|
68 |
+
border: 10px solid transparent;
|
69 |
+
border-bottom-color: #4caf50;
|
70 |
+
}
|
71 |
+
|
72 |
+
.generate-btn {
|
73 |
+
background: #ff5722 !important;
|
74 |
+
color: white !important;
|
75 |
+
font-weight: bold !important;
|
76 |
+
font-size: 1.2rem !important;
|
77 |
+
padding: 0.7rem 2rem !important;
|
78 |
+
border-radius: 50px !important;
|
79 |
+
border: none !important;
|
80 |
+
box-shadow: 0 4px 8px rgba(0,0,0,0.3) !important;
|
81 |
+
transition: all 0.3s !important;
|
82 |
+
margin-top: 1rem;
|
83 |
+
}
|
84 |
+
|
85 |
+
.generate-btn:hover {
|
86 |
+
transform: scale(1.05) !important;
|
87 |
+
box-shadow: 0 6px 12px rgba(0,0,0,0.4) !important;
|
88 |
+
}
|
89 |
+
|
90 |
+
.code-block {
|
91 |
+
background: #2d2d2d;
|
92 |
+
color: #f8f8f2;
|
93 |
+
padding: 1rem;
|
94 |
+
border-radius: 10px;
|
95 |
+
font-family: monospace;
|
96 |
+
font-size: 1.1rem;
|
97 |
+
margin: 1rem 0;
|
98 |
+
overflow-x: auto;
|
99 |
+
}
|
100 |
+
</style>
|
101 |
+
""", unsafe_allow_html=True)
|
102 |
|
103 |
+
# Header section
|
104 |
+
st.markdown('<div class="header">CodeTales โจ</div>', unsafe_allow_html=True)
|
105 |
+
st.markdown('<div class="subheader">Storytime + Coding Magic</div>', unsafe_allow_html=True)
|
106 |
+
st.markdown('<div style="text-align:center; color:white; font-size:1.2rem; margin-bottom:2rem;">Turn wild stories into playable games with AI magic!</div>', unsafe_allow_html=True)
|
107 |
|
108 |
+
# How it works section
|
109 |
+
with st.expander("โจ How It Works (Like Baking a Cake) ๐"):
|
110 |
+
st.markdown("""
|
111 |
+
**1. Kids Write a Story (The Recipe)**
|
112 |
+
Example: *"The spaceship zooms past aliens and shoots lasers!"*
|
113 |
+
|
114 |
+
**2. AI is the Magic Oven ๐ฎ**
|
115 |
+
We turn words into code (like translating English to Computer)
|
116 |
+
|
117 |
+
**3. Animation Pops Out (The Cake!) ๐ฎ**
|
118 |
+
See your spaceship flying and shooting instantly!
|
119 |
+
|
120 |
+
**4. Robot Teacher Explains ๐ค**
|
121 |
+
Tavus shows: *"See? 'spaceship.move_right()' makes it fly! That's coding!"*
|
122 |
+
""")
|
123 |
+
|
124 |
+
# Main content
|
125 |
+
col1, col2 = st.columns([1, 1])
|
126 |
+
|
127 |
+
with col1:
|
128 |
+
st.markdown('<div class="story-box">', unsafe_allow_html=True)
|
129 |
+
st.markdown("### ๐ Write Your Story Here:")
|
130 |
+
story_text = st.text_area(
|
131 |
+
"Tell your adventure story...",
|
132 |
+
height=200,
|
133 |
+
placeholder="Once upon a time, a brave spaceship zoomed through space, shooting lasers at alien spaceships...",
|
134 |
+
label_visibility="collapsed"
|
135 |
+
)
|
136 |
+
|
137 |
+
# Generate button with animation
|
138 |
+
if st.button("โจ Generate Animation!", use_container_width=True, key="generate", type="primary"):
|
139 |
+
st.session_state.generate_clicked = True
|
140 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
141 |
|
142 |
+
with col2:
|
143 |
+
st.markdown('<div class="story-box">', unsafe_allow_html=True)
|
144 |
+
st.markdown("### ๐ฎ Your Game Animation")
|
145 |
+
|
146 |
+
if 'generate_clicked' in st.session_state and story_text:
|
147 |
+
with st.spinner("๐งโโ๏ธ Cooking your story in the magic oven..."):
|
148 |
+
# Simulate processing time
|
149 |
+
time.sleep(3)
|
150 |
+
|
151 |
+
# Generate animation (would use actual API call in production)
|
152 |
+
st.session_state.animation_generated = True
|
153 |
+
st.session_state.story_text = story_text
|
154 |
+
|
155 |
+
# Display animation placeholder
|
156 |
+
st.video("https://cdn.pixabay.com/video/2023/01/20/155564-810349295_large.mp4")
|
157 |
+
|
158 |
+
st.success("๐ Your animation is ready! Tavus will explain the magic now!")
|
159 |
+
elif 'animation_generated' in st.session_state:
|
160 |
+
st.video("https://cdn.pixabay.com/video/2023/01/20/155564-810349295_large.mp4")
|
161 |
else:
|
162 |
+
st.image("https://img.freepik.com/free-vector/hand-drawn-colorful-space-background_23-2148821798.jpg", use_column_width=True)
|
163 |
+
st.info("๐ Write your story and click Generate to see the magic!")
|
164 |
+
|
165 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
166 |
+
|
167 |
+
# Tavus explanation section
|
168 |
+
if 'animation_generated' in st.session_state and 'story_text' in st.session_state:
|
169 |
+
st.markdown('<div class="robot-speech">', unsafe_allow_html=True)
|
170 |
+
st.markdown("### ๐ค Tavus the Robot Teacher says:")
|
171 |
+
|
172 |
+
# Extract action words from story
|
173 |
+
action_words = ["zoom", "shoot", "fly", "move", "jump", "run", "attack"]
|
174 |
+
found_actions = [word for word in action_words if word in st.session_state.story_text.lower()]
|
175 |
+
|
176 |
+
if found_actions:
|
177 |
+
action = found_actions[0]
|
178 |
+
explanation = {
|
179 |
+
"zoom": "makes your spaceship move super fast!",
|
180 |
+
"shoot": "creates laser beams to defeat enemies!",
|
181 |
+
"fly": "keeps your character moving through the air!",
|
182 |
+
"move": "changes position on the screen!",
|
183 |
+
"jump": "makes your character leap upwards!",
|
184 |
+
"run": "makes your character move faster!",
|
185 |
+
"attack": "lets your hero fight the bad guys!"
|
186 |
+
}
|
187 |
+
|
188 |
+
code_snippet = {
|
189 |
+
"zoom": "spaceship.accelerate(speed=10)",
|
190 |
+
"shoot": "laser = spaceship.fire_weapon()",
|
191 |
+
"fly": "character.apply_gravity(False)",
|
192 |
+
"move": "player.move(direction='right')",
|
193 |
+
"jump": "hero.jump(height=100)",
|
194 |
+
"run": "player.speed = player.speed * 2",
|
195 |
+
"attack": "sword.swing(damage=15)"
|
196 |
+
}
|
197 |
+
|
198 |
+
st.markdown(f"See how your story became real code? When you said **'{action}'**, we used:")
|
199 |
+
st.markdown(f'<div class="code-block">{code_snippet[action]}</div>', unsafe_allow_html=True)
|
200 |
+
st.markdown(f"This code {explanation[action]} That's the magic of coding - turning words into actions!")
|
201 |
+
else:
|
202 |
+
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!")
|
203 |
+
|
204 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
205 |
+
|
206 |
+
# Benefits section
|
207 |
+
st.markdown("""
|
208 |
+
## โค Why Everyone Will Love CodeTales
|
209 |
+
|
210 |
+
| For Kids ๐ง๐ฆ | For Parents & Teachers ๐ช๐ฉโ๐ซ |
|
211 |
+
|--------------|----------------------------|
|
212 |
+
| โจ Feels like playing, not learning | ๐ง Secretly teaches programming concepts |
|
213 |
+
| ๐ Brings imagination to life | ๐ Develops logical thinking skills |
|
214 |
+
| ๐ฎ Creates personal video games | โ Reinforces math fundamentals |
|
215 |
+
| ๐ Makes learning fun and exciting | ๐งฉ Encourages problem-solving abilities |
|
216 |
+
""")
|
217 |
|
218 |
+
# Footer
|
219 |
+
st.markdown("---")
|
220 |
+
st.markdown("""
|
221 |
+
<center>
|
222 |
+
<p style="color:white; font-size:1.1rem;">
|
223 |
+
โจ Made with magic by CodeTales Team โจ<br>
|
224 |
+
Transforming stories into games since 2023
|
225 |
+
</p>
|
226 |
+
</center>
|
227 |
+
""", unsafe_allow_html=True)
|