lanna_lalala;- commited on
Commit
2950f9c
·
1 Parent(s): 3958d92

init frontend

Browse files
Files changed (2) hide show
  1. app.py +7 -2
  2. utils/api.py +5 -0
app.py CHANGED
@@ -12,11 +12,16 @@ from dashboards import student_db,teacher_db
12
  from phase.Student_view import chatbot, lesson, quiz, game, teacherlink
13
  from phase.Teacher_view import classmanage,studentlist,contentmanage
14
  from phase.Student_view.games import profitpuzzle
15
- from utils import db
16
  import os
17
 
18
 
19
-
 
 
 
 
 
20
  # --- SESSION STATE INITIALIZATION ---
21
  for key, default in [("user", None), ("current_page", "Welcome"),
22
  ("xp", 2450), ("streak", 7), ("current_game", None),
 
12
  from phase.Student_view import chatbot, lesson, quiz, game, teacherlink
13
  from phase.Teacher_view import classmanage,studentlist,contentmanage
14
  from phase.Student_view.games import profitpuzzle
15
+ from utils import db,api
16
  import os
17
 
18
 
19
+ try:
20
+ ok = api.health().get("ok")
21
+ st.sidebar.success("Backend: UP") if ok else st.sidebar.warning("Backend: ?")
22
+ except Exception as e:
23
+ st.sidebar.error(f"Backend DOWN: {e}")
24
+
25
  # --- SESSION STATE INITIALIZATION ---
26
  for key, default in [("user", None), ("current_page", "Welcome"),
27
  ("xp", 2450), ("streak", 7), ("current_game", None),
utils/api.py CHANGED
@@ -6,6 +6,11 @@ if not BACKEND:
6
  raise RuntimeError("BACKEND_URL is not set in Space secrets.")
7
  BACKEND = BACKEND.rstrip("/")
8
 
 
 
 
 
 
9
  def start_agent(student_id:int, lesson_id:int, level_slug:str):
10
  r = requests.post(f"{BACKEND}/agent/start", json={"student_id":student_id,"lesson_id":lesson_id,"level_slug":level_slug})
11
  r.raise_for_status()
 
6
  raise RuntimeError("BACKEND_URL is not set in Space secrets.")
7
  BACKEND = BACKEND.rstrip("/")
8
 
9
+ def health():
10
+ r = requests.get(f"{BACKEND}/health", timeout=10)
11
+ r.raise_for_status()
12
+ return r.json()
13
+
14
  def start_agent(student_id:int, lesson_id:int, level_slug:str):
15
  r = requests.post(f"{BACKEND}/agent/start", json={"student_id":student_id,"lesson_id":lesson_id,"level_slug":level_slug})
16
  r.raise_for_status()