Update app.py
Browse files
app.py
CHANGED
|
@@ -391,9 +391,6 @@ def safe_state_update(state, updates):
|
|
| 391 |
print(f"State update error: {e}")
|
| 392 |
return state
|
| 393 |
|
| 394 |
-
# 상태 업데이트 시 사용
|
| 395 |
-
state = safe_state_update(state, {"user_name": name})
|
| 396 |
-
|
| 397 |
def create_interface():
|
| 398 |
db = SimpleDB()
|
| 399 |
|
|
@@ -446,7 +443,7 @@ def create_interface():
|
|
| 446 |
label="축원 문장 녹음하기",
|
| 447 |
sources=["microphone"],
|
| 448 |
type="numpy",
|
| 449 |
-
streaming=False
|
| 450 |
min_width=300, # 최소 너비 설정
|
| 451 |
elem_id="audio-recorder" # CSS 식별자 추가
|
| 452 |
)
|
|
@@ -524,7 +521,7 @@ def create_interface():
|
|
| 524 |
generate_btn = gr.Button("마음의 그림 그리기", variant="primary")
|
| 525 |
result_image = gr.Image(
|
| 526 |
label="생성된 이미지",
|
| 527 |
-
show_download_button=True
|
| 528 |
min_width=300,
|
| 529 |
elem_id="result-image"
|
| 530 |
)
|
|
@@ -564,21 +561,26 @@ def create_interface():
|
|
| 564 |
current_state,
|
| 565 |
gr.update(selected=1) # 축원 탭(두 번째 탭)으로 이동
|
| 566 |
)
|
|
|
|
| 567 |
def handle_baseline(audio, current_state):
|
| 568 |
if audio is None:
|
| 569 |
-
return current_state, "음성을 먼저 녹음해주세요."
|
| 570 |
|
| 571 |
try:
|
| 572 |
sr, y = audio
|
| 573 |
-
y = y.astype(np.float32)
|
| 574 |
features = calculate_baseline_features((sr, y))
|
| 575 |
if features:
|
| 576 |
current_state = {**current_state, "baseline_features": features}
|
| 577 |
-
return
|
| 578 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 579 |
except Exception as e:
|
| 580 |
print(f"Baseline error: {str(e)}")
|
| 581 |
-
return current_state, "오류가 발생했습니다. 다시 시도해주세요."
|
| 582 |
|
| 583 |
# 음악 재생 이벤트 핸들러 수정
|
| 584 |
def play_music():
|
|
@@ -655,7 +657,7 @@ def create_interface():
|
|
| 655 |
set_baseline_btn.click(
|
| 656 |
fn=handle_baseline,
|
| 657 |
inputs=[baseline_audio, state],
|
| 658 |
-
outputs=[state, baseline_status]
|
| 659 |
)
|
| 660 |
|
| 661 |
play_music_btn.click(
|
|
|
|
| 391 |
print(f"State update error: {e}")
|
| 392 |
return state
|
| 393 |
|
|
|
|
|
|
|
|
|
|
| 394 |
def create_interface():
|
| 395 |
db = SimpleDB()
|
| 396 |
|
|
|
|
| 443 |
label="축원 문장 녹음하기",
|
| 444 |
sources=["microphone"],
|
| 445 |
type="numpy",
|
| 446 |
+
streaming=False,
|
| 447 |
min_width=300, # 최소 너비 설정
|
| 448 |
elem_id="audio-recorder" # CSS 식별자 추가
|
| 449 |
)
|
|
|
|
| 521 |
generate_btn = gr.Button("마음의 그림 그리기", variant="primary")
|
| 522 |
result_image = gr.Image(
|
| 523 |
label="생성된 이미지",
|
| 524 |
+
show_download_button=True,
|
| 525 |
min_width=300,
|
| 526 |
elem_id="result-image"
|
| 527 |
)
|
|
|
|
| 561 |
current_state,
|
| 562 |
gr.update(selected=1) # 축원 탭(두 번째 탭)으로 이동
|
| 563 |
)
|
| 564 |
+
|
| 565 |
def handle_baseline(audio, current_state):
|
| 566 |
if audio is None:
|
| 567 |
+
return current_state, "음성을 먼저 녹음해주세요.", gr.update(selected=1) # 현재 탭 유지
|
| 568 |
|
| 569 |
try:
|
| 570 |
sr, y = audio
|
| 571 |
+
y = y.astype(np.float32)
|
| 572 |
features = calculate_baseline_features((sr, y))
|
| 573 |
if features:
|
| 574 |
current_state = {**current_state, "baseline_features": features}
|
| 575 |
+
return (
|
| 576 |
+
current_state,
|
| 577 |
+
"기준점이 설정되었습니다. 청신 탭으로 이동합니다.",
|
| 578 |
+
gr.update(selected=2) # 청신 탭으로 이동
|
| 579 |
+
)
|
| 580 |
+
return current_state, "기준점 설정에 실패했습니다. 다시 시도해주세요.", gr.update(selected=1)
|
| 581 |
except Exception as e:
|
| 582 |
print(f"Baseline error: {str(e)}")
|
| 583 |
+
return current_state, "오류가 발생했습니다. 다시 시도해주세요.", gr.update(selected=1)
|
| 584 |
|
| 585 |
# 음악 재생 이벤트 핸들러 수정
|
| 586 |
def play_music():
|
|
|
|
| 657 |
set_baseline_btn.click(
|
| 658 |
fn=handle_baseline,
|
| 659 |
inputs=[baseline_audio, state],
|
| 660 |
+
outputs=[state, baseline_status, tabs] # tabs 추가
|
| 661 |
)
|
| 662 |
|
| 663 |
play_music_btn.click(
|