Spaces:
Sleeping
Sleeping
seawolf2357
commited on
Commit
β’
57d8237
1
Parent(s):
da2d938
Update app.py
Browse files
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 |
-
|
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 |
μ¬μ£Ό_λ°μ΄ν° = {
|