haepada commited on
Commit
60135b3
·
verified ·
1 Parent(s): 9d6ecca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -51
app.py CHANGED
@@ -664,55 +664,47 @@ def create_interface():
664
  type="numpy",
665
  streaming=False
666
  )
667
- analysis_status = gr.Markdown(
668
- "축원 문장을 녹음해주세요.",
669
- visible=True
670
- )
671
-
672
- with gr.Column(visible=False) as analysis_results:
673
- baseline_status = gr.Markdown("")
674
- voice_analysis = gr.Markdown("")
675
- set_baseline_btn = gr.Button(
676
- "축원 마치기",
677
- variant="primary",
678
- visible=False
679
- )
680
-
681
- def handle_baseline_recording(audio, state):
682
- """기준 음성 분석"""
683
  if audio is None:
684
  return {
685
  "state": state,
686
- "status": "축원 문장을 녹음해주세요.",
687
- "analysis_visible": False,
688
- "button_visible": False,
689
- "analysis_text": ""
690
  }
691
-
692
  try:
693
- # 분석 중임을 표시
694
  yield {
695
  "state": state,
696
- "status": "음성을 분석하고 있습니다...",
697
- "analysis_visible": False,
698
- "button_visible": False,
699
- "analysis_text": ""
700
  }
701
-
702
  # 음성 분석
703
  features = calculate_baseline_features(audio)
704
  if features is None:
705
  return {
706
  "state": state,
707
- "status": "음성 분석에 실패했습니다. 다시 시도해주세요.",
708
- "analysis_visible": False,
709
- "button_visible": False,
710
- "analysis_text": ""
711
  }
712
-
713
  # 감정 분석
714
  baseline_emotion = map_acoustic_to_emotion(features)
715
-
716
  # 분석 결과 생성
717
  analysis_text = (
718
  f"기준 음성 분석 결과:\n"
@@ -722,34 +714,27 @@ def create_interface():
722
  f"- 음높이: {baseline_emotion['details']['pitch_variation']}\n"
723
  f"이 음성을 기준으로 이후 소원을 비교 분석합니다."
724
  )
725
-
726
  # 상태 업데이트
727
  new_state = {**state, "baseline_features": features, "analysis_complete": True}
728
-
729
  return {
730
  "state": new_state,
731
- "status": "",
732
- "analysis_visible": True,
733
- "button_visible": True,
734
- "analysis_text": analysis_text
735
  }
736
-
737
  except Exception as e:
738
  return {
739
  "state": state,
740
- "status": f"오류가 발생했습니다: {str(e)}",
741
- "analysis_visible": False,
742
- "button_visible": False,
743
- "analysis_text": ""
744
  }
745
 
746
- def handle_blessing_complete(state):
747
- """축원 완료 처리"""
748
- if not state.get("analysis_complete"):
749
- return state, "음성 분석이 완료되지 않았습니다.", gr.update(visible=True), gr.update(visible=False)
750
-
751
- return state, "", gr.update(visible=False), gr.update(visible=True)
752
-
753
  # 4단계: 굿판 입장 안내
754
  entry_guide_section = gr.Column(visible=False)
755
  with entry_guide_section:
 
664
  type="numpy",
665
  streaming=False
666
  )
667
+
668
+ with gr.Column() as action_section:
669
+ set_baseline_btn = gr.Button("축원 마치기", variant="primary")
670
+ analysis_status = gr.Markdown(visible=False)
671
+ analysis_result = gr.Markdown(visible=False)
672
+
673
+ def handle_blessing_complete(audio, state):
674
+ """축원 완료 및 분석 처리"""
 
 
 
 
 
 
 
 
675
  if audio is None:
676
  return {
677
  "state": state,
678
+ "status": gr.update(visible=True, value="축원 문장을 먼저 녹음해주세요."),
679
+ "result": gr.update(visible=False),
680
+ "blessing_visible": True,
681
+ "guide_visible": False
682
  }
683
+
684
  try:
685
+ # 분석 시작 표시
686
  yield {
687
  "state": state,
688
+ "status": gr.update(visible=True, value="축원 문장을 분석하고 있습니다..."),
689
+ "result": gr.update(visible=False),
690
+ "blessing_visible": True,
691
+ "guide_visible": False
692
  }
693
+
694
  # 음성 분석
695
  features = calculate_baseline_features(audio)
696
  if features is None:
697
  return {
698
  "state": state,
699
+ "status": gr.update(visible=True, value="음성 분석에 실패했습니다. 다시 시도해주세요."),
700
+ "result": gr.update(visible=False),
701
+ "blessing_visible": True,
702
+ "guide_visible": False
703
  }
704
+
705
  # 감정 분석
706
  baseline_emotion = map_acoustic_to_emotion(features)
707
+
708
  # 분석 결과 생성
709
  analysis_text = (
710
  f"기준 음성 분석 결과:\n"
 
714
  f"- 음높이: {baseline_emotion['details']['pitch_variation']}\n"
715
  f"이 음성을 기준으로 이후 소원을 비교 분석합니다."
716
  )
717
+
718
  # 상태 업데이트
719
  new_state = {**state, "baseline_features": features, "analysis_complete": True}
720
+
721
  return {
722
  "state": new_state,
723
+ "status": gr.update(visible=False),
724
+ "result": gr.update(visible=True, value=analysis_text),
725
+ "blessing_visible": False,
726
+ "guide_visible": True
727
  }
728
+
729
  except Exception as e:
730
  return {
731
  "state": state,
732
+ "status": gr.update(visible=True, value=f"오류가 발생했습니다: {str(e)}"),
733
+ "result": gr.update(visible=False),
734
+ "blessing_visible": True,
735
+ "guide_visible": False
736
  }
737
 
 
 
 
 
 
 
 
738
  # 4단계: 굿판 입장 안내
739
  entry_guide_section = gr.Column(visible=False)
740
  with entry_guide_section: