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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import base64
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
|
| 6 |
+
def set_page_config():
|
| 7 |
+
st.set_page_config(
|
| 8 |
+
page_title="Gyan.AI | Synaptyx.AI",
|
| 9 |
+
page_icon="π",
|
| 10 |
+
layout="wide",
|
| 11 |
+
initial_sidebar_state="expanded"
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
def apply_custom_css():
|
| 15 |
+
st.markdown("""
|
| 16 |
+
<style>
|
| 17 |
+
/* Main app styling */
|
| 18 |
+
.stApp {
|
| 19 |
+
background-color: #f8f9fa;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
/* Header styling */
|
| 23 |
+
.header-container {
|
| 24 |
+
position: fixed;
|
| 25 |
+
top: 0;
|
| 26 |
+
left: 0;
|
| 27 |
+
right: 0;
|
| 28 |
+
height: 60px;
|
| 29 |
+
background-color: white;
|
| 30 |
+
border-bottom: 1px solid #e9ecef;
|
| 31 |
+
z-index: 999;
|
| 32 |
+
padding: 0 20px;
|
| 33 |
+
display: flex;
|
| 34 |
+
align-items: center;
|
| 35 |
+
justify-content: space-between;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
.brand-text {
|
| 39 |
+
font-size: 24px;
|
| 40 |
+
font-weight: 600;
|
| 41 |
+
color: #1a1a1a;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
.sub-brand {
|
| 45 |
+
font-size: 18px;
|
| 46 |
+
color: #666;
|
| 47 |
+
margin-left: 8px;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
/* Chat container styling */
|
| 51 |
+
.chat-container {
|
| 52 |
+
background-color: white;
|
| 53 |
+
border-radius: 10px;
|
| 54 |
+
padding: 20px;
|
| 55 |
+
margin: 10px 0;
|
| 56 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
/* Message styling */
|
| 60 |
+
.user-message {
|
| 61 |
+
background-color: #007bff;
|
| 62 |
+
color: white;
|
| 63 |
+
padding: 10px 15px;
|
| 64 |
+
border-radius: 15px;
|
| 65 |
+
margin: 5px 0;
|
| 66 |
+
max-width: 80%;
|
| 67 |
+
margin-left: auto;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
.assistant-message {
|
| 71 |
+
background-color: #f1f3f5;
|
| 72 |
+
color: #1a1a1a;
|
| 73 |
+
padding: 10px 15px;
|
| 74 |
+
border-radius: 15px;
|
| 75 |
+
margin: 5px 0;
|
| 76 |
+
max-width: 80%;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
/* Input box styling */
|
| 80 |
+
.stTextInput input {
|
| 81 |
+
border-radius: 20px;
|
| 82 |
+
border: 1px solid #e9ecef;
|
| 83 |
+
padding: 10px 20px;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
.stTextInput input:focus {
|
| 87 |
+
border-color: #007bff;
|
| 88 |
+
box-shadow: 0 0 0 2px rgba(0,123,255,0.25);
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
/* Button styling */
|
| 92 |
+
.stButton button {
|
| 93 |
+
border-radius: 20px;
|
| 94 |
+
padding: 10px 25px;
|
| 95 |
+
background-color: #007bff;
|
| 96 |
+
color: white;
|
| 97 |
+
border: none;
|
| 98 |
+
transition: all 0.3s ease;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
.stButton button:hover {
|
| 102 |
+
background-color: #0056b3;
|
| 103 |
+
transform: translateY(-1px);
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
/* Sidebar styling */
|
| 107 |
+
.css-1d391kg {
|
| 108 |
+
background-color: white;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
/* Progress bar styling */
|
| 112 |
+
.stProgress > div > div {
|
| 113 |
+
background-color: #007bff;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
/* Custom tab styling */
|
| 117 |
+
.stTabs [data-baseweb="tab-list"] {
|
| 118 |
+
gap: 24px;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
.stTabs [data-baseweb="tab"] {
|
| 122 |
+
height: 50px;
|
| 123 |
+
white-space: pre;
|
| 124 |
+
background-color: transparent;
|
| 125 |
+
border-radius: 4px;
|
| 126 |
+
color: #666;
|
| 127 |
+
font-size: 16px;
|
| 128 |
+
font-weight: 500;
|
| 129 |
+
border: none;
|
| 130 |
+
padding: 0 16px;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
.stTabs [data-baseweb="tab"]:hover {
|
| 134 |
+
color: #007bff;
|
| 135 |
+
background-color: #f8f9fa;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
.stTabs [aria-selected="true"] {
|
| 139 |
+
color: #007bff !important;
|
| 140 |
+
background-color: #e7f1ff !important;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
/* Avatar styling */
|
| 144 |
+
.avatar-container {
|
| 145 |
+
width: 80px;
|
| 146 |
+
height: 80px;
|
| 147 |
+
border-radius: 40px;
|
| 148 |
+
background-color: #e7f1ff;
|
| 149 |
+
display: flex;
|
| 150 |
+
align-items: center;
|
| 151 |
+
justify-content: center;
|
| 152 |
+
margin: 20px auto;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
/* Onboarding card styling */
|
| 156 |
+
.onboarding-card {
|
| 157 |
+
background-color: white;
|
| 158 |
+
border-radius: 10px;
|
| 159 |
+
padding: 30px;
|
| 160 |
+
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
| 161 |
+
margin: 20px auto;
|
| 162 |
+
max-width: 600px;
|
| 163 |
+
}
|
| 164 |
+
</style>
|
| 165 |
+
""", unsafe_allow_html=True)
|
| 166 |
+
|
| 167 |
+
def show_header():
|
| 168 |
+
st.markdown("""
|
| 169 |
+
<div class="header-container">
|
| 170 |
+
<div>
|
| 171 |
+
<span class="brand-text">Synaptyx.AI</span>
|
| 172 |
+
<span class="sub-brand">/ Gyan.AI</span>
|
| 173 |
+
</div>
|
| 174 |
+
</div>
|
| 175 |
+
<div style="height: 60px"></div>
|
| 176 |
+
""", unsafe_allow_html=True)
|
| 177 |
+
|
| 178 |
+
def show_onboarding():
|
| 179 |
+
st.session_state.onboarding_step = st.session_state.get('onboarding_step', 0)
|
| 180 |
+
|
| 181 |
+
steps = [
|
| 182 |
+
{
|
| 183 |
+
"title": "Welcome to Gyan.AI",
|
| 184 |
+
"description": "Your personal AI learning companion. Let's get started on your educational journey.",
|
| 185 |
+
"emoji": "π"
|
| 186 |
+
},
|
| 187 |
+
{
|
| 188 |
+
"title": "Choose Your Path",
|
| 189 |
+
"description": "Select from various learning paths tailored to your interests and goals.",
|
| 190 |
+
"emoji": "π―"
|
| 191 |
+
},
|
| 192 |
+
{
|
| 193 |
+
"title": "Meet Your AI Tutor",
|
| 194 |
+
"description": "I'm here to guide you through your learning journey with personalized support.",
|
| 195 |
+
"emoji": "π€"
|
| 196 |
+
}
|
| 197 |
+
]
|
| 198 |
+
|
| 199 |
+
col1, col2, col3 = st.columns([1, 2, 1])
|
| 200 |
+
with col2:
|
| 201 |
+
st.markdown('<div class="onboarding-card">', unsafe_allow_html=True)
|
| 202 |
+
|
| 203 |
+
# Progress bar
|
| 204 |
+
progress = (st.session_state.onboarding_step + 1) / len(steps)
|
| 205 |
+
st.progress(progress)
|
| 206 |
+
|
| 207 |
+
# Avatar/emoji
|
| 208 |
+
st.markdown(f"""
|
| 209 |
+
<div class="avatar-container">
|
| 210 |
+
<span style="font-size: 40px">{steps[st.session_state.onboarding_step]['emoji']}</span>
|
| 211 |
+
</div>
|
| 212 |
+
""", unsafe_allow_html=True)
|
| 213 |
+
|
| 214 |
+
# Content
|
| 215 |
+
st.markdown(f"<h2 style='text-align: center; margin-bottom: 20px;'>{steps[st.session_state.onboarding_step]['title']}</h2>", unsafe_allow_html=True)
|
| 216 |
+
st.markdown(f"<p style='text-align: center; color: #666;'>{steps[st.session_state.onboarding_step]['description']}</p>", unsafe_allow_html=True)
|
| 217 |
+
|
| 218 |
+
# Navigation buttons
|
| 219 |
+
cols = st.columns([1, 1, 1])
|
| 220 |
+
with cols[0]:
|
| 221 |
+
if st.session_state.onboarding_step > 0:
|
| 222 |
+
if st.button("β Back"):
|
| 223 |
+
st.session_state.onboarding_step -= 1
|
| 224 |
+
st.rerun()
|
| 225 |
+
|
| 226 |
+
with cols[2]:
|
| 227 |
+
if st.session_state.onboarding_step < len(steps) - 1:
|
| 228 |
+
if st.button("Next β"):
|
| 229 |
+
st.session_state.onboarding_step += 1
|
| 230 |
+
st.rerun()
|
| 231 |
+
else:
|
| 232 |
+
if st.button("Get Started β"):
|
| 233 |
+
st.session_state.onboarding_completed = True
|
| 234 |
+
st.rerun()
|
| 235 |
+
|
| 236 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 237 |
+
|
| 238 |
+
def show_main_interface():
|
| 239 |
+
# Sidebar
|
| 240 |
+
with st.sidebar:
|
| 241 |
+
st.markdown("### π€ Profile")
|
| 242 |
+
if 'username' not in st.session_state:
|
| 243 |
+
username = st.text_input("Enter your nickname")
|
| 244 |
+
if username:
|
| 245 |
+
st.session_state.username = username
|
| 246 |
+
else:
|
| 247 |
+
st.write(f"Welcome, {st.session_state.username}! π")
|
| 248 |
+
|
| 249 |
+
st.markdown("### π Progress")
|
| 250 |
+
completed = len(st.session_state.get('completed_modules', []))
|
| 251 |
+
st.progress(completed / 8, f"Completed {completed}/8 modules")
|
| 252 |
+
|
| 253 |
+
if st.session_state.get('achievements', []):
|
| 254 |
+
st.markdown("### π Achievements")
|
| 255 |
+
for achievement in st.session_state.get('achievements', []):
|
| 256 |
+
st.success(f"{achievement['name']} - {achievement['date']}")
|
| 257 |
+
|
| 258 |
+
# Main content
|
| 259 |
+
tab1, tab2, tab3 = st.tabs(["π¬ Chat", "π Learn", "π» Code"])
|
| 260 |
+
|
| 261 |
+
with tab1:
|
| 262 |
+
st.markdown('<div class="chat-container">', unsafe_allow_html=True)
|
| 263 |
+
|
| 264 |
+
# Display chat messages
|
| 265 |
+
for message in st.session_state.get('messages', []):
|
| 266 |
+
if message["role"] == "user":
|
| 267 |
+
st.markdown(f'<div class="user-message">{message["content"]}</div>', unsafe_allow_html=True)
|
| 268 |
+
else:
|
| 269 |
+
st.markdown(f'<div class="assistant-message">{message["content"]}</div>', unsafe_allow_html=True)
|
| 270 |
+
|
| 271 |
+
# Chat input
|
| 272 |
+
with st.container():
|
| 273 |
+
if prompt := st.chat_input("Ask anything..."):
|
| 274 |
+
if 'messages' not in st.session_state:
|
| 275 |
+
st.session_state.messages = []
|
| 276 |
+
|
| 277 |
+
# Add user message
|
| 278 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 279 |
+
|
| 280 |
+
# Add AI response (placeholder)
|
| 281 |
+
response = f"I understand you want to learn about {prompt}. Let me help you with that."
|
| 282 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|
| 283 |
+
|
| 284 |
+
st.rerun()
|
| 285 |
+
|
| 286 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 287 |
+
|
| 288 |
+
with tab2:
|
| 289 |
+
st.markdown("### Learning Paths")
|
| 290 |
+
paths = {
|
| 291 |
+
'python_basics': {
|
| 292 |
+
'name': 'Python Programming Basics',
|
| 293 |
+
'modules': [
|
| 294 |
+
'Introduction to Python',
|
| 295 |
+
'Variables and Data Types',
|
| 296 |
+
'Control Flow',
|
| 297 |
+
'Functions'
|
| 298 |
+
],
|
| 299 |
+
'description': 'Learn the fundamentals of Python programming.'
|
| 300 |
+
},
|
| 301 |
+
'data_structures': {
|
| 302 |
+
'name': 'Data Structures',
|
| 303 |
+
'modules': [
|
| 304 |
+
'Lists and Tuples',
|
| 305 |
+
'Dictionaries',
|
| 306 |
+
'Sets',
|
| 307 |
+
'Advanced Operations'
|
| 308 |
+
],
|
| 309 |
+
'description': 'Master Python data structures and their operations.'
|
| 310 |
+
}
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
for path_id, path_info in paths.items():
|
| 314 |
+
with st.expander(f"{path_info['name']} π"):
|
| 315 |
+
st.write(path_info['description'])
|
| 316 |
+
st.write("### Modules:")
|
| 317 |
+
for module in path_info['modules']:
|
| 318 |
+
st.checkbox(module, key=f"module_{module}")
|
| 319 |
+
|
| 320 |
+
with tab3:
|
| 321 |
+
st.markdown("### Code Playground")
|
| 322 |
+
code = st.text_area("Write your Python code here", height=200)
|
| 323 |
+
col1, col2 = st.columns(2)
|
| 324 |
+
with col1:
|
| 325 |
+
if st.button("Run Code"):
|
| 326 |
+
try:
|
| 327 |
+
exec(code)
|
| 328 |
+
except Exception as e:
|
| 329 |
+
st.error(f"Error: {str(e)}")
|
| 330 |
+
|
| 331 |
+
def main():
|
| 332 |
+
set_page_config()
|
| 333 |
+
apply_custom_css()
|
| 334 |
+
show_header()
|
| 335 |
+
|
| 336 |
+
if not st.session_state.get('onboarding_completed', False):
|
| 337 |
+
show_onboarding()
|
| 338 |
+
else:
|
| 339 |
+
show_main_interface()
|
| 340 |
+
|
| 341 |
+
if __name__ == "__main__":
|
| 342 |
+
main()
|