Spaces:
Runtime error
Runtime error
Update core/infer.py
Browse files- core/infer.py +33 -19
core/infer.py
CHANGED
|
@@ -1,25 +1,38 @@
|
|
| 1 |
import numpy as np, pandas as pd
|
| 2 |
import shap
|
|
|
|
| 3 |
|
| 4 |
-
# --- import
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
)
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
# ---------------------------------------------------
|
| 24 |
|
| 25 |
Z_BASE = ["opm","npm","cur_ratio","eq_ratio","de","ocf_sales"]
|
|
@@ -72,6 +85,7 @@ class InferenceService:
|
|
| 72 |
+ self.weights["ai"]*ai["ai_total"]
|
| 73 |
)
|
| 74 |
|
|
|
|
| 75 |
try:
|
| 76 |
sv = self.explainer.shap_values(df[self.feats])
|
| 77 |
shap_vals = (sv[0][0] if isinstance(sv, list) else sv[0]).tolist()
|
|
|
|
| 1 |
import numpy as np, pandas as pd
|
| 2 |
import shap
|
| 3 |
+
import os, importlib.util
|
| 4 |
|
| 5 |
+
# --- robust import of sibling modules ---
|
| 6 |
+
def _import_sibling(mod_name: str, filename: str):
|
| 7 |
+
try:
|
| 8 |
+
return __import__(f"{__package__}.{mod_name}", fromlist=[mod_name]) # relative
|
| 9 |
+
except Exception:
|
| 10 |
+
pass
|
| 11 |
+
try:
|
| 12 |
+
return __import__(f"core.{mod_name}", fromlist=[mod_name]) # absolute
|
| 13 |
+
except Exception:
|
| 14 |
+
pass
|
| 15 |
+
cur_dir = os.path.dirname(os.path.abspath(__file__))
|
| 16 |
+
path = os.path.join(cur_dir, filename)
|
| 17 |
+
spec = importlib.util.spec_from_file_location(mod_name, path)
|
| 18 |
+
if spec and spec.loader:
|
| 19 |
+
m = importlib.util.module_from_spec(spec)
|
| 20 |
+
spec.loader.exec_module(m)
|
| 21 |
+
return m
|
| 22 |
+
raise ImportError(f"Failed to import sibling module '{mod_name}'")
|
| 23 |
+
|
| 24 |
+
_features = _import_sibling("features", "features.py")
|
| 25 |
+
_normalize = _import_sibling("normalize", "normalize.py")
|
| 26 |
+
_external = _import_sibling("external_score", "external_score.py")
|
| 27 |
+
_ai = _import_sibling("ai_judgement", "ai_judgement.py")
|
| 28 |
+
|
| 29 |
+
build_features = _features.build_features
|
| 30 |
+
robust_industry_z = _normalize.robust_industry_z
|
| 31 |
+
get_external_template_df = _external.get_external_template_df
|
| 32 |
+
apply_llm_signals_to_df = _external.apply_llm_signals_to_df
|
| 33 |
+
score_external_from_df = _external.score_external_from_df
|
| 34 |
+
ai_evaluate = _ai.ai_evaluate
|
| 35 |
+
suggest_external_with_llm = _ai.suggest_external_with_llm
|
| 36 |
# ---------------------------------------------------
|
| 37 |
|
| 38 |
Z_BASE = ["opm","npm","cur_ratio","eq_ratio","de","ocf_sales"]
|
|
|
|
| 85 |
+ self.weights["ai"]*ai["ai_total"]
|
| 86 |
)
|
| 87 |
|
| 88 |
+
# SHAPの両対応
|
| 89 |
try:
|
| 90 |
sv = self.explainer.shap_values(df[self.feats])
|
| 91 |
shap_vals = (sv[0][0] if isinstance(sv, list) else sv[0]).tolist()
|