dev-yuje commited on
Commit
d36d4ca
ยท
1 Parent(s): 61525d4

Fix feature mismatch and typos in credit_app.py

Browse files
Files changed (3) hide show
  1. .DS_Store +0 -0
  2. .gitignore +1 -0
  3. credit_app.py +28 -13
.DS_Store ADDED
Binary file (12.3 kB). View file
 
.gitignore CHANGED
@@ -2,3 +2,4 @@ models/preprocessor.pkl
2
  models/telecom_cb_model.keras
3
  __pycache__/
4
  .venv/
 
 
2
  models/telecom_cb_model.keras
3
  __pycache__/
4
  .venv/
5
+ .env
credit_app.py CHANGED
@@ -16,7 +16,7 @@ from predictors.score_prediction import predictor
16
  os.environ["GOOGLE_API_KEY"] = GEMINI_API_KEY
17
 
18
  # ==========================================
19
- # 1. ํ”ผ์ฒ˜ ์ •์˜
20
  # ==========================================
21
  FEATURES = {
22
  'C1Z001386': '1๋…„๋‚ด ์นด๋“œ ์ด ์ด์šฉ๊ธˆ์•ก (๋งŒ์›)',
@@ -24,16 +24,21 @@ FEATURES = {
24
  'C18210000': '์ฒดํฌ์นด๋“œ ๊ฑด์ˆ˜',
25
  'C1L120001': '์นด๋“œ ์ด ํ•œ๋„๊ธˆ์•ก (๋งŒ์›)',
26
  'C1L120004': '์นด๋“œ ๊ฐœ์„ค์ผ์ˆ˜',
 
 
 
 
 
 
27
  'D10110000': '์—ฐ์ฒด ๊ฑด์ˆ˜',
28
- 'D10113000': '์—ฐ์ฒด ์ž”์•ก (๋งŒ์›)',
29
- 'E1L210000': '์€ํ–‰์—…์ข… ๋Œ€์ถœ ๊ฑด์ˆ˜',
30
- 'E1L21B000': '๋‹ด๋ณด ๋Œ€์ถœ ๊ฑด์ˆ˜',
31
  'PERF1': '90์ผ ์—ฐ์ฒด ์—ฌ๋ถ€'
32
  }
33
 
34
  FEATURE_ORDER = [
35
  'C1Z001386', 'C1M210000', 'C18210000', 'C1L120001', 'C1L120004',
36
- 'D10110000', 'D10113000', 'E1L210000', 'E1L21B000', 'PERF1'
 
37
  ]
38
 
39
  # ==========================================
@@ -135,14 +140,24 @@ with gr.Blocks(title="KCB Credit AI", theme=gr.themes.Soft()) as demo:
135
  submit_btn = gr.Button("์ƒ๋‹ดํ•˜๊ธฐ", variant="primary", scale=1)
136
 
137
  def handle_predict(*args):
138
- ui_input_keys = [k for k in FEATURE_ORDER if k in FEATURES]
139
- features_dict = {}
140
- for i, key in enumerate(ui_input_keys):
141
- if key == 'PERF1': features_dict[key] = int(args[i])
142
- else: features_dict[key] = float(args[i]) if args[i] else 0.0
143
- score = predictor.predict(features_dict)
144
- display_score = int(min(max(round(score), 0), 1000))
145
- return {"features": features_dict, "score": display_score}, display_score
 
 
 
 
 
 
 
 
 
 
146
 
147
  def user_msg(user_message, history):
148
  if not user_message: return history, "", ""
 
16
  os.environ["GOOGLE_API_KEY"] = GEMINI_API_KEY
17
 
18
  # ==========================================
19
+ # 1. ํ”ผ์ฒ˜ ์ •์˜ (๋ชจ๋ธ์ด ํ•™์Šตํ•œ 14๊ฐœ ํ”ผ์ฒ˜์™€ ์ •ํ™•ํžˆ ์ผ์น˜ํ•ด์•ผ ํ•จ)
20
  # ==========================================
21
  FEATURES = {
22
  'C1Z001386': '1๋…„๋‚ด ์นด๋“œ ์ด ์ด์šฉ๊ธˆ์•ก (๋งŒ์›)',
 
24
  'C18210000': '์ฒดํฌ์นด๋“œ ๊ฑด์ˆ˜',
25
  'C1L120001': '์นด๋“œ ์ด ํ•œ๋„๊ธˆ์•ก (๋งŒ์›)',
26
  'C1L120004': '์นด๋“œ ๊ฐœ์„ค์ผ์ˆ˜',
27
+ 'L10210000': '์€ํ–‰๊ถŒ ๋Œ€์ถœ ๊ฑด์ˆ˜',
28
+ 'L90210100': '์€ํ–‰์—…์ข… ๋Œ€์ถœ ๊ฑด์ˆ˜',
29
+ 'L90210200': '์นด๋“œ์—…์ข… ๋Œ€์ถœ ๊ฑด์ˆ˜',
30
+ 'L10210B00': '๋ณดํ—˜์—…์ข… ๋Œ€์ถœ ๊ฑด์ˆ˜',
31
+ 'L10216000': '์‹ ์šฉ๋Œ€์ถœ ๊ฑด์ˆ˜',
32
+ 'L10217000': '๋‹ด๋ณด๋Œ€์ถœ ๊ฑด์ˆ˜',
33
  'D10110000': '์—ฐ์ฒด ๊ฑด์ˆ˜',
34
+ 'D10133000': '์ด ์—ฐ์ฒด ์ƒํ™˜๊ธˆ์•ก (๋งŒ์›)',
 
 
35
  'PERF1': '90์ผ ์—ฐ์ฒด ์—ฌ๋ถ€'
36
  }
37
 
38
  FEATURE_ORDER = [
39
  'C1Z001386', 'C1M210000', 'C18210000', 'C1L120001', 'C1L120004',
40
+ 'L10210000', 'L90210100', 'L90210200', 'L10210B00', 'L10216000',
41
+ 'L10217000', 'D10110000', 'D10133000', 'PERF1'
42
  ]
43
 
44
  # ==========================================
 
140
  submit_btn = gr.Button("์ƒ๋‹ดํ•˜๊ธฐ", variant="primary", scale=1)
141
 
142
  def handle_predict(*args):
143
+ try:
144
+ ui_input_keys = FEATURE_ORDER
145
+ features_dict = {}
146
+ for i, key in enumerate(ui_input_keys):
147
+ if key == 'PERF1': features_dict[key] = int(args[i])
148
+ else: features_dict[key] = float(args[i]) if args[i] else 0.0
149
+
150
+ score = predictor.predict(features_dict)
151
+
152
+ # score๊ฐ€ NaN์ธ ๊ฒฝ์šฐ 0์œผ๋กœ ์ฒ˜๋ฆฌ (์—๋Ÿฌ ๋ฐฉ์ง€)
153
+ if np.isnan(score):
154
+ return {"features": features_dict, "error": "Prediction returned NaN"}, 0
155
+
156
+ display_score = int(min(max(round(score), 0), 1000))
157
+ return {"features": features_dict, "score": display_score}, display_score
158
+ except Exception as e:
159
+ print(f"Prediction Error: {e}")
160
+ return {"features": {}, "error": str(e)}, 0
161
 
162
  def user_msg(user_message, history):
163
  if not user_message: return history, "", ""