Corin1998 commited on
Commit
3159a2b
·
verified ·
1 Parent(s): 3e2b12f

Update core/infer.py

Browse files
Files changed (1) hide show
  1. 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 that works both as package and script ---
5
- try:
6
- from .features import build_features
7
- from .normalize import robust_industry_z
8
- from .external_score import (
9
- get_external_template_df,
10
- apply_llm_signals_to_df,
11
- score_external_from_df,
12
- )
13
- from .ai_judgement import ai_evaluate, suggest_external_with_llm
14
- except ImportError:
15
- from core.features import build_features
16
- from core.normalize import robust_industry_z
17
- from core.external_score import (
18
- get_external_template_df,
19
- apply_llm_signals_to_df,
20
- score_external_from_df,
21
- )
22
- from core.ai_judgement import ai_evaluate, suggest_external_with_llm
 
 
 
 
 
 
 
 
 
 
 
 
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()