Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,8 +5,6 @@ import os
|
|
5 |
import sys
|
6 |
import json
|
7 |
|
8 |
-
# 환경 변수에서 OPENAI API 키 로드
|
9 |
-
OPENAI_API_KEY = "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"
|
10 |
|
11 |
def exception_handler(exception_type, exception, traceback):
|
12 |
print(f"{exception_type.__name__}: {exception}")
|
@@ -14,7 +12,6 @@ def exception_handler(exception_type, exception, traceback):
|
|
14 |
sys.excepthook = exception_handler
|
15 |
sys.tracebacklimit = 0
|
16 |
|
17 |
-
|
18 |
def get_chinese_hour(birth_hour):
|
19 |
hour = int(birth_hour[:2])
|
20 |
chinese_hours = ['자', '축', '인', '묘', '진', '사', '오', '미', '신', '유', '술', '해']
|
@@ -128,7 +125,6 @@ def get_lunar_info(solYear, solMonth, solDay, solHour):
|
|
128 |
else:
|
129 |
return {"Error": "API 호출에 실패했습니다."}, "정보 없음", "<p>API 호출에 실패했습니다.</p>"
|
130 |
|
131 |
-
# 성격과 특징을 분석하는 함수 수정 (API 키 인자 추가)
|
132 |
def analyze_character(lunIljin, OPENAI_API_KEY):
|
133 |
API_URL = "https://api.openai.com/v1/chat/completions"
|
134 |
payload = {
|
@@ -152,6 +148,7 @@ def analyze_character(lunIljin, OPENAI_API_KEY):
|
|
152 |
return f"오류가 발생했습니다. 상태 코드: {response.status_code}"
|
153 |
|
154 |
|
|
|
155 |
# 사주 분석 데이터 예시 (간소화된 버전)
|
156 |
사주_데이터 = {
|
157 |
'갑자(甲子)' : '새로운 시작의 상징, 리더십과 독립성이 특징이며, 호쾌하고 성실한 특성을 지닌다. ',
|
@@ -228,7 +225,8 @@ def 사주_분석(년주, 월주, 일주, 시주):
|
|
228 |
</div>
|
229 |
"""
|
230 |
return html_result
|
231 |
-
|
|
|
232 |
with gr.Blocks() as demo:
|
233 |
with gr.Tab("AI 사주 운세 분석"):
|
234 |
solYear = gr.Textbox(label="생년(예: 1990)")
|
@@ -236,12 +234,10 @@ with gr.Blocks() as demo:
|
|
236 |
solDay = gr.Textbox(label="생일(예: 31)")
|
237 |
solHour = gr.Textbox(label="생시(예시: 1030)", placeholder="시간을 24시간 형식으로 입력하세요 (예: 2230)")
|
238 |
output1 = gr.JSON(label="결과")
|
239 |
-
analysis_result = gr.HTML() # 사주 분석 결과를 출력할 HTML 컴포넌트
|
240 |
-
# 일주를 저장할 State
|
241 |
-
lunIljin_state = gr.State()
|
242 |
get_lunar_info_btn = gr.Button("분석하기")
|
243 |
|
244 |
-
# 버튼 클릭 이벤트 설정, outputs 순서에 맞게 수정
|
245 |
get_lunar_info_btn.click(
|
246 |
fn=get_lunar_info,
|
247 |
inputs=[solYear, solMonth, solDay, solHour],
|
@@ -252,7 +248,6 @@ with gr.Blocks() as demo:
|
|
252 |
OPENAI_API_KEY_input = gr.Textbox(label="OpenAI API 키", placeholder="여기에 OpenAI API 키를 입력하세요")
|
253 |
character_output = gr.Textbox(label="성격과 특징")
|
254 |
analyze_button = gr.Button("분석하기")
|
255 |
-
# analyze_character 함수를 호출할 때 lunIljin_state와 OPENAI_API_KEY_input를 입력으로 사용
|
256 |
analyze_button.click(fn=analyze_character, inputs=[lunIljin_state, OPENAI_API_KEY_input], outputs=character_output)
|
257 |
|
258 |
-
demo.launch()
|
|
|
5 |
import sys
|
6 |
import json
|
7 |
|
|
|
|
|
8 |
|
9 |
def exception_handler(exception_type, exception, traceback):
|
10 |
print(f"{exception_type.__name__}: {exception}")
|
|
|
12 |
sys.excepthook = exception_handler
|
13 |
sys.tracebacklimit = 0
|
14 |
|
|
|
15 |
def get_chinese_hour(birth_hour):
|
16 |
hour = int(birth_hour[:2])
|
17 |
chinese_hours = ['자', '축', '인', '묘', '진', '사', '오', '미', '신', '유', '술', '해']
|
|
|
125 |
else:
|
126 |
return {"Error": "API 호출에 실패했습니다."}, "정보 없음", "<p>API 호출에 실패했습니다.</p>"
|
127 |
|
|
|
128 |
def analyze_character(lunIljin, OPENAI_API_KEY):
|
129 |
API_URL = "https://api.openai.com/v1/chat/completions"
|
130 |
payload = {
|
|
|
148 |
return f"오류가 발생했습니다. 상태 코드: {response.status_code}"
|
149 |
|
150 |
|
151 |
+
|
152 |
# 사주 분석 데이터 예시 (간소화된 버전)
|
153 |
사주_데이터 = {
|
154 |
'갑자(甲子)' : '새로운 시작의 상징, 리더십과 독립성이 특징이며, 호쾌하고 성실한 특성을 지닌다. ',
|
|
|
225 |
</div>
|
226 |
"""
|
227 |
return html_result
|
228 |
+
|
229 |
+
|
230 |
with gr.Blocks() as demo:
|
231 |
with gr.Tab("AI 사주 운세 분석"):
|
232 |
solYear = gr.Textbox(label="생년(예: 1990)")
|
|
|
234 |
solDay = gr.Textbox(label="생일(예: 31)")
|
235 |
solHour = gr.Textbox(label="생시(예시: 1030)", placeholder="시간을 24시간 형식으로 입력하세요 (예: 2230)")
|
236 |
output1 = gr.JSON(label="결과")
|
237 |
+
analysis_result = gr.HTML() # 사주 분석 결과를 출력할 HTML 컴포넌트
|
238 |
+
lunIljin_state = gr.State() # 일주를 저장할 State
|
|
|
239 |
get_lunar_info_btn = gr.Button("분석하기")
|
240 |
|
|
|
241 |
get_lunar_info_btn.click(
|
242 |
fn=get_lunar_info,
|
243 |
inputs=[solYear, solMonth, solDay, solHour],
|
|
|
248 |
OPENAI_API_KEY_input = gr.Textbox(label="OpenAI API 키", placeholder="여기에 OpenAI API 키를 입력하세요")
|
249 |
character_output = gr.Textbox(label="성격과 특징")
|
250 |
analyze_button = gr.Button("분석하기")
|
|
|
251 |
analyze_button.click(fn=analyze_character, inputs=[lunIljin_state, OPENAI_API_KEY_input], outputs=character_output)
|
252 |
|
253 |
+
demo.launch()
|