Update app.py
Browse files
app.py
CHANGED
@@ -621,6 +621,21 @@ def create_interface():
|
|
621 |
.gradio-button:active {
|
622 |
transform: scale(0.98);
|
623 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
624 |
"""
|
625 |
|
626 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as app:
|
@@ -689,12 +704,11 @@ def create_interface():
|
|
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=
|
698 |
gr.update(visible=False), # voice_features
|
699 |
gr.update(visible=False), # text_sentiment
|
700 |
gr.update(visible=False), # analysis_result
|
@@ -703,11 +717,17 @@ def create_interface():
|
|
703 |
)
|
704 |
|
705 |
try:
|
706 |
-
# 분석 시작
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
711 |
|
712 |
features = calculate_baseline_features(audio)
|
713 |
if features is None:
|
@@ -722,30 +742,44 @@ def create_interface():
|
|
722 |
gr.update(visible=False)
|
723 |
)
|
724 |
|
725 |
-
# 감정 분석
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
726 |
baseline_emotion = map_acoustic_to_emotion(features)
|
727 |
|
728 |
-
#
|
729 |
-
voice_features_text =
|
730 |
-
|
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 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
749 |
|
750 |
# 상태 업데이트
|
751 |
new_state = safe_state_update(state, {
|
@@ -754,15 +788,16 @@ def create_interface():
|
|
754 |
"analysis_complete": True
|
755 |
})
|
756 |
|
|
|
757 |
return (
|
758 |
new_state,
|
759 |
"✅ 축원이 완료되었습니다. 이제 청신 단계로 진행해주세요.",
|
760 |
-
gr.update(visible=False),
|
761 |
-
gr.update(value=voice_features_text, visible=True),
|
762 |
-
gr.update(value=sentiment_text, visible=True),
|
763 |
-
gr.update(value=analysis_text, visible=True),
|
764 |
-
gr.update(visible=False),
|
765 |
-
gr.update(visible=True)
|
766 |
)
|
767 |
|
768 |
except Exception as e:
|
@@ -776,7 +811,7 @@ def create_interface():
|
|
776 |
gr.update(visible=True),
|
777 |
gr.update(visible=False)
|
778 |
)
|
779 |
-
|
780 |
# 4단계: 굿판 입장 안내
|
781 |
entry_guide_section = gr.Column(visible=False)
|
782 |
with entry_guide_section:
|
|
|
621 |
.gradio-button:active {
|
622 |
transform: scale(0.98);
|
623 |
}
|
624 |
+
.loader {
|
625 |
+
width: 48px;
|
626 |
+
height: 48px;
|
627 |
+
border: 5px solid #FFF;
|
628 |
+
border-bottom-color: #FF3D00;
|
629 |
+
border-radius: 50%;
|
630 |
+
display: inline-block;
|
631 |
+
box-sizing: border-box;
|
632 |
+
animation: rotation 1s linear infinite;
|
633 |
+
}
|
634 |
+
|
635 |
+
@keyframes rotation {
|
636 |
+
0% { transform: rotate(0deg); }
|
637 |
+
100% { transform: rotate(360deg); }
|
638 |
+
}
|
639 |
"""
|
640 |
|
641 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as app:
|
|
|
704 |
analysis_result = gr.Markdown("")
|
705 |
|
706 |
def handle_blessing_complete(audio, state):
|
|
|
707 |
if audio is None:
|
708 |
return (
|
709 |
state,
|
710 |
"음성을 먼저 녹음해주세요.",
|
711 |
+
gr.update(visible=False), # loading
|
712 |
gr.update(visible=False), # voice_features
|
713 |
gr.update(visible=False), # text_sentiment
|
714 |
gr.update(visible=False), # analysis_result
|
|
|
717 |
)
|
718 |
|
719 |
try:
|
720 |
+
# 분석 시작 표시
|
721 |
+
yield (
|
722 |
+
state,
|
723 |
+
"🔄 기준 음성을 분석중입니다...",
|
724 |
+
gr.update(value='''<div style="display:flex;justify-content:center;align-items:center;"><div class="loader"></div></div>''', visible=True),
|
725 |
+
gr.update(visible=False),
|
726 |
+
gr.update(visible=False),
|
727 |
+
gr.update(visible=False),
|
728 |
+
gr.update(visible=True),
|
729 |
+
gr.update(visible=False)
|
730 |
+
)
|
731 |
|
732 |
features = calculate_baseline_features(audio)
|
733 |
if features is None:
|
|
|
742 |
gr.update(visible=False)
|
743 |
)
|
744 |
|
745 |
+
# 감정 분석 중 표시
|
746 |
+
yield (
|
747 |
+
state,
|
748 |
+
"🔄 음성의 감정과 특성을 분석중입니다...",
|
749 |
+
gr.update(visible=True),
|
750 |
+
gr.update(visible=False),
|
751 |
+
gr.update(visible=False),
|
752 |
+
gr.update(visible=False),
|
753 |
+
gr.update(visible=True),
|
754 |
+
gr.update(visible=False)
|
755 |
+
)
|
756 |
+
|
757 |
baseline_emotion = map_acoustic_to_emotion(features)
|
758 |
|
759 |
+
# 분석 결과 생성
|
760 |
+
voice_features_text = f"""
|
761 |
+
🎭 음성 특성 분석:
|
|
|
|
|
|
|
|
|
|
|
762 |
|
763 |
+
• 에너지 레벨: {baseline_emotion['details']['energy_level']}
|
764 |
+
• 말하기 속도: {baseline_emotion['details']['speech_rate']}
|
765 |
+
• 음높이 변화: {baseline_emotion['details']['pitch_variation']}
|
766 |
+
• 음성 크기: {baseline_emotion['details']['voice_volume']}
|
767 |
+
"""
|
768 |
|
769 |
+
sentiment_text = f"""
|
770 |
+
💫 기본 감정 상태:
|
771 |
+
|
772 |
+
• 주요 감정: {baseline_emotion['primary']}
|
773 |
+
• 감정 강도: {baseline_emotion['intensity']:.1f}%
|
774 |
+
• 특징: {', '.join(baseline_emotion['characteristics'])}
|
775 |
+
"""
|
776 |
+
|
777 |
+
analysis_text = f"""
|
778 |
+
✨ 기준 음성 분석이 완료되었습니다.
|
779 |
+
|
780 |
+
이 음성 특성을 기준으로 이후의 감정 변화를 분석합니다.
|
781 |
+
청신 단계에서 마음을 정화하신 후 기원을 진행해주세요.
|
782 |
+
"""
|
783 |
|
784 |
# 상태 업데이트
|
785 |
new_state = safe_state_update(state, {
|
|
|
788 |
"analysis_complete": True
|
789 |
})
|
790 |
|
791 |
+
# 최종 결과 반환
|
792 |
return (
|
793 |
new_state,
|
794 |
"✅ 축원이 완료되었습니다. 이제 청신 단계로 진행해주세요.",
|
795 |
+
gr.update(visible=False),
|
796 |
+
gr.update(value=voice_features_text, visible=True),
|
797 |
+
gr.update(value=sentiment_text, visible=True),
|
798 |
+
gr.update(value=analysis_text, visible=True),
|
799 |
+
gr.update(visible=False),
|
800 |
+
gr.update(visible=True)
|
801 |
)
|
802 |
|
803 |
except Exception as e:
|
|
|
811 |
gr.update(visible=True),
|
812 |
gr.update(visible=False)
|
813 |
)
|
814 |
+
|
815 |
# 4단계: 굿판 입장 안내
|
816 |
entry_guide_section = gr.Column(visible=False)
|
817 |
with entry_guide_section:
|