Update app.py
Browse files
app.py
CHANGED
@@ -667,36 +667,39 @@ def create_interface():
|
|
667 |
|
668 |
with gr.Column() as action_section:
|
669 |
set_baseline_btn = gr.Button("축원 마치기", variant="primary")
|
670 |
-
analysis_status = gr.Markdown(visible=
|
671 |
-
analysis_result = gr.Markdown(visible=
|
672 |
|
673 |
def handle_blessing_complete(audio, state):
|
674 |
"""축원 완료 및 분석 처리"""
|
675 |
if audio is None:
|
676 |
return (
|
677 |
-
state,
|
678 |
-
"음성을 먼저 녹음해주세요.",
|
679 |
-
gr.update(visible=False),
|
680 |
-
gr.update(visible=True),
|
681 |
-
gr.update(visible=False)
|
682 |
)
|
683 |
|
684 |
try:
|
685 |
-
# 분석
|
686 |
-
gr.update(value="축원 음성을 분석중입니다...", visible=True)
|
687 |
-
|
|
|
688 |
features = calculate_baseline_features(audio)
|
689 |
if features is None:
|
690 |
return (
|
691 |
state,
|
692 |
-
"음성 분석에 실패했습니다.",
|
693 |
gr.update(visible=False),
|
694 |
gr.update(visible=True),
|
695 |
gr.update(visible=False)
|
696 |
)
|
697 |
|
698 |
-
# 감정 분석
|
699 |
-
gr.update(value="감정을 분석중입니다...", visible=True)
|
|
|
|
|
700 |
baseline_emotion = map_acoustic_to_emotion(features)
|
701 |
|
702 |
# 분석 결과 생성
|
@@ -713,17 +716,17 @@ def create_interface():
|
|
713 |
new_state = safe_state_update(state, {"baseline_features": features, "analysis_complete": True})
|
714 |
|
715 |
return (
|
716 |
-
new_state,
|
717 |
-
"축원이 완료되었습니다. 이제 굿판으로 입장하실 수 있습니다.",
|
718 |
-
gr.update(value=analysis_text, visible=True),
|
719 |
-
gr.update(visible=False),
|
720 |
-
gr.update(visible=True)
|
721 |
)
|
722 |
|
723 |
except Exception as e:
|
724 |
return (
|
725 |
state,
|
726 |
-
f"오류가 발생했습니다: {str(e)}",
|
727 |
gr.update(visible=False),
|
728 |
gr.update(visible=True),
|
729 |
gr.update(visible=False)
|
@@ -932,26 +935,25 @@ def create_interface():
|
|
932 |
sentiment_text = "분석 불가"
|
933 |
|
934 |
# DB에 저장
|
935 |
-
db.save_reflection(name, text, sentiment_text)
|
936 |
|
937 |
-
#
|
938 |
display_data = []
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
# 상태 업데이트
|
948 |
-
state = safe_state_update(state, {"reflections":
|
949 |
|
950 |
-
return state,
|
951 |
-
|
952 |
except Exception as e:
|
953 |
print(f"Error saving reflection: {e}")
|
954 |
-
return state, []
|
955 |
|
956 |
def handle_save_wish(text, state):
|
957 |
if not text.strip():
|
|
|
667 |
|
668 |
with gr.Column() as action_section:
|
669 |
set_baseline_btn = gr.Button("축원 마치기", variant="primary")
|
670 |
+
analysis_status = gr.Markdown(visible=True)
|
671 |
+
analysis_result = gr.Markdown(visible=True)
|
672 |
|
673 |
def handle_blessing_complete(audio, state):
|
674 |
"""축원 완료 및 분석 처리"""
|
675 |
if audio is None:
|
676 |
return (
|
677 |
+
state,
|
678 |
+
gr.update(value="음성을 먼저 녹음해주세요.", visible=True), # 상태 메시지
|
679 |
+
gr.update(visible=False), # 분석 결과
|
680 |
+
gr.update(visible=True), # blessing_section
|
681 |
+
gr.update(visible=False) # entry_guide_section
|
682 |
)
|
683 |
|
684 |
try:
|
685 |
+
# 분석 시작 상태 표시
|
686 |
+
status = gr.update(value="🔄 축원 음성을 분석중입니다...", visible=True)
|
687 |
+
yield state, status, gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
|
688 |
+
|
689 |
features = calculate_baseline_features(audio)
|
690 |
if features is None:
|
691 |
return (
|
692 |
state,
|
693 |
+
gr.update(value="❌ 음성 분석에 실패했습니다.", visible=True),
|
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 |
# 분석 결과 생성
|
|
|
716 |
new_state = safe_state_update(state, {"baseline_features": features, "analysis_complete": True})
|
717 |
|
718 |
return (
|
719 |
+
new_state,
|
720 |
+
gr.update(value="✅ 축원이 완료되었습니다. 이제 굿판으로 입장하실 수 있습니다.", visible=True),
|
721 |
+
gr.update(value=analysis_text, visible=True),
|
722 |
+
gr.update(visible=False),
|
723 |
+
gr.update(visible=True)
|
724 |
)
|
725 |
|
726 |
except Exception as e:
|
727 |
return (
|
728 |
state,
|
729 |
+
gr.update(value=f"❌ 오류가 발생했습니다: {str(e)}", visible=True),
|
730 |
gr.update(visible=False),
|
731 |
gr.update(visible=True),
|
732 |
gr.update(visible=False)
|
|
|
935 |
sentiment_text = "분석 불가"
|
936 |
|
937 |
# DB에 저장
|
938 |
+
reflection_data = db.save_reflection(name, text, sentiment_text)
|
939 |
|
940 |
+
# 현재 세션의 감상 데이터만 표시
|
941 |
display_data = []
|
942 |
+
session_reflections = state.get("reflections", [])
|
943 |
+
session_reflections.append([
|
944 |
+
current_time,
|
945 |
+
text,
|
946 |
+
sentiment_text
|
947 |
+
])
|
948 |
+
|
|
|
949 |
# 상태 업데이트
|
950 |
+
state = safe_state_update(state, {"reflections": session_reflections})
|
951 |
|
952 |
+
return state, session_reflections # 세션 데이터만 반환
|
953 |
+
|
954 |
except Exception as e:
|
955 |
print(f"Error saving reflection: {e}")
|
956 |
+
return state, state.get("reflections", [])
|
957 |
|
958 |
def handle_save_wish(text, state):
|
959 |
if not text.strip():
|