Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -124,18 +124,82 @@ class SajuCalculator:
|
|
124 |
|
125 |
return daeun_list
|
126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
def calculate_saju(birth_date, birth_time, gender, birth_place):
|
128 |
"""사주 계산 메인 함수"""
|
129 |
try:
|
130 |
# 입력 검증
|
131 |
-
if not birth_date
|
132 |
-
return "❌
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
-
#
|
135 |
try:
|
136 |
-
birth_datetime = datetime
|
137 |
-
except ValueError:
|
138 |
-
return "❌
|
139 |
|
140 |
calculator = SajuCalculator()
|
141 |
|
@@ -162,7 +226,7 @@ def calculate_saju(birth_date, birth_time, gender, birth_place):
|
|
162 |
return result
|
163 |
|
164 |
except Exception as e:
|
165 |
-
return f"❌ 계산 중 오류가 발생했습니다: {str(e)}\n\n입력
|
166 |
|
167 |
def format_saju_result(ganzhi, elements, ten_gods, daeun, birth_datetime, gender, birth_place):
|
168 |
"""사주 결과 포맷팅"""
|
@@ -305,14 +369,14 @@ def create_interface():
|
|
305 |
|
306 |
birth_date = gr.Textbox(
|
307 |
label="생년월일",
|
308 |
-
placeholder="1990-
|
309 |
-
info="
|
310 |
)
|
311 |
|
312 |
birth_time = gr.Textbox(
|
313 |
-
label="태어난 시간",
|
314 |
-
placeholder="14:30",
|
315 |
-
info="
|
316 |
)
|
317 |
|
318 |
gender = gr.Radio(
|
@@ -347,7 +411,7 @@ def create_interface():
|
|
347 |
|
348 |
# 예시 데이터로 자동 실행
|
349 |
demo.load(
|
350 |
-
fn=lambda: calculate_saju("
|
351 |
outputs=result_output
|
352 |
)
|
353 |
|
|
|
124 |
|
125 |
return daeun_list
|
126 |
|
127 |
+
def parse_flexible_date(date_str):
|
128 |
+
"""유연한 날짜 파싱"""
|
129 |
+
import re
|
130 |
+
|
131 |
+
# 숫자만 추출
|
132 |
+
numbers = re.findall(r'\d+', date_str)
|
133 |
+
|
134 |
+
if len(numbers) >= 3:
|
135 |
+
year = int(numbers[0])
|
136 |
+
month = int(numbers[1])
|
137 |
+
day = int(numbers[2])
|
138 |
+
|
139 |
+
# 연도가 2자리인 경우 처리
|
140 |
+
if year < 100:
|
141 |
+
if year > 30: # 30 이상이면 19XX년
|
142 |
+
year += 1900
|
143 |
+
else: # 30 이하면 20XX년
|
144 |
+
year += 2000
|
145 |
+
|
146 |
+
return year, month, day
|
147 |
+
else:
|
148 |
+
raise ValueError("날짜 정보가 부족합니다.")
|
149 |
+
|
150 |
+
def parse_flexible_time(time_str):
|
151 |
+
"""유연한 시간 파싱"""
|
152 |
+
import re
|
153 |
+
|
154 |
+
# 숫자만 추출
|
155 |
+
numbers = re.findall(r'\d+', time_str)
|
156 |
+
|
157 |
+
if len(numbers) >= 1:
|
158 |
+
hour = int(numbers[0])
|
159 |
+
minute = int(numbers[1]) if len(numbers) >= 2 else 0
|
160 |
+
|
161 |
+
# 24시간 형식으로 변환
|
162 |
+
if hour > 24:
|
163 |
+
hour = hour % 24
|
164 |
+
|
165 |
+
return hour, minute
|
166 |
+
else:
|
167 |
+
return 12, 0 # 기본값
|
168 |
+
|
169 |
def calculate_saju(birth_date, birth_time, gender, birth_place):
|
170 |
"""사주 계산 메인 함수"""
|
171 |
try:
|
172 |
# 입력 검증
|
173 |
+
if not birth_date:
|
174 |
+
return "❌ 생년월일을 입력해주세요."
|
175 |
+
|
176 |
+
# 유연한 날짜 파싱
|
177 |
+
try:
|
178 |
+
year, month, day = parse_flexible_date(birth_date)
|
179 |
+
|
180 |
+
# 날짜 유효성 검사
|
181 |
+
if month < 1 or month > 12:
|
182 |
+
return f"❌ 월은 1~12 사이여야 합니다. 입력된 월: {month}"
|
183 |
+
if day < 1 or day > 31:
|
184 |
+
return f"❌ 일은 1~31 사이여야 합니다. 입력된 일: {day}"
|
185 |
+
|
186 |
+
except Exception as e:
|
187 |
+
return f"❌ 날짜 형식을 읽을 수 없습니다.\n다음과 같이 입력해보세요:\n- 1990-5-15 또는 19900515 또는 1990/5/15"
|
188 |
+
|
189 |
+
# 유연한 시간 파싱
|
190 |
+
if birth_time:
|
191 |
+
try:
|
192 |
+
hour, minute = parse_flexible_time(birth_time)
|
193 |
+
except:
|
194 |
+
hour, minute = 12, 0 # 기본값
|
195 |
+
else:
|
196 |
+
hour, minute = 12, 0 # 시간 입력이 없으면 정오로 설정
|
197 |
|
198 |
+
# datetime 객체 생성
|
199 |
try:
|
200 |
+
birth_datetime = datetime(year, month, day, hour, minute)
|
201 |
+
except ValueError as e:
|
202 |
+
return f"❌ 유효하지 않은 날짜입니다: {year}년 {month}월 {day}일\n{str(e)}"
|
203 |
|
204 |
calculator = SajuCalculator()
|
205 |
|
|
|
226 |
return result
|
227 |
|
228 |
except Exception as e:
|
229 |
+
return f"❌ 계산 중 오류가 발생했습니다: {str(e)}\n\n💡 입력 예시:\n- 생년월일: 19900515, 1990-5-15, 90515\n- 시간: 1430, 14:30, 오후2시30분"
|
230 |
|
231 |
def format_saju_result(ganzhi, elements, ten_gods, daeun, birth_datetime, gender, birth_place):
|
232 |
"""사주 결과 포맷팅"""
|
|
|
369 |
|
370 |
birth_date = gr.Textbox(
|
371 |
label="생년월일",
|
372 |
+
placeholder="19900515 또는 1990-5-15 또는 1990/5/15",
|
373 |
+
info="숫자만 입력해도 됩니다 (예: 19900515, 1990515, 90515)"
|
374 |
)
|
375 |
|
376 |
birth_time = gr.Textbox(
|
377 |
+
label="태어난 시간 (선택사항)",
|
378 |
+
placeholder="1430 또는 14:30 또는 오후2시30분",
|
379 |
+
info="숫자만 입력해도 됩니다 (예: 1430, 14시30분, 230). 비우면 정오(12시)로 설정"
|
380 |
)
|
381 |
|
382 |
gender = gr.Radio(
|
|
|
411 |
|
412 |
# 예시 데이터로 자동 실행
|
413 |
demo.load(
|
414 |
+
fn=lambda: calculate_saju("19900515", "1430", "남", "서울특별시"),
|
415 |
outputs=result_output
|
416 |
)
|
417 |
|