sdawdsdw commited on
Commit
d75ec6b
·
verified ·
1 Parent(s): 8b25b74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -29,12 +29,19 @@ def evaluate_trajectory_api(api_key: str, payload_json: str) -> str:
29
  except Exception as e:
30
  return json.dumps({"error": f"Malformed JSON: {e}", "status_code": 400})
31
 
32
- # 1. Calcul rapid
33
- report = evaluate_trajectories_batch(raw_payload, "standard", False)
 
 
 
 
 
 
 
 
34
  ai_markdown = generate_ai_report(report)
35
  report["narrative_report"] = ai_markdown
36
 
37
- # 2. Salvarea in DB se face pe fundal (non-blocking pentru utilizator!)
38
  if auth_ctx.get("project_id"):
39
  t = threading.Thread(
40
  target=save_evaluation_to_db,
@@ -43,10 +50,10 @@ def evaluate_trajectory_api(api_key: str, payload_json: str) -> str:
43
  )
44
  t.start()
45
 
46
- # 3. Returneaza instant rezultatul la client!
47
  return json.dumps(report)
48
 
49
 
 
50
  with gr.Blocks(title="Limina AI Engine") as demo:
51
  gr.Markdown("# Limina AI — Cognitive Trajectory Engine API")
52
  api_key_input = gr.Textbox(label="API Key", type="password")
 
29
  except Exception as e:
30
  return json.dumps({"error": f"Malformed JSON: {e}", "status_code": 400})
31
 
32
+ # AFLAM PLANUL UTILIZATORULUI DIN SUPABASE (ex: "free" sau "pro")
33
+ user_plan = auth_ctx.get("plan", "free")
34
+
35
+ # Trimitem planul catre functia de evaluare
36
+ report = evaluate_trajectories_batch(raw_payload, "standard", False, plan=user_plan)
37
+
38
+ # Daca a depasit limita de pasi pe free tier, returnam eroarea
39
+ if "error" in report:
40
+ return json.dumps(report)
41
+
42
  ai_markdown = generate_ai_report(report)
43
  report["narrative_report"] = ai_markdown
44
 
 
45
  if auth_ctx.get("project_id"):
46
  t = threading.Thread(
47
  target=save_evaluation_to_db,
 
50
  )
51
  t.start()
52
 
 
53
  return json.dumps(report)
54
 
55
 
56
+
57
  with gr.Blocks(title="Limina AI Engine") as demo:
58
  gr.Markdown("# Limina AI — Cognitive Trajectory Engine API")
59
  api_key_input = gr.Textbox(label="API Key", type="password")