Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -125,7 +125,6 @@ def get_lunar_info(solYear, solMonth, solDay, solHour):
|
|
125 |
else:
|
126 |
return {"Error": "API νΈμΆμ μ€ν¨νμ΅λλ€."}, "μ 보 μμ", "<p>API νΈμΆμ μ€ν¨νμ΅λλ€.</p>"
|
127 |
|
128 |
-
|
129 |
# B λ°μ΄ν°λ₯Ό νμ©νλ ν¨μ μΆκ°
|
130 |
def get_famous_people(lunIljin):
|
131 |
famous_people = {
|
@@ -146,7 +145,6 @@ def get_famous_people(lunIljin):
|
|
146 |
}
|
147 |
return famous_people.get(lunIljin, "ν΄λΉ μΌμ£Όμ λν μ λͺ
μΈ μ λ³΄κ° μμ΅λλ€.")
|
148 |
|
149 |
-
|
150 |
def analyze_character(lunIljin, OPENAI_API_KEY):
|
151 |
API_URL = "https://api.openai.com/v1/chat/completions"
|
152 |
payload = {
|
@@ -166,13 +164,12 @@ def analyze_character(lunIljin, OPENAI_API_KEY):
|
|
166 |
response = requests.post(API_URL, headers=headers, json=payload)
|
167 |
if response.status_code == 200:
|
168 |
data = response.json()
|
169 |
-
# λνν API μλ΅μμ μ μ ν λ©μμ§ μΆμΆ
|
170 |
-
return
|
171 |
else:
|
172 |
# μ€λ₯ λ©μμ§ κ°μ
|
173 |
-
return f"μ€λ₯κ° λ°μνμ΅λλ€. μν μ½λ: {response.status_code}, λ©μμ§: {response.json().get('error', {}).get('message', 'Unknown error')}"
|
174 |
|
175 |
-
|
176 |
|
177 |
# μ¬μ£Ό λΆμ λ°μ΄ν° μμ (κ°μνλ λ²μ )
|
178 |
μ¬μ£Ό_λ°μ΄ν° = {
|
@@ -252,9 +249,6 @@ def μ¬μ£Ό_λΆμ(λ
μ£Ό, μμ£Ό, μΌμ£Ό, μμ£Ό):
|
|
252 |
return html_result
|
253 |
|
254 |
|
255 |
-
def analyze_character(lunIljin_state, OPENAI_API_KEY):
|
256 |
-
# μ¬κΈ°μ μ±κ²©κ³Ό νΉμ§μ λΆμνλ ν¨μμ λ΄μ©μ ꡬννμΈμ.
|
257 |
-
pass
|
258 |
with gr.Blocks() as demo:
|
259 |
with gr.Tab("AI μ¬μ£Ό μ΄μΈ λΆμ"):
|
260 |
solYear = gr.Textbox(label="μλ
(μ: 1990)")
|
@@ -280,9 +274,7 @@ with gr.Blocks() as demo:
|
|
280 |
|
281 |
analyze_button = gr.Button("λΆμνκΈ°")
|
282 |
analyze_button.click(fn=analyze_character, inputs=[lunIljin_state, OPENAI_API_KEY_input], outputs=[character_output, celebrity_output])
|
283 |
-
|
284 |
-
# μ λͺ
μΈ λΆμμ κ°μ νμ μΆκ°
|
285 |
-
|
286 |
|
|
|
287 |
|
288 |
demo.launch()
|
|
|
125 |
else:
|
126 |
return {"Error": "API νΈμΆμ μ€ν¨νμ΅λλ€."}, "μ 보 μμ", "<p>API νΈμΆμ μ€ν¨νμ΅λλ€.</p>"
|
127 |
|
|
|
128 |
# B λ°μ΄ν°λ₯Ό νμ©νλ ν¨μ μΆκ°
|
129 |
def get_famous_people(lunIljin):
|
130 |
famous_people = {
|
|
|
145 |
}
|
146 |
return famous_people.get(lunIljin, "ν΄λΉ μΌμ£Όμ λν μ λͺ
μΈ μ λ³΄κ° μμ΅λλ€.")
|
147 |
|
|
|
148 |
def analyze_character(lunIljin, OPENAI_API_KEY):
|
149 |
API_URL = "https://api.openai.com/v1/chat/completions"
|
150 |
payload = {
|
|
|
164 |
response = requests.post(API_URL, headers=headers, json=payload)
|
165 |
if response.status_code == 200:
|
166 |
data = response.json()
|
167 |
+
# λνν API μλ΅μμ μ μ ν λ©μμ§ μΆμΆ λ° μ λͺ
μΈ μ΄λ¦ λ°ν
|
168 |
+
return data["choices"][0]["message"]["content"], get_famous_people(lunIljin)
|
169 |
else:
|
170 |
# μ€λ₯ λ©μμ§ κ°μ
|
171 |
+
return f"μ€λ₯κ° λ°μνμ΅λλ€. μν μ½λ: {response.status_code}, λ©μμ§: {response.json().get('error', {}).get('message', 'Unknown error')}", ""
|
172 |
|
|
|
173 |
|
174 |
# μ¬μ£Ό λΆμ λ°μ΄ν° μμ (κ°μνλ λ²μ )
|
175 |
μ¬μ£Ό_λ°μ΄ν° = {
|
|
|
249 |
return html_result
|
250 |
|
251 |
|
|
|
|
|
|
|
252 |
with gr.Blocks() as demo:
|
253 |
with gr.Tab("AI μ¬μ£Ό μ΄μΈ λΆμ"):
|
254 |
solYear = gr.Textbox(label="μλ
(μ: 1990)")
|
|
|
274 |
|
275 |
analyze_button = gr.Button("λΆμνκΈ°")
|
276 |
analyze_button.click(fn=analyze_character, inputs=[lunIljin_state, OPENAI_API_KEY_input], outputs=[character_output, celebrity_output])
|
|
|
|
|
|
|
277 |
|
278 |
+
|
279 |
|
280 |
demo.launch()
|