Spaces:
Sleeping
Sleeping
Update app.py
#2
by maryamshanabli - opened
app.py
CHANGED
|
@@ -1,398 +1,892 @@
|
|
| 1 |
-
# app.py β Clean, fixed, single-file Gradio app for Synchrony
|
| 2 |
-
# Last updated: 2025-11-06
|
| 3 |
-
# Author: (rewritten for Lujain)
|
| 4 |
-
# -------------------------------------------------------
|
| 5 |
-
|
| 6 |
import gradio as gr
|
| 7 |
import requests
|
|
|
|
| 8 |
from datetime import datetime
|
| 9 |
-
from typing import Tuple, Any, Dict, List
|
| 10 |
|
| 11 |
# ============================================
|
| 12 |
-
#
|
|
|
|
| 13 |
# ============================================
|
|
|
|
|
|
|
| 14 |
BASE_URL = "https://maryyam.app.n8n.cloud/webhook-test"
|
| 15 |
START_SESSION_URL = f"{BASE_URL}/start-session"
|
| 16 |
GENERATE_CHALLENGES_URL = f"{BASE_URL}/generate-challenges"
|
| 17 |
REQUEST_HINT_URL = f"{BASE_URL}/request-hint"
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
# ============================================
|
| 24 |
-
#
|
| 25 |
# ============================================
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
try:
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
else:
|
| 35 |
-
|
|
|
|
|
|
|
| 36 |
except Exception as e:
|
| 37 |
-
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
-
def
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
-
if isinstance(result, dict):
|
| 49 |
-
session_id = result.get("session_id", "")
|
| 50 |
-
current_session["session_id"] = session_id
|
| 51 |
-
students = result.get("students", [])
|
| 52 |
-
students_list = ", ".join([s.get("name", "Unknown") for s in students]) if students else "No students found"
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
)
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
output_lines: List[str] = []
|
| 80 |
-
output_lines.append("β
**Challenges Generated!**\n")
|
| 81 |
-
synco_msg = result.get("synco_message", "")
|
| 82 |
-
if synco_msg:
|
| 83 |
-
output_lines.append(f"**π¬ Synco says:** {synco_msg}\n")
|
| 84 |
-
output_lines.append("---\n")
|
| 85 |
-
|
| 86 |
-
if not challenges:
|
| 87 |
-
output_lines.append("_No challenges returned from the API._")
|
| 88 |
else:
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
if isinstance(ch_json, dict):
|
| 94 |
-
description = ch_json.get("description", "")
|
| 95 |
-
topics = ch_json.get("topics_involved", "")
|
| 96 |
-
else:
|
| 97 |
-
description = str(ch)
|
| 98 |
-
|
| 99 |
-
output_lines.append(f"### π― Challenge {i}\n")
|
| 100 |
-
output_lines.append(f"**Description:**\n{description}\n")
|
| 101 |
-
if topics:
|
| 102 |
-
output_lines.append(f"**Topics:** {topics}\n")
|
| 103 |
-
output_lines.append("π‘ 3 hints available - request them when stuck!\n")
|
| 104 |
-
output_lines.append("---\n")
|
| 105 |
-
|
| 106 |
-
return "\n".join(output_lines)
|
| 107 |
-
|
| 108 |
-
return f"β
Response:\n```\n{result}\n```"
|
| 109 |
-
|
| 110 |
|
| 111 |
-
def request_hint(session_id: str, challenge_num: str, hint_level: str) -> str:
|
| 112 |
-
sid = session_id or current_session.get("session_id")
|
| 113 |
-
if not sid:
|
| 114 |
-
return "β Please provide a session ID."
|
| 115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
try:
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
output
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
|
| 143 |
|
| 144 |
# ============================================
|
| 145 |
-
#
|
| 146 |
# ============================================
|
|
|
|
| 147 |
custom_css = """
|
|
|
|
| 148 |
.gradio-container {
|
| 149 |
-
background:
|
| 150 |
-
font-family:
|
| 151 |
-
color: #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
}
|
| 153 |
|
| 154 |
-
/* Tabs styling */
|
| 155 |
.tab-nav button {
|
| 156 |
-
background:
|
| 157 |
-
border:
|
| 158 |
-
color:
|
| 159 |
-
font-weight:
|
|
|
|
|
|
|
|
|
|
| 160 |
transition: all 0.3s ease !important;
|
|
|
|
|
|
|
|
|
|
| 161 |
}
|
|
|
|
| 162 |
.tab-nav button:hover {
|
| 163 |
-
background:
|
| 164 |
-
border-color:
|
|
|
|
|
|
|
|
|
|
| 165 |
}
|
|
|
|
| 166 |
.tab-nav button.selected {
|
| 167 |
-
background:
|
| 168 |
-
border-color:
|
| 169 |
-
color:
|
| 170 |
-
|
|
|
|
| 171 |
}
|
| 172 |
|
| 173 |
/* Input fields */
|
| 174 |
input, textarea, select {
|
| 175 |
-
background:
|
| 176 |
-
border:
|
| 177 |
-
color: #
|
| 178 |
-
border-radius:
|
| 179 |
-
|
|
|
|
|
|
|
| 180 |
}
|
|
|
|
| 181 |
input:focus, textarea:focus, select:focus {
|
| 182 |
-
border-color:
|
| 183 |
-
box-shadow: 0 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
}
|
| 185 |
|
| 186 |
/* Buttons */
|
| 187 |
button {
|
| 188 |
-
background:
|
| 189 |
border: none !important;
|
| 190 |
-
color:
|
| 191 |
-
font-weight:
|
| 192 |
-
|
| 193 |
-
|
|
|
|
|
|
|
|
|
|
| 194 |
transition: all 0.3s ease !important;
|
| 195 |
-
box-shadow: 0
|
|
|
|
| 196 |
}
|
|
|
|
| 197 |
button:hover {
|
| 198 |
-
transform: translateY(-
|
| 199 |
-
box-shadow: 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
}
|
| 201 |
|
| 202 |
/* Output boxes */
|
| 203 |
-
.output-markdown {
|
| 204 |
-
background:
|
| 205 |
-
border:
|
| 206 |
-
border-radius:
|
| 207 |
-
padding:
|
| 208 |
-
color: #
|
|
|
|
|
|
|
| 209 |
}
|
| 210 |
|
| 211 |
/* Headers */
|
| 212 |
-
h1
|
| 213 |
-
background: linear-gradient(135deg,
|
| 214 |
-webkit-background-clip: text;
|
| 215 |
-webkit-text-fill-color: transparent;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
font-weight: 800 !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
}
|
| 218 |
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
}
|
| 226 |
|
| 227 |
/* Links */
|
| 228 |
a {
|
| 229 |
-
color:
|
| 230 |
text-decoration: none !important;
|
| 231 |
-
font-weight:
|
|
|
|
| 232 |
}
|
|
|
|
| 233 |
a:hover {
|
| 234 |
-
color:
|
| 235 |
-
text-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
}
|
| 237 |
|
| 238 |
/* Scrollbar */
|
| 239 |
::-webkit-scrollbar {
|
| 240 |
-
width:
|
|
|
|
| 241 |
}
|
|
|
|
| 242 |
::-webkit-scrollbar-track {
|
| 243 |
-
background:
|
|
|
|
| 244 |
}
|
|
|
|
| 245 |
::-webkit-scrollbar-thumb {
|
| 246 |
-
background:
|
| 247 |
border-radius: 10px;
|
|
|
|
| 248 |
}
|
|
|
|
| 249 |
::-webkit-scrollbar-thumb:hover {
|
| 250 |
-
background:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
}
|
| 252 |
-
"""
|
| 253 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
|
| 255 |
# ============================================
|
| 256 |
-
#
|
| 257 |
# ============================================
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
*Example Group IDs:* G001, G002, G003""")
|
| 282 |
with gr.Row():
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
with gr.Row():
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
- *Frontend:* Gradio (Python)
|
| 332 |
-
- *Backend:* n8n Workflows
|
| 333 |
-
- *AI:* Groq API (Llama 3.3 70B)
|
| 334 |
-
- *Database:* Google Sheets
|
| 335 |
-
- *Matching Algorithm:* Chemistry Score System
|
| 336 |
-
---
|
| 337 |
-
### π₯ Created By
|
| 338 |
-
*Maryam Shanabli* | 2025-11-06
|
| 339 |
-
Powered by AI β’ Built for Students β’ Designed for Impact π
|
| 340 |
-
"""
|
| 341 |
)
|
| 342 |
-
|
| 343 |
-
#
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 386 |
""")
|
| 387 |
|
| 388 |
-
|
| 389 |
# ============================================
|
| 390 |
-
#
|
| 391 |
# ============================================
|
|
|
|
| 392 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 393 |
app.launch(
|
| 394 |
server_name="0.0.0.0",
|
| 395 |
server_port=7860,
|
| 396 |
-
share=True,
|
| 397 |
-
show_error=True
|
| 398 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
+
import json
|
| 4 |
from datetime import datetime
|
|
|
|
| 5 |
|
| 6 |
# ============================================
|
| 7 |
+
# π SYNCHRONY - STUDENT PORTAL (GEN Z EDITION)
|
| 8 |
+
# Real Team Data | No Hardcoding | Pure Black Style
|
| 9 |
# ============================================
|
| 10 |
+
|
| 11 |
+
# Your n8n webhook URLs (CORRECTED)
|
| 12 |
BASE_URL = "https://maryyam.app.n8n.cloud/webhook-test"
|
| 13 |
START_SESSION_URL = f"{BASE_URL}/start-session"
|
| 14 |
GENERATE_CHALLENGES_URL = f"{BASE_URL}/generate-challenges"
|
| 15 |
REQUEST_HINT_URL = f"{BASE_URL}/request-hint"
|
| 16 |
|
| 17 |
+
# Google Form and Sheets URLs
|
| 18 |
+
REGISTRATION_FORM = "https://docs.google.com/forms/d/e/1FAIpQLSfJFGx-yd0FPIuRYLUJut3BOOiQ14x_5DYheWpgrUqcHdQaCA/viewform"
|
| 19 |
+
GOOGLE_SHEETS = "https://docs.google.com/spreadsheets/d/1rpR-E_RSooDkNDh-Q_1BDIeGw4vfgmusNAfwPqATaW4/edit?usp=sharing"
|
| 20 |
+
|
| 21 |
+
# Current student session (stored in memory)
|
| 22 |
+
current_student = {
|
| 23 |
+
"name": None,
|
| 24 |
+
"email": None,
|
| 25 |
+
"group_id": None,
|
| 26 |
+
"session_id": None,
|
| 27 |
+
"team_members": [],
|
| 28 |
+
"challenges": []
|
| 29 |
+
}
|
| 30 |
|
| 31 |
# ============================================
|
| 32 |
+
# π§ API FUNCTIONS (ALL REAL - NO HARDCODING)
|
| 33 |
# ============================================
|
| 34 |
+
|
| 35 |
+
def start_session_and_get_team(group_id):
|
| 36 |
+
"""Start session and get REAL team data from n8n"""
|
| 37 |
try:
|
| 38 |
+
response = requests.post(
|
| 39 |
+
START_SESSION_URL,
|
| 40 |
+
json={"group_id": group_id},
|
| 41 |
+
headers={"Content-Type": "application/json"},
|
| 42 |
+
timeout=30
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
if response.status_code == 200:
|
| 46 |
+
data = response.json()
|
| 47 |
+
|
| 48 |
+
# Store real data from API
|
| 49 |
+
current_student["session_id"] = data.get("session_id")
|
| 50 |
+
current_student["group_id"] = group_id
|
| 51 |
+
current_student["team_members"] = data.get("students", [])
|
| 52 |
+
|
| 53 |
+
return data
|
| 54 |
else:
|
| 55 |
+
print(f"Error starting session: {response.status_code}")
|
| 56 |
+
return None
|
| 57 |
+
|
| 58 |
except Exception as e:
|
| 59 |
+
print(f"Exception starting session: {str(e)}")
|
| 60 |
+
return None
|
| 61 |
|
| 62 |
|
| 63 |
+
def lookup_student(email):
|
| 64 |
+
"""Login with any email - assigns to G001 for demo, gets REAL team"""
|
| 65 |
+
try:
|
| 66 |
+
if not email or "@" not in email:
|
| 67 |
+
return False, "β please enter a valid email address!"
|
| 68 |
+
|
| 69 |
+
# Extract name from email (demo approach)
|
| 70 |
+
name_part = email.split("@")[0]
|
| 71 |
+
name = name_part.replace(".", " ").replace("_", " ").title()
|
| 72 |
+
|
| 73 |
+
# For demo: everyone joins G001 (in production: query Sheets for real group)
|
| 74 |
+
# Start session to get REAL team data
|
| 75 |
+
session_data = start_session_and_get_team("G001")
|
| 76 |
+
|
| 77 |
+
if session_data:
|
| 78 |
+
current_student["name"] = name
|
| 79 |
+
current_student["email"] = email
|
| 80 |
+
|
| 81 |
+
welcome_msg = f"β
**welcome back, {name}!** π\n\n"
|
| 82 |
+
welcome_msg += f"π **session id:** `{session_data.get('session_id')}`\n\n"
|
| 83 |
+
welcome_msg += f"π¬ **synco says:**\n{session_data.get('synco_message', '')}\n\n"
|
| 84 |
+
welcome_msg += f"π₯ **your team:** {', '.join([s['name'] for s in session_data.get('students', [])])}\n\n"
|
| 85 |
+
welcome_msg += f"β¨ head to **MY TEAM** tab to see everyone!"
|
| 86 |
+
|
| 87 |
+
return True, welcome_msg
|
| 88 |
+
else:
|
| 89 |
+
return False, "β could not connect to server. try again!"
|
| 90 |
+
|
| 91 |
+
except Exception as e:
|
| 92 |
+
return False, f"β error: {str(e)}"
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
+
def get_team_info():
|
| 96 |
+
"""Display REAL team information from start-session API"""
|
| 97 |
+
if not current_student.get("team_members"):
|
| 98 |
+
# Try to load team if not loaded
|
| 99 |
+
if current_student.get("group_id"):
|
| 100 |
+
session_data = start_session_and_get_team(current_student["group_id"])
|
| 101 |
+
if not session_data:
|
| 102 |
+
return "β οΈ could not load team info. try logging in again!"
|
| 103 |
+
else:
|
| 104 |
+
return "β οΈ please login first in the **HOME** tab!"
|
| 105 |
+
|
| 106 |
+
output = f"## π₯ your study squad - {current_student.get('group_id', '???')} π₯\n\n"
|
| 107 |
+
output += f"**session id:** `{current_student.get('session_id', 'not started')}`\n\n"
|
| 108 |
+
output += "---\n\n"
|
| 109 |
+
|
| 110 |
+
for i, member in enumerate(current_student["team_members"], 1):
|
| 111 |
+
# Check if this is the logged-in user (fuzzy match)
|
| 112 |
+
user_name = current_student.get("name", "").lower()
|
| 113 |
+
member_name = member.get("name", "").lower()
|
| 114 |
+
is_you = " **(YOU)** π" if user_name in member_name or member_name in user_name else ""
|
| 115 |
+
|
| 116 |
+
output += f"### π {member['name']}{is_you}\n"
|
| 117 |
+
output += f"**studying:** {member.get('topic', 'N/A')}\n\n"
|
| 118 |
+
|
| 119 |
+
output += "---\n\n"
|
| 120 |
+
output += f"π‘ *collaborate, learn together, level up!*"
|
| 121 |
+
|
| 122 |
+
return output
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def load_challenges():
|
| 126 |
+
"""Load REAL challenges from generate-challenges API"""
|
| 127 |
+
if not current_student.get("session_id"):
|
| 128 |
+
return "β οΈ no active session. please login first in the **HOME** tab!"
|
| 129 |
+
|
| 130 |
+
try:
|
| 131 |
+
response = requests.post(
|
| 132 |
+
GENERATE_CHALLENGES_URL,
|
| 133 |
+
json={"session_id": current_student["session_id"]},
|
| 134 |
+
headers={"Content-Type": "application/json"},
|
| 135 |
+
timeout=60 # AI generation can take time
|
| 136 |
)
|
| 137 |
+
|
| 138 |
+
if response.status_code == 200:
|
| 139 |
+
data = response.json()
|
| 140 |
+
current_student["challenges"] = data.get("challenges", [])
|
| 141 |
+
|
| 142 |
+
output = f"# π― your collaborative challenges\n\n"
|
| 143 |
+
output += f"π¬ **synco says:**\n{data.get('synco_message', '')}\n\n"
|
| 144 |
+
output += "---\n\n"
|
| 145 |
+
|
| 146 |
+
for i, challenge in enumerate(current_student["challenges"], 1):
|
| 147 |
+
chal = challenge.get('json', challenge)
|
| 148 |
+
output += f"## π― challenge {i}\n\n"
|
| 149 |
+
output += f"{chal.get('description', 'no description')}\n\n"
|
| 150 |
+
output += f"**π topics:** {chal.get('topics_involved', 'N/A')}\n\n"
|
| 151 |
+
output += f"π‘ *stuck? request a hint in the **HINTS** tab!*\n\n"
|
| 152 |
+
output += "---\n\n"
|
| 153 |
+
|
| 154 |
+
return output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
else:
|
| 156 |
+
return f"β error loading challenges: {response.status_code}\n\ntry refreshing or check your session id!"
|
| 157 |
+
|
| 158 |
+
except Exception as e:
|
| 159 |
+
return f"β connection error: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
+
def request_hint(challenge_num, hint_level_text):
|
| 163 |
+
"""Request REAL hint from request-hint API"""
|
| 164 |
+
if not current_student.get("session_id"):
|
| 165 |
+
return "β οΈ no active session. please login first!"
|
| 166 |
+
|
| 167 |
+
# Extract hint level number from text (e.g., "1 - gentle nudge π€" -> "1")
|
| 168 |
+
hint_level = hint_level_text.split(" - ")[0].strip()
|
| 169 |
+
|
| 170 |
try:
|
| 171 |
+
response = requests.post(
|
| 172 |
+
REQUEST_HINT_URL,
|
| 173 |
+
json={
|
| 174 |
+
"session_id": current_student["session_id"],
|
| 175 |
+
"challenge_number": int(challenge_num),
|
| 176 |
+
"hint_level": int(hint_level)
|
| 177 |
+
},
|
| 178 |
+
headers={"Content-Type": "application/json"},
|
| 179 |
+
timeout=10
|
| 180 |
+
)
|
| 181 |
+
|
| 182 |
+
if response.status_code == 200:
|
| 183 |
+
data = response.json()
|
| 184 |
+
|
| 185 |
+
output = f"## {data.get('synco_message', '')}\n\n"
|
| 186 |
+
output += f"π― **challenge {challenge_num}** | **hint level {hint_level}**\n\n"
|
| 187 |
+
output += "---\n\n"
|
| 188 |
+
output += f"{data.get('hint', '')}\n\n"
|
| 189 |
+
output += "---\n\n"
|
| 190 |
+
output += f"πͺ *you got this! keep going!*"
|
| 191 |
+
|
| 192 |
+
return output
|
| 193 |
+
else:
|
| 194 |
+
return f"β error: {response.status_code}\n\nmake sure you've loaded challenges first!"
|
| 195 |
+
|
| 196 |
+
except Exception as e:
|
| 197 |
+
return f"β connection error: {str(e)}"
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def send_message(message, history):
|
| 201 |
+
"""Send a chat message (SIMULATED for demo - would need real-time backend)"""
|
| 202 |
+
if not message.strip():
|
| 203 |
+
return history, ""
|
| 204 |
+
|
| 205 |
+
# Add user message
|
| 206 |
+
history.append({
|
| 207 |
+
"role": "user",
|
| 208 |
+
"content": f"**{current_student.get('name', 'you')}:** {message}"
|
| 209 |
+
})
|
| 210 |
+
|
| 211 |
+
# Simulate team member responses (FAKE - for demo only)
|
| 212 |
+
import random
|
| 213 |
+
|
| 214 |
+
if not current_student.get("team_members"):
|
| 215 |
+
response = "**synco (ai):** please login first to chat with your team! π¬"
|
| 216 |
+
else:
|
| 217 |
+
# Get random team member
|
| 218 |
+
other_members = [m for m in current_student["team_members"]
|
| 219 |
+
if m['name'].lower() != current_student.get('name', '').lower()]
|
| 220 |
+
|
| 221 |
+
if other_members:
|
| 222 |
+
member = random.choice(other_members)
|
| 223 |
+
responses = [
|
| 224 |
+
f"**{member['name']}:** that's a great point! let me add to that...",
|
| 225 |
+
f"**{member['name']}:** interesting! in {member['topic']}, we do it differently...",
|
| 226 |
+
f"**{member['name']}:** i agree! should we try that approach?",
|
| 227 |
+
f"**{member['name']}:** wait, can you explain that part again?",
|
| 228 |
+
f"**synco (ai):** great discussion everyone! π‘ keep collaborating!"
|
| 229 |
+
]
|
| 230 |
+
response = random.choice(responses)
|
| 231 |
+
else:
|
| 232 |
+
response = "**synco (ai):** great question! your teammates will respond soon! π¬"
|
| 233 |
+
|
| 234 |
+
history.append({
|
| 235 |
+
"role": "assistant",
|
| 236 |
+
"content": response
|
| 237 |
+
})
|
| 238 |
+
|
| 239 |
+
return history, ""
|
| 240 |
|
| 241 |
|
| 242 |
# ============================================
|
| 243 |
+
# π¨ CUSTOM CSS - PURE BLACK GEN Z STYLE
|
| 244 |
# ============================================
|
| 245 |
+
|
| 246 |
custom_css = """
|
| 247 |
+
/* Pure Black Gen Z Background */
|
| 248 |
.gradio-container {
|
| 249 |
+
background: #000000 !important;
|
| 250 |
+
font-family: 'Inter', 'SF Pro Display', 'Segoe UI', sans-serif !important;
|
| 251 |
+
color: #ffffff !important;
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
/* Neon accent colors */
|
| 255 |
+
:root {
|
| 256 |
+
--neon-pink: #ff0080;
|
| 257 |
+
--neon-cyan: #00ffff;
|
| 258 |
+
--neon-purple: #a855f7;
|
| 259 |
+
--neon-green: #00ff88;
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
/* Main container */
|
| 263 |
+
.contain {
|
| 264 |
+
background: #000000 !important;
|
| 265 |
+
max-width: 1400px !important;
|
| 266 |
+
margin: 0 auto !important;
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
/* Tabs */
|
| 270 |
+
.tab-nav {
|
| 271 |
+
background: #0a0a0a !important;
|
| 272 |
+
border-bottom: 2px solid var(--neon-pink) !important;
|
| 273 |
+
padding: 10px 0 !important;
|
| 274 |
}
|
| 275 |
|
|
|
|
| 276 |
.tab-nav button {
|
| 277 |
+
background: #1a1a1a !important;
|
| 278 |
+
border: 2px solid #222222 !important;
|
| 279 |
+
color: var(--neon-cyan) !important;
|
| 280 |
+
font-weight: 800 !important;
|
| 281 |
+
font-size: 15px !important;
|
| 282 |
+
text-transform: uppercase !important;
|
| 283 |
+
letter-spacing: 1.5px !important;
|
| 284 |
transition: all 0.3s ease !important;
|
| 285 |
+
margin: 0 5px !important;
|
| 286 |
+
padding: 12px 20px !important;
|
| 287 |
+
border-radius: 8px !important;
|
| 288 |
}
|
| 289 |
+
|
| 290 |
.tab-nav button:hover {
|
| 291 |
+
background: #252525 !important;
|
| 292 |
+
border-color: var(--neon-pink) !important;
|
| 293 |
+
color: var(--neon-pink) !important;
|
| 294 |
+
transform: translateY(-2px) !important;
|
| 295 |
+
box-shadow: 0 5px 20px rgba(255, 0, 128, 0.4) !important;
|
| 296 |
}
|
| 297 |
+
|
| 298 |
.tab-nav button.selected {
|
| 299 |
+
background: linear-gradient(135deg, var(--neon-pink) 0%, var(--neon-purple) 100%) !important;
|
| 300 |
+
border-color: var(--neon-pink) !important;
|
| 301 |
+
color: #000000 !important;
|
| 302 |
+
font-weight: 900 !important;
|
| 303 |
+
box-shadow: 0 0 30px rgba(255, 0, 128, 0.8) !important;
|
| 304 |
}
|
| 305 |
|
| 306 |
/* Input fields */
|
| 307 |
input, textarea, select {
|
| 308 |
+
background: #1a1a1a !important;
|
| 309 |
+
border: 2px solid #333333 !important;
|
| 310 |
+
color: #ffffff !important;
|
| 311 |
+
border-radius: 10px !important;
|
| 312 |
+
font-size: 16px !important;
|
| 313 |
+
padding: 14px !important;
|
| 314 |
+
transition: all 0.3s ease !important;
|
| 315 |
}
|
| 316 |
+
|
| 317 |
input:focus, textarea:focus, select:focus {
|
| 318 |
+
border-color: var(--neon-cyan) !important;
|
| 319 |
+
box-shadow: 0 0 25px rgba(0, 255, 255, 0.5) !important;
|
| 320 |
+
outline: none !important;
|
| 321 |
+
background: #222222 !important;
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
input::placeholder, textarea::placeholder {
|
| 325 |
+
color: #666666 !important;
|
| 326 |
}
|
| 327 |
|
| 328 |
/* Buttons */
|
| 329 |
button {
|
| 330 |
+
background: linear-gradient(135deg, var(--neon-pink) 0%, var(--neon-purple) 100%) !important;
|
| 331 |
border: none !important;
|
| 332 |
+
color: #000000 !important;
|
| 333 |
+
font-weight: 900 !important;
|
| 334 |
+
font-size: 16px !important;
|
| 335 |
+
text-transform: uppercase !important;
|
| 336 |
+
letter-spacing: 2px !important;
|
| 337 |
+
border-radius: 10px !important;
|
| 338 |
+
padding: 16px 32px !important;
|
| 339 |
transition: all 0.3s ease !important;
|
| 340 |
+
box-shadow: 0 5px 25px rgba(255, 0, 128, 0.4) !important;
|
| 341 |
+
cursor: pointer !important;
|
| 342 |
}
|
| 343 |
+
|
| 344 |
button:hover {
|
| 345 |
+
transform: translateY(-4px) scale(1.03) !important;
|
| 346 |
+
box-shadow: 0 10px 40px rgba(255, 0, 128, 0.7) !important;
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
button:active {
|
| 350 |
+
transform: translateY(-1px) scale(0.98) !important;
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
/* Secondary buttons */
|
| 354 |
+
button.secondary {
|
| 355 |
+
background: linear-gradient(135deg, var(--neon-cyan) 0%, var(--neon-green) 100%) !important;
|
| 356 |
}
|
| 357 |
|
| 358 |
/* Output boxes */
|
| 359 |
+
.output-markdown, .prose, .markdown {
|
| 360 |
+
background: #0a0a0a !important;
|
| 361 |
+
border: 2px solid #1a1a1a !important;
|
| 362 |
+
border-radius: 12px !important;
|
| 363 |
+
padding: 24px !important;
|
| 364 |
+
color: #e0e0e0 !important;
|
| 365 |
+
box-shadow: inset 0 0 30px rgba(0, 255, 255, 0.05) !important;
|
| 366 |
+
min-height: 100px !important;
|
| 367 |
}
|
| 368 |
|
| 369 |
/* Headers */
|
| 370 |
+
h1 {
|
| 371 |
+
background: linear-gradient(135deg, var(--neon-pink) 0%, var(--neon-cyan) 100%);
|
| 372 |
-webkit-background-clip: text;
|
| 373 |
-webkit-text-fill-color: transparent;
|
| 374 |
+
background-clip: text;
|
| 375 |
+
font-weight: 900 !important;
|
| 376 |
+
font-size: 56px !important;
|
| 377 |
+
text-transform: uppercase !important;
|
| 378 |
+
letter-spacing: 4px !important;
|
| 379 |
+
text-align: center !important;
|
| 380 |
+
margin: 30px 0 !important;
|
| 381 |
+
filter: drop-shadow(0 0 20px rgba(255, 0, 128, 0.5));
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
h2 {
|
| 385 |
+
color: var(--neon-cyan) !important;
|
| 386 |
font-weight: 800 !important;
|
| 387 |
+
font-size: 32px !important;
|
| 388 |
+
text-transform: lowercase !important;
|
| 389 |
+
letter-spacing: 1px !important;
|
| 390 |
+
margin: 20px 0 !important;
|
| 391 |
}
|
| 392 |
|
| 393 |
+
h3 {
|
| 394 |
+
color: var(--neon-pink) !important;
|
| 395 |
+
font-weight: 700 !important;
|
| 396 |
+
font-size: 24px !important;
|
| 397 |
+
margin: 16px 0 !important;
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
/* Paragraphs */
|
| 401 |
+
p {
|
| 402 |
+
color: #cccccc !important;
|
| 403 |
+
font-size: 16px !important;
|
| 404 |
+
line-height: 1.6 !important;
|
| 405 |
}
|
| 406 |
|
| 407 |
/* Links */
|
| 408 |
a {
|
| 409 |
+
color: var(--neon-cyan) !important;
|
| 410 |
text-decoration: none !important;
|
| 411 |
+
font-weight: 700 !important;
|
| 412 |
+
transition: all 0.3s ease !important;
|
| 413 |
}
|
| 414 |
+
|
| 415 |
a:hover {
|
| 416 |
+
color: var(--neon-pink) !important;
|
| 417 |
+
text-shadow: 0 0 15px rgba(255, 0, 128, 0.8) !important;
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
/* Code blocks */
|
| 421 |
+
code {
|
| 422 |
+
background: #1a1a1a !important;
|
| 423 |
+
color: var(--neon-green) !important;
|
| 424 |
+
padding: 4px 10px !important;
|
| 425 |
+
border-radius: 6px !important;
|
| 426 |
+
border: 1px solid var(--neon-cyan) !important;
|
| 427 |
+
font-family: 'Fira Code', 'Consolas', monospace !important;
|
| 428 |
+
font-size: 14px !important;
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
+
/* Horizontal rules */
|
| 432 |
+
hr {
|
| 433 |
+
border: none !important;
|
| 434 |
+
border-top: 2px solid var(--neon-pink) !important;
|
| 435 |
+
margin: 30px 0 !important;
|
| 436 |
+
opacity: 0.3 !important;
|
| 437 |
}
|
| 438 |
|
| 439 |
/* Scrollbar */
|
| 440 |
::-webkit-scrollbar {
|
| 441 |
+
width: 12px;
|
| 442 |
+
height: 12px;
|
| 443 |
}
|
| 444 |
+
|
| 445 |
::-webkit-scrollbar-track {
|
| 446 |
+
background: #0a0a0a;
|
| 447 |
+
border-radius: 10px;
|
| 448 |
}
|
| 449 |
+
|
| 450 |
::-webkit-scrollbar-thumb {
|
| 451 |
+
background: linear-gradient(135deg, var(--neon-pink) 0%, var(--neon-cyan) 100%);
|
| 452 |
border-radius: 10px;
|
| 453 |
+
border: 2px solid #000000;
|
| 454 |
}
|
| 455 |
+
|
| 456 |
::-webkit-scrollbar-thumb:hover {
|
| 457 |
+
background: linear-gradient(135deg, var(--neon-cyan) 0%, var(--neon-pink) 100%);
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
/* Labels */
|
| 461 |
+
label {
|
| 462 |
+
color: var(--neon-cyan) !important;
|
| 463 |
+
font-weight: 700 !important;
|
| 464 |
+
font-size: 13px !important;
|
| 465 |
+
text-transform: uppercase !important;
|
| 466 |
+
letter-spacing: 1.2px !important;
|
| 467 |
+
margin-bottom: 8px !important;
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
/* Chatbot styling */
|
| 471 |
+
.message-wrap {
|
| 472 |
+
background: #1a1a1a !important;
|
| 473 |
+
border: 1px solid #333333 !important;
|
| 474 |
+
border-radius: 12px !important;
|
| 475 |
+
margin: 8px 0 !important;
|
| 476 |
+
padding: 12px !important;
|
| 477 |
+
}
|
| 478 |
+
|
| 479 |
+
.message.user {
|
| 480 |
+
background: linear-gradient(135deg, var(--neon-pink) 0%, var(--neon-purple) 100%) !important;
|
| 481 |
+
color: #ffffff !important;
|
| 482 |
+
border-radius: 12px !important;
|
| 483 |
+
padding: 12px !important;
|
| 484 |
+
}
|
| 485 |
+
|
| 486 |
+
.message.bot {
|
| 487 |
+
background: #222222 !important;
|
| 488 |
+
border: 1px solid var(--neon-cyan) !important;
|
| 489 |
+
color: #ffffff !important;
|
| 490 |
+
border-radius: 12px !important;
|
| 491 |
+
padding: 12px !important;
|
| 492 |
+
}
|
| 493 |
+
|
| 494 |
+
/* Dropdown menus */
|
| 495 |
+
.dropdown-container {
|
| 496 |
+
background: #1a1a1a !important;
|
| 497 |
+
border: 2px solid #333333 !important;
|
| 498 |
+
border-radius: 10px !important;
|
| 499 |
+
}
|
| 500 |
+
|
| 501 |
+
/* Info/Warning boxes */
|
| 502 |
+
.info {
|
| 503 |
+
background: rgba(0, 255, 255, 0.1) !important;
|
| 504 |
+
border-left: 4px solid var(--neon-cyan) !important;
|
| 505 |
+
padding: 16px !important;
|
| 506 |
+
border-radius: 8px !important;
|
| 507 |
+
margin: 16px 0 !important;
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
.warning {
|
| 511 |
+
background: rgba(255, 0, 128, 0.1) !important;
|
| 512 |
+
border-left: 4px solid var(--neon-pink) !important;
|
| 513 |
+
padding: 16px !important;
|
| 514 |
+
border-radius: 8px !important;
|
| 515 |
+
margin: 16px 0 !important;
|
| 516 |
+
}
|
| 517 |
+
|
| 518 |
+
/* Loading animation */
|
| 519 |
+
@keyframes glow {
|
| 520 |
+
0%, 100% {
|
| 521 |
+
box-shadow: 0 0 20px var(--neon-pink), 0 0 40px var(--neon-pink);
|
| 522 |
+
}
|
| 523 |
+
50% {
|
| 524 |
+
box-shadow: 0 0 30px var(--neon-cyan), 0 0 60px var(--neon-cyan);
|
| 525 |
+
}
|
| 526 |
+
}
|
| 527 |
+
|
| 528 |
+
.loading {
|
| 529 |
+
animation: glow 2s ease-in-out infinite;
|
| 530 |
+
}
|
| 531 |
+
|
| 532 |
+
/* Strong/Bold text */
|
| 533 |
+
strong {
|
| 534 |
+
color: var(--neon-pink) !important;
|
| 535 |
+
font-weight: 800 !important;
|
| 536 |
+
}
|
| 537 |
+
|
| 538 |
+
/* Emphasis/Italic text */
|
| 539 |
+
em {
|
| 540 |
+
color: var(--neon-cyan) !important;
|
| 541 |
+
font-style: italic !important;
|
| 542 |
+
}
|
| 543 |
+
|
| 544 |
+
/* Lists */
|
| 545 |
+
ul, ol {
|
| 546 |
+
color: #cccccc !important;
|
| 547 |
+
padding-left: 30px !important;
|
| 548 |
+
}
|
| 549 |
+
|
| 550 |
+
li {
|
| 551 |
+
margin: 8px 0 !important;
|
| 552 |
}
|
|
|
|
| 553 |
|
| 554 |
+
/* Blockquotes */
|
| 555 |
+
blockquote {
|
| 556 |
+
border-left: 4px solid var(--neon-purple) !important;
|
| 557 |
+
padding-left: 20px !important;
|
| 558 |
+
color: #aaaaaa !important;
|
| 559 |
+
font-style: italic !important;
|
| 560 |
+
margin: 20px 0 !important;
|
| 561 |
+
}
|
| 562 |
+
"""
|
| 563 |
|
| 564 |
# ============================================
|
| 565 |
+
# π GRADIO INTERFACE
|
| 566 |
# ============================================
|
| 567 |
+
|
| 568 |
+
with gr.Blocks(css=custom_css, title="π SYNCHRONY - Student Portal", theme=gr.themes.Base()) as app:
|
| 569 |
+
|
| 570 |
+
# ============================================
|
| 571 |
+
# HEADER
|
| 572 |
+
# ============================================
|
| 573 |
+
gr.Markdown("""
|
| 574 |
+
# π SYNCHRONY
|
| 575 |
+
## *where students teach students* π«
|
| 576 |
+
|
| 577 |
+
---
|
| 578 |
+
""")
|
| 579 |
+
|
| 580 |
+
# ============================================
|
| 581 |
+
# TAB 1: HOME / LOGIN
|
| 582 |
+
# ============================================
|
| 583 |
+
with gr.Tab("π home"):
|
| 584 |
+
gr.Markdown("""
|
| 585 |
+
## welcome to synchrony β¨
|
| 586 |
+
|
| 587 |
+
*the ai-powered study platform where you learn by teaching each other*
|
| 588 |
+
""")
|
| 589 |
+
|
|
|
|
| 590 |
with gr.Row():
|
| 591 |
+
with gr.Column(scale=1):
|
| 592 |
+
gr.Markdown("""
|
| 593 |
+
### π new here?
|
| 594 |
+
|
| 595 |
+
join synchrony and get matched with your perfect study squad!
|
| 596 |
+
|
| 597 |
+
click below to fill out the registration form π
|
| 598 |
+
""")
|
| 599 |
+
|
| 600 |
+
register_btn = gr.Button("π REGISTER NOW", variant="primary", size="lg")
|
| 601 |
+
|
| 602 |
+
gr.Markdown("""
|
| 603 |
+
|
| 604 |
+
---
|
| 605 |
+
|
| 606 |
+
### π already registered?
|
| 607 |
+
|
| 608 |
+
enter your university email to access your study session
|
| 609 |
+
""")
|
| 610 |
+
|
| 611 |
+
email_input = gr.Textbox(
|
| 612 |
+
label="π§ university email",
|
| 613 |
+
placeholder="your.email@university.edu",
|
| 614 |
+
lines=1
|
| 615 |
+
)
|
| 616 |
+
|
| 617 |
+
login_btn = gr.Button("π LOGIN", variant="secondary", size="lg")
|
| 618 |
+
login_output = gr.Markdown(label="")
|
| 619 |
+
|
| 620 |
+
gr.Markdown("""
|
| 621 |
+
|
| 622 |
+
---
|
| 623 |
+
|
| 624 |
+
### π view database
|
| 625 |
+
|
| 626 |
+
check out the student database and see who's in synchrony!
|
| 627 |
+
""")
|
| 628 |
+
|
| 629 |
+
sheets_btn = gr.Button("π OPEN GOOGLE SHEETS", variant="secondary")
|
| 630 |
+
|
| 631 |
+
# Register button opens Google Form in new tab
|
| 632 |
+
register_btn.click(
|
| 633 |
+
fn=lambda: None,
|
| 634 |
+
js=f"() => window.open('{REGISTRATION_FORM}', '_blank')"
|
| 635 |
+
)
|
| 636 |
+
|
| 637 |
+
# Sheets button opens Google Sheets in new tab
|
| 638 |
+
sheets_btn.click(
|
| 639 |
+
fn=lambda: None,
|
| 640 |
+
js=f"() => window.open('{GOOGLE_SHEETS}', '_blank')"
|
| 641 |
+
)
|
| 642 |
+
|
| 643 |
+
# Login button
|
| 644 |
+
def handle_login(email):
|
| 645 |
+
success, message = lookup_student(email)
|
| 646 |
+
return message
|
| 647 |
+
|
| 648 |
+
login_btn.click(
|
| 649 |
+
fn=handle_login,
|
| 650 |
+
inputs=[email_input],
|
| 651 |
+
outputs=[login_output]
|
| 652 |
+
)
|
| 653 |
+
|
| 654 |
+
email_input.submit(
|
| 655 |
+
fn=handle_login,
|
| 656 |
+
inputs=[email_input],
|
| 657 |
+
outputs=[login_output]
|
| 658 |
+
)
|
| 659 |
+
|
| 660 |
+
# ============================================
|
| 661 |
+
# TAB 2: MY TEAM
|
| 662 |
+
# ============================================
|
| 663 |
+
with gr.Tab("π₯ my team"):
|
| 664 |
+
gr.Markdown("""
|
| 665 |
+
## your study squad π₯
|
| 666 |
+
|
| 667 |
+
meet your teammates and see what everyone's working on
|
| 668 |
+
""")
|
| 669 |
+
|
| 670 |
+
team_display = gr.Markdown(value="β οΈ please login first in the **HOME** tab!")
|
| 671 |
+
|
| 672 |
+
refresh_team_btn = gr.Button("π REFRESH TEAM INFO", variant="secondary")
|
| 673 |
+
|
| 674 |
+
refresh_team_btn.click(
|
| 675 |
+
fn=get_team_info,
|
| 676 |
+
outputs=[team_display]
|
| 677 |
+
)
|
| 678 |
+
|
| 679 |
+
# ============================================
|
| 680 |
+
# TAB 3: CHALLENGES
|
| 681 |
+
# ============================================
|
| 682 |
+
with gr.Tab("π― challenges"):
|
| 683 |
+
gr.Markdown("""
|
| 684 |
+
## your collaborative challenges πͺ
|
| 685 |
+
|
| 686 |
+
work together, learn from each other, level up!
|
| 687 |
+
|
| 688 |
+
*ai-generated challenges tailored to your group's topics*
|
| 689 |
+
""")
|
| 690 |
+
|
| 691 |
+
load_challenges_btn = gr.Button("π₯ LOAD CHALLENGES", variant="primary", size="lg")
|
| 692 |
+
challenges_display = gr.Markdown(value="β οΈ click the button above to load your challenges!")
|
| 693 |
+
|
| 694 |
+
load_challenges_btn.click(
|
| 695 |
+
fn=load_challenges,
|
| 696 |
+
outputs=[challenges_display]
|
| 697 |
+
)
|
| 698 |
+
|
| 699 |
+
# ============================================
|
| 700 |
+
# TAB 4: HINTS
|
| 701 |
+
# ============================================
|
| 702 |
+
with gr.Tab("π‘ hints"):
|
| 703 |
+
gr.Markdown("""
|
| 704 |
+
## need help? no worries! π€
|
| 705 |
+
|
| 706 |
+
synco's got your back with **adaptive hints**
|
| 707 |
+
|
| 708 |
+
**hint 1:** gentle nudge π€
|
| 709 |
+
**hint 2:** clearer guidance π
|
| 710 |
+
**hint 3:** almost there! π―
|
| 711 |
+
""")
|
| 712 |
+
|
| 713 |
with gr.Row():
|
| 714 |
+
challenge_select = gr.Dropdown(
|
| 715 |
+
label="π― select challenge",
|
| 716 |
+
choices=["1", "2", "3"],
|
| 717 |
+
value="1",
|
| 718 |
+
scale=1
|
| 719 |
+
)
|
| 720 |
+
|
| 721 |
+
hint_level_select = gr.Dropdown(
|
| 722 |
+
label="π‘ hint level",
|
| 723 |
+
choices=[
|
| 724 |
+
"1 - gentle nudge π€",
|
| 725 |
+
"2 - clearer guidance π",
|
| 726 |
+
"3 - almost there! π―"
|
| 727 |
+
],
|
| 728 |
+
value="1 - gentle nudge π€",
|
| 729 |
+
scale=2
|
| 730 |
+
)
|
| 731 |
+
|
| 732 |
+
get_hint_btn = gr.Button("π‘ GET HINT", variant="primary", size="lg")
|
| 733 |
+
hint_display = gr.Markdown(value="β οΈ select a challenge and hint level, then click the button!")
|
| 734 |
+
|
| 735 |
+
get_hint_btn.click(
|
| 736 |
+
fn=request_hint,
|
| 737 |
+
inputs=[challenge_select, hint_level_select],
|
| 738 |
+
outputs=[hint_display]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 739 |
)
|
| 740 |
+
|
| 741 |
+
# ============================================
|
| 742 |
+
# TAB 5: TEAM CHAT
|
| 743 |
+
# ============================================
|
| 744 |
+
with gr.Tab("π¬ chat"):
|
| 745 |
+
gr.Markdown("""
|
| 746 |
+
## team chat π¬
|
| 747 |
+
|
| 748 |
+
discuss challenges, share ideas, help each other out!
|
| 749 |
+
|
| 750 |
+
<div class="warning">
|
| 751 |
+
β οΈ <strong>demo mode:</strong> chat responses are simulated. in production, this would be real-time collaboration!
|
| 752 |
+
</div>
|
| 753 |
+
""")
|
| 754 |
+
|
| 755 |
+
chatbot = gr.Chatbot(
|
| 756 |
+
value=[],
|
| 757 |
+
label="",
|
| 758 |
+
height=450,
|
| 759 |
+
type="messages",
|
| 760 |
+
avatar_images=None
|
| 761 |
+
)
|
| 762 |
+
|
| 763 |
+
with gr.Row():
|
| 764 |
+
msg_input = gr.Textbox(
|
| 765 |
+
label="",
|
| 766 |
+
placeholder="type your message here...",
|
| 767 |
+
scale=5,
|
| 768 |
+
lines=1
|
| 769 |
+
)
|
| 770 |
+
send_btn = gr.Button("π€ SEND", variant="primary", scale=1)
|
| 771 |
+
|
| 772 |
+
send_btn.click(
|
| 773 |
+
fn=send_message,
|
| 774 |
+
inputs=[msg_input, chatbot],
|
| 775 |
+
outputs=[chatbot, msg_input]
|
| 776 |
+
)
|
| 777 |
+
|
| 778 |
+
msg_input.submit(
|
| 779 |
+
fn=send_message,
|
| 780 |
+
inputs=[msg_input, chatbot],
|
| 781 |
+
outputs=[chatbot, msg_input]
|
| 782 |
+
)
|
| 783 |
+
|
| 784 |
+
# ============================================
|
| 785 |
+
# TAB 6: ABOUT
|
| 786 |
+
# ============================================
|
| 787 |
+
with gr.Tab("βΉοΈ about"):
|
| 788 |
+
gr.Markdown(f"""
|
| 789 |
+
## π about synchrony
|
| 790 |
+
|
| 791 |
+
**synchrony** is an ai-powered collaborative learning platform that revolutionizes how students study together.
|
| 792 |
+
|
| 793 |
+
---
|
| 794 |
+
|
| 795 |
+
### β¨ what we do
|
| 796 |
+
|
| 797 |
+
β
**smart matching** - match students with complementary learning styles
|
| 798 |
+
β
**group formation** - create study groups based on chemistry scores
|
| 799 |
+
β
**ai challenges** - generate personalized collaborative challenges
|
| 800 |
+
β
**adaptive hints** - provide progressive learning support
|
| 801 |
+
β
**peer teaching** - students teach each other, reinforcing their knowledge
|
| 802 |
+
|
| 803 |
+
---
|
| 804 |
+
|
| 805 |
+
### π οΈ tech stack
|
| 806 |
+
|
| 807 |
+
- **frontend:** gradio (python)
|
| 808 |
+
- **backend:** n8n workflows
|
| 809 |
+
- **ai:** groq api (llama 3.3 70b)
|
| 810 |
+
- **database:** google sheets
|
| 811 |
+
- **matching:** chemistry score algorithm
|
| 812 |
+
|
| 813 |
+
---
|
| 814 |
+
|
| 815 |
+
### π links
|
| 816 |
+
|
| 817 |
+
- π [student registration form]({REGISTRATION_FORM})
|
| 818 |
+
- π [view database (google sheets)]({GOOGLE_SHEETS})
|
| 819 |
+
- π **webhook base:** `{BASE_URL}`
|
| 820 |
+
|
| 821 |
+
---
|
| 822 |
+
|
| 823 |
+
### π what's real vs demo
|
| 824 |
+
|
| 825 |
+
<div class="info">
|
| 826 |
+
β
<strong>fully functional:</strong>
|
| 827 |
+
<ul>
|
| 828 |
+
<li>student registration (google form β sheets)</li>
|
| 829 |
+
<li>ai challenge generation (groq api)</li>
|
| 830 |
+
<li>adaptive hints system (n8n + sheets)</li>
|
| 831 |
+
<li>team data from real api calls</li>
|
| 832 |
+
</ul>
|
| 833 |
+
</div>
|
| 834 |
+
|
| 835 |
+
<div class="warning">
|
| 836 |
+
π <strong>simulated for demo:</strong>
|
| 837 |
+
<ul>
|
| 838 |
+
<li>login system (assigns everyone to G001)</li>
|
| 839 |
+
<li>team chat (random responses)</li>
|
| 840 |
+
</ul>
|
| 841 |
+
|
| 842 |
+
<em>these would connect to authentication/real-time systems in production</em>
|
| 843 |
+
</div>
|
| 844 |
+
|
| 845 |
+
---
|
| 846 |
+
|
| 847 |
+
### π₯ created by
|
| 848 |
+
|
| 849 |
+
**maryam shanabli** | november 2025
|
| 850 |
+
|
| 851 |
+
*powered by ai β’ built for students β’ designed for impact* π
|
| 852 |
+
|
| 853 |
+
---
|
| 854 |
+
|
| 855 |
+
### π― project status
|
| 856 |
+
|
| 857 |
+
**current phase:** demo/prototype
|
| 858 |
+
**backend status:** fully operational β
|
| 859 |
+
**frontend status:** student portal (v2) β
|
| 860 |
+
**next steps:** real-time chat, authentication, mobile app
|
| 861 |
+
""")
|
| 862 |
+
|
| 863 |
+
# ============================================
|
| 864 |
+
# FOOTER
|
| 865 |
+
# ============================================
|
| 866 |
+
gr.Markdown("""
|
| 867 |
+
---
|
| 868 |
+
|
| 869 |
+
### π **synchrony** | *collaborative learning, powered by ai* π
|
| 870 |
+
|
| 871 |
+
made with π₯ by maryam shanabli | 2025
|
| 872 |
""")
|
| 873 |
|
|
|
|
| 874 |
# ============================================
|
| 875 |
+
# π LAUNCH APP
|
| 876 |
# ============================================
|
| 877 |
+
|
| 878 |
if __name__ == "__main__":
|
| 879 |
+
print("π Starting SYNCHRONY Student Portal...")
|
| 880 |
+
print(f"π‘ Connected to: {BASE_URL}")
|
| 881 |
+
print(f"π Registration: {REGISTRATION_FORM}")
|
| 882 |
+
print(f"π Database: {GOOGLE_SHEETS}")
|
| 883 |
+
print("β¨ All systems ready!")
|
| 884 |
+
|
| 885 |
app.launch(
|
| 886 |
server_name="0.0.0.0",
|
| 887 |
server_port=7860,
|
| 888 |
+
share=True, # Creates public shareable link
|
| 889 |
+
show_error=True,
|
| 890 |
+
favicon_path=None,
|
| 891 |
+
show_api=False
|
| 892 |
+
)
|