seawolf2357 commited on
Commit
57d8237
β€’
1 Parent(s): da2d938

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -142,13 +142,22 @@ def analyze_character(lunIljin, OPENAI_API_KEY):
142
  "Content-Type": "application/json",
143
  "Authorization": f"Bearer {OPENAI_API_KEY}" # API ν‚€κ°€ μ •ν™•νžˆ μž…λ ₯λ˜μ—ˆλŠ”μ§€ 확인
144
  }
 
145
  response = requests.post(API_URL, headers=headers, json=payload)
 
146
  if response.status_code == 200:
147
  data = response.json()
148
  return data["choices"][0]["text"]
149
  else:
150
- return f"였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€. μƒνƒœ μ½”λ“œ: {response.status_code}"
151
-
 
 
 
 
 
 
 
152
 
153
  # 사주 뢄석 데이터 μ˜ˆμ‹œ (κ°„μ†Œν™”λœ 버전)
154
  사주_데이터 = {
 
142
  "Content-Type": "application/json",
143
  "Authorization": f"Bearer {OPENAI_API_KEY}" # API ν‚€κ°€ μ •ν™•νžˆ μž…λ ₯λ˜μ—ˆλŠ”μ§€ 확인
144
  }
145
+
146
  response = requests.post(API_URL, headers=headers, json=payload)
147
+
148
  if response.status_code == 200:
149
  data = response.json()
150
  return data["choices"][0]["text"]
151
  else:
152
+ # 였λ₯˜ λ©”μ‹œμ§€ λ°˜ν™˜ 방식 κ°œμ„ 
153
+ try:
154
+ error_data = response.json() # 였λ₯˜ 응닡이 JSON ν˜•νƒœμΈ 경우
155
+ error_message = error_data.get("error", {}).get("message", "API ν˜ΈμΆœμ— μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€.")
156
+ except ValueError:
157
+ error_message = "API 호좜 μ‹€νŒ¨: 응닡을 JSON으둜 νŒŒμ‹±ν•  수 μ—†μŠ΅λ‹ˆλ‹€."
158
+
159
+ return f"였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€. μƒνƒœ μ½”λ“œ: {response.status_code}, λ©”μ‹œμ§€: {error_message}"
160
+
161
 
162
  # 사주 뢄석 데이터 μ˜ˆμ‹œ (κ°„μ†Œν™”λœ 버전)
163
  사주_데이터 = {