Update app.py
Browse files
app.py
CHANGED
@@ -667,66 +667,111 @@ def create_interface():
|
|
667 |
|
668 |
with gr.Column() as action_section:
|
669 |
set_baseline_btn = gr.Button("축원 마치기", variant="primary")
|
670 |
-
|
671 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
672 |
|
673 |
def handle_blessing_complete(audio, state):
|
674 |
"""축원 완료 및 분석 처리"""
|
675 |
if audio is None:
|
676 |
return (
|
677 |
state,
|
678 |
-
|
679 |
-
gr.update(visible=
|
680 |
-
gr.update(visible=
|
681 |
-
gr.update(visible=False)
|
|
|
|
|
|
|
682 |
)
|
683 |
|
684 |
try:
|
685 |
-
# 분석 시작
|
686 |
-
|
687 |
-
|
|
|
|
|
688 |
|
689 |
features = calculate_baseline_features(audio)
|
690 |
if features is None:
|
691 |
return (
|
692 |
state,
|
693 |
-
|
|
|
|
|
|
|
694 |
gr.update(visible=False),
|
695 |
gr.update(visible=True),
|
696 |
gr.update(visible=False)
|
697 |
)
|
698 |
|
699 |
-
# 감정 분석
|
700 |
-
status = gr.update(value="🔄 감정을 분석중입니다...", visible=True)
|
701 |
-
yield state, status, gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
|
702 |
-
|
703 |
baseline_emotion = map_acoustic_to_emotion(features)
|
704 |
|
705 |
-
# 분석 결과
|
706 |
-
|
707 |
-
f"
|
708 |
-
f"- 감정: {baseline_emotion['primary']}\n"
|
709 |
f"- 에너지 레벨: {baseline_emotion['details']['energy_level']}\n"
|
710 |
f"- 말하기 속도: {baseline_emotion['details']['speech_rate']}\n"
|
711 |
-
f"- 음높이 변화: {baseline_emotion['details']['pitch_variation']}\n
|
712 |
-
f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
713 |
)
|
714 |
|
715 |
# 상태 업데이트
|
716 |
-
new_state = safe_state_update(state, {
|
|
|
|
|
|
|
|
|
717 |
|
718 |
return (
|
719 |
new_state,
|
720 |
-
|
721 |
-
gr.update(
|
722 |
-
gr.update(visible=
|
723 |
-
gr.update(visible=True)
|
|
|
|
|
|
|
724 |
)
|
725 |
|
726 |
except Exception as e:
|
727 |
return (
|
728 |
state,
|
729 |
-
|
|
|
|
|
|
|
730 |
gr.update(visible=False),
|
731 |
gr.update(visible=True),
|
732 |
gr.update(visible=False)
|
@@ -992,7 +1037,10 @@ def create_interface():
|
|
992 |
outputs=[
|
993 |
state, # 상태
|
994 |
analysis_status, # 상태 메시지
|
995 |
-
|
|
|
|
|
|
|
996 |
blessing_section, # 축원 섹션
|
997 |
entry_guide_section # 가이드 섹션
|
998 |
]
|
|
|
667 |
|
668 |
with gr.Column() as action_section:
|
669 |
set_baseline_btn = gr.Button("축원 마치기", variant="primary")
|
670 |
+
|
671 |
+
# 분석 상태와 결과를 보여주는 섹션
|
672 |
+
with gr.Column(visible=True) as analysis_section:
|
673 |
+
analysis_status = gr.Markdown("")
|
674 |
+
loading_icon = gr.HTML("""
|
675 |
+
<div id="loading" style="display:none; text-align:center;">
|
676 |
+
<img src="https://i.gifer.com/ZKZx.gif" alt="loading..." style="width:50px; height:50px;">
|
677 |
+
</div>
|
678 |
+
""")
|
679 |
+
voice_features = gr.Textbox(
|
680 |
+
label="음성 특성 분석",
|
681 |
+
interactive=False,
|
682 |
+
visible=False
|
683 |
+
)
|
684 |
+
text_sentiment = gr.Textbox(
|
685 |
+
label="기본 감정 상태",
|
686 |
+
interactive=False,
|
687 |
+
visible=False
|
688 |
+
)
|
689 |
+
analysis_result = gr.Markdown("")
|
690 |
|
691 |
def handle_blessing_complete(audio, state):
|
692 |
"""축원 완료 및 분석 처리"""
|
693 |
if audio is None:
|
694 |
return (
|
695 |
state,
|
696 |
+
"음성을 먼저 녹음해주세요.",
|
697 |
+
gr.update(visible=True), # loading
|
698 |
+
gr.update(visible=False), # voice_features
|
699 |
+
gr.update(visible=False), # text_sentiment
|
700 |
+
gr.update(visible=False), # analysis_result
|
701 |
+
gr.update(visible=True), # blessing_section
|
702 |
+
gr.update(visible=False) # entry_guide_section
|
703 |
)
|
704 |
|
705 |
try:
|
706 |
+
# 분석 시작
|
707 |
+
loading = gr.update(visible=True)
|
708 |
+
status = "🔄 기준 음성을 분석중입니다..."
|
709 |
+
yield (state, status, loading, gr.update(visible=False), gr.update(visible=False),
|
710 |
+
gr.update(visible=False), gr.update(visible=True), gr.update(visible=False))
|
711 |
|
712 |
features = calculate_baseline_features(audio)
|
713 |
if features is None:
|
714 |
return (
|
715 |
state,
|
716 |
+
"❌ 음성 분석에 실패했습니다.",
|
717 |
+
gr.update(visible=False),
|
718 |
+
gr.update(visible=False),
|
719 |
+
gr.update(visible=False),
|
720 |
gr.update(visible=False),
|
721 |
gr.update(visible=True),
|
722 |
gr.update(visible=False)
|
723 |
)
|
724 |
|
725 |
+
# 감정 분석
|
|
|
|
|
|
|
726 |
baseline_emotion = map_acoustic_to_emotion(features)
|
727 |
|
728 |
+
# 기본 음성 특성 분석 결과
|
729 |
+
voice_features_text = (
|
730 |
+
f"음성 특성:\n"
|
|
|
731 |
f"- 에너지 레벨: {baseline_emotion['details']['energy_level']}\n"
|
732 |
f"- 말하기 속도: {baseline_emotion['details']['speech_rate']}\n"
|
733 |
+
f"- 음높이 변화: {baseline_emotion['details']['pitch_variation']}\n"
|
734 |
+
f"- 음성 크기: {baseline_emotion['details']['voice_volume']}"
|
735 |
+
)
|
736 |
+
|
737 |
+
sentiment_text = (
|
738 |
+
f"기본 감정 상태: {baseline_emotion['primary']}\n"
|
739 |
+
f"감정 강도: {baseline_emotion['intensity']:.1f}%\n"
|
740 |
+
f"특징: {', '.join(baseline_emotion['characteristics'])}"
|
741 |
+
)
|
742 |
+
|
743 |
+
# 최종 분석 결과
|
744 |
+
analysis_text = (
|
745 |
+
f"✨ 기준 음성 분석이 완료되었습니다.\n\n"
|
746 |
+
f"이 음성 특성을 기준으로 이후의 감정 변화를 분석합니다.\n"
|
747 |
+
f"청신 단계에서 마음을 정화하신 후 기원을 진행해주세요."
|
748 |
)
|
749 |
|
750 |
# 상태 업데이트
|
751 |
+
new_state = safe_state_update(state, {
|
752 |
+
"baseline_features": features,
|
753 |
+
"baseline_emotion": baseline_emotion,
|
754 |
+
"analysis_complete": True
|
755 |
+
})
|
756 |
|
757 |
return (
|
758 |
new_state,
|
759 |
+
"✅ 축원이 완료되었습니다. 이제 청신 단계로 진행해주세요.",
|
760 |
+
gr.update(visible=False), # loading
|
761 |
+
gr.update(value=voice_features_text, visible=True), # voice_features
|
762 |
+
gr.update(value=sentiment_text, visible=True), # text_sentiment
|
763 |
+
gr.update(value=analysis_text, visible=True), # analysis_result
|
764 |
+
gr.update(visible=False), # blessing_section
|
765 |
+
gr.update(visible=True) # entry_guide_section
|
766 |
)
|
767 |
|
768 |
except Exception as e:
|
769 |
return (
|
770 |
state,
|
771 |
+
f"❌ 오류가 발생했습니다: {str(e)}",
|
772 |
+
gr.update(visible=False),
|
773 |
+
gr.update(visible=False),
|
774 |
+
gr.update(visible=False),
|
775 |
gr.update(visible=False),
|
776 |
gr.update(visible=True),
|
777 |
gr.update(visible=False)
|
|
|
1037 |
outputs=[
|
1038 |
state, # 상태
|
1039 |
analysis_status, # 상태 메시지
|
1040 |
+
loading_icon, # 로딩 아이콘
|
1041 |
+
voice_features, # 음성 특성 분석
|
1042 |
+
text_sentiment, # 기본 감정 상태
|
1043 |
+
analysis_result, # 최종 분석 결과
|
1044 |
blessing_section, # 축원 섹션
|
1045 |
entry_guide_section # 가이드 섹션
|
1046 |
]
|