haepada commited on
Commit
1b6ce40
·
verified ·
1 Parent(s): a5eed8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -17
app.py CHANGED
@@ -708,16 +708,16 @@ def create_interface():
708
  return (
709
  state,
710
  "음성을 먼저 녹음해주세요.",
711
- gr.update(visible=False),
712
- gr.update(visible=False),
713
- gr.update(visible=False),
714
- gr.update(visible=False),
715
- gr.update(visible=True),
716
- gr.update(visible=False)
 
717
  )
718
 
719
  try:
720
- # 1. 음성 특성 분석
721
  features = calculate_baseline_features(audio)
722
  if features is None:
723
  return (
@@ -727,14 +727,13 @@ def create_interface():
727
  gr.update(visible=False),
728
  gr.update(visible=False),
729
  gr.update(visible=False),
 
730
  gr.update(visible=True),
731
  gr.update(visible=False)
732
  )
733
 
734
- # 2. 감정 분석
735
  baseline_emotion = map_acoustic_to_emotion(features)
736
 
737
- # 3. 분석 결과 생성
738
  voice_features_text = f"""
739
  🎭 음성 특성 분석:
740
 
@@ -754,26 +753,25 @@ def create_interface():
754
 
755
  analysis_text = """
756
  ✨ 기준 음성 분석이 완료되었습니다.
757
- 청신 단계에서 마음을 정화하신 기원을 진행해주세요.
758
  """
759
 
760
- # 4. 상태 업데이트
761
  new_state = safe_state_update(state, {
762
  "baseline_features": features,
763
  "baseline_emotion": baseline_emotion,
764
  "analysis_complete": True
765
  })
766
 
767
- # 5. 최종 결과 반환 - 여기서 entry_guide_section을 보이게 설정
768
  return (
769
  new_state,
770
  "✅ 축원이 완료되었습니다.",
771
- gr.update(visible=False), # loading_icon
772
  gr.update(value=voice_features_text, visible=True), # voice_features
773
- gr.update(value=sentiment_text, visible=True), # text_sentiment
774
- gr.update(value=analysis_text, visible=True), # analysis_result
775
- gr.update(visible=False), # blessing_section
776
- gr.update(visible=True) # entry_guide_section - 중요: 다음 단계로 진행
 
777
  )
778
 
779
  except Exception as e:
@@ -785,9 +783,56 @@ def create_interface():
785
  gr.update(visible=False),
786
  gr.update(visible=False),
787
  gr.update(visible=False),
 
788
  gr.update(visible=True),
789
  gr.update(visible=False)
790
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
791
 
792
  # 4단계: 굿판 입장 안내
793
  entry_guide_section = gr.Column(visible=False)
@@ -1056,7 +1101,21 @@ def create_interface():
1056
  blessing_section, # 축원 섹션
1057
  entry_guide_section # 가이드 섹션
1058
  ]
 
 
 
 
1059
  )
 
 
 
 
 
 
 
 
 
 
1060
  enter_btn.click(
1061
  fn=handle_enter,
1062
  outputs=[tabs]
 
708
  return (
709
  state,
710
  "음성을 먼저 녹음해주세요.",
711
+ gr.update(visible=False), # loading_icon
712
+ gr.update(visible=False), # voice_features
713
+ gr.update(visible=False), # text_sentiment
714
+ gr.update(visible=False), # analysis_result
715
+ gr.update(visible=False), # next_button
716
+ gr.update(visible=True), # blessing_section
717
+ gr.update(visible=False) # entry_guide_section
718
  )
719
 
720
  try:
 
721
  features = calculate_baseline_features(audio)
722
  if features is None:
723
  return (
 
727
  gr.update(visible=False),
728
  gr.update(visible=False),
729
  gr.update(visible=False),
730
+ gr.update(visible=False),
731
  gr.update(visible=True),
732
  gr.update(visible=False)
733
  )
734
 
 
735
  baseline_emotion = map_acoustic_to_emotion(features)
736
 
 
737
  voice_features_text = f"""
738
  🎭 음성 특성 분석:
739
 
 
753
 
754
  analysis_text = """
755
  ✨ 기준 음성 분석이 완료되었습니다.
756
+ 결과를 확인하신 아래의 '다음 단계로' 버튼을 눌러주세요.
757
  """
758
 
 
759
  new_state = safe_state_update(state, {
760
  "baseline_features": features,
761
  "baseline_emotion": baseline_emotion,
762
  "analysis_complete": True
763
  })
764
 
 
765
  return (
766
  new_state,
767
  "✅ 축원이 완료되었습니다.",
768
+ gr.update(visible=False), # loading_icon
769
  gr.update(value=voice_features_text, visible=True), # voice_features
770
+ gr.update(value=sentiment_text, visible=True), # text_sentiment
771
+ gr.update(value=analysis_text, visible=True), # analysis_result
772
+ gr.update(visible=True), # next_button
773
+ gr.update(visible=True), # blessing_section
774
+ gr.update(visible=False) # entry_guide_section
775
  )
776
 
777
  except Exception as e:
 
783
  gr.update(visible=False),
784
  gr.update(visible=False),
785
  gr.update(visible=False),
786
+ gr.update(visible=False),
787
  gr.update(visible=True),
788
  gr.update(visible=False)
789
  )
790
+
791
+ def next_section():
792
+ return (
793
+ gr.update(visible=False), # blessing_section
794
+ gr.update(visible=True) # entry_guide_section
795
+ )
796
+
797
+ # UI 구성
798
+ blessing_section = gr.Column(visible=False)
799
+ with blessing_section:
800
+ gr.Markdown("### 축원의식을 시작하겠습니다")
801
+ gr.Markdown("'명짐 복짐 짊어지고 안가태평하시기를 비도발원 축원 드립니다'")
802
+ with gr.Column() as recording_section:
803
+ baseline_audio = gr.Audio(
804
+ label="축원 문장 녹음하기",
805
+ sources=["microphone"],
806
+ type="numpy",
807
+ streaming=False
808
+ )
809
+
810
+ with gr.Column() as action_section:
811
+ set_baseline_btn = gr.Button("축원 마치기", variant="primary")
812
+
813
+ # 분석 상태와 결과를 보여주는 섹션
814
+ analysis_status = gr.Markdown("")
815
+ loading_icon = gr.HTML("""
816
+ <div style="display:flex;justify-content:center;align-items:center;height:50px;overflow:hidden;">
817
+ <div class="loader" style="width:30px;height:30px;"></div>
818
+ </div>
819
+ """)
820
+ voice_features = gr.Textbox(
821
+ label="음성 특성 분석",
822
+ interactive=False,
823
+ visible=False
824
+ )
825
+ text_sentiment = gr.Textbox(
826
+ label="기본 감정 상태",
827
+ interactive=False,
828
+ visible=False
829
+ )
830
+ analysis_result = gr.Markdown(visible=False)
831
+ next_button = gr.Button(
832
+ "다음 단계로",
833
+ variant="primary",
834
+ visible=False # 초기에는 숨김
835
+ )
836
 
837
  # 4단계: 굿판 입장 안내
838
  entry_guide_section = gr.Column(visible=False)
 
1101
  blessing_section, # 축원 섹션
1102
  entry_guide_section # 가이드 섹션
1103
  ]
1104
+ ).then( # 분석 완료 후 '다음으로' 버튼 표시
1105
+ lambda: gr.update(visible=True),
1106
+ None,
1107
+ [next_step_btn]
1108
  )
1109
+
1110
+ # 새로운 버튼에 대한 이벤트 연결
1111
+ next_step_btn.click(
1112
+ fn=proceed_to_next_step,
1113
+ outputs=[
1114
+ blessing_section,
1115
+ entry_guide_section
1116
+ ]
1117
+ )
1118
+
1119
  enter_btn.click(
1120
  fn=handle_enter,
1121
  outputs=[tabs]