lyi029 commited on
Commit
7eb06fd
·
1 Parent(s): 2fbdb13

performance

Browse files
Files changed (1) hide show
  1. app.py +44 -44
app.py CHANGED
@@ -957,50 +957,50 @@ def health():
957
  return {"status": "ok", "space_b_url": SPACE_B_URL, "model": MODEL_REPO}
958
 
959
 
960
- @app.get("/performance")
961
- async def performance():
962
- """
963
- 簡單回報目前的推論 performance 統計
964
- (目前只統計 /predict 的執行時間與呼叫次數)
965
- """
966
- avg_sec = (
967
- PERF_STATS["predict_total_seconds"] / PERF_STATS["predict_calls"]
968
- if PERF_STATS["predict_calls"] > 0 else 0.0
969
- )
970
-
971
- base_info = {
972
- "model_name": MODEL_REPO,
973
- "current_tag": CURRENT_TAG,
974
- "device": str(DEVICE),
975
- "som_available": SOM_AVAILABLE,
976
- "space_b_url": SPACE_B_URL,
977
- }
978
-
979
- perf_info = {
980
- "predict_calls": PERF_STATS["predict_calls"],
981
- "predict_total_seconds": PERF_STATS["predict_total_seconds"],
982
- "predict_avg_seconds": avg_sec,
983
- "predict_last_ms": PERF_STATS["predict_last_ms"],
984
- "predict_last_files": PERF_STATS["predict_last_files"],
985
- "last_updated": PERF_STATS["last_updated"],
986
- }
987
-
988
- # (可選)試著從 Space B 拿 performance(如果那邊有 /performance 的話)
989
- space_b_perf = None
990
- if SPACE_B_URL:
991
- try:
992
- async with httpx.AsyncClient(timeout=5.0) as client:
993
- r = await client.get(f"{SPACE_B_URL}/performance")
994
- if r.status_code == 200:
995
- space_b_perf = r.json()
996
- except Exception:
997
- space_b_perf = None
998
-
999
- return {
1000
- "base": base_info,
1001
- "space_a_performance": perf_info,
1002
- "space_b_performance": space_b_perf,
1003
- }
1004
 
1005
 
1006
  # ===== Hugging Face Space 啟動 =====
 
957
  return {"status": "ok", "space_b_url": SPACE_B_URL, "model": MODEL_REPO}
958
 
959
 
960
+ # @app.get("/performance")
961
+ # async def performance():
962
+ # """
963
+ # 簡單回報目前的推論 performance 統計
964
+ # (目前只統計 /predict 的執行時間與呼叫次數)
965
+ # """
966
+ # avg_sec = (
967
+ # PERF_STATS["predict_total_seconds"] / PERF_STATS["predict_calls"]
968
+ # if PERF_STATS["predict_calls"] > 0 else 0.0
969
+ # )
970
+
971
+ # base_info = {
972
+ # "model_name": MODEL_REPO,
973
+ # "current_tag": CURRENT_TAG,
974
+ # "device": str(DEVICE),
975
+ # "som_available": SOM_AVAILABLE,
976
+ # "space_b_url": SPACE_B_URL,
977
+ # }
978
+
979
+ # perf_info = {
980
+ # "predict_calls": PERF_STATS["predict_calls"],
981
+ # "predict_total_seconds": PERF_STATS["predict_total_seconds"],
982
+ # "predict_avg_seconds": avg_sec,
983
+ # "predict_last_ms": PERF_STATS["predict_last_ms"],
984
+ # "predict_last_files": PERF_STATS["predict_last_files"],
985
+ # "last_updated": PERF_STATS["last_updated"],
986
+ # }
987
+
988
+ # # (可選)試著從 Space B 拿 performance(如果那邊有 /performance 的話)
989
+ # space_b_perf = None
990
+ # if SPACE_B_URL:
991
+ # try:
992
+ # async with httpx.AsyncClient(timeout=5.0) as client:
993
+ # r = await client.get(f"{SPACE_B_URL}/performance")
994
+ # if r.status_code == 200:
995
+ # space_b_perf = r.json()
996
+ # except Exception:
997
+ # space_b_perf = None
998
+
999
+ # return {
1000
+ # "base": base_info,
1001
+ # "space_a_performance": perf_info,
1002
+ # "space_b_performance": space_b_perf,
1003
+ # }
1004
 
1005
 
1006
  # ===== Hugging Face Space 啟動 =====