haepada commited on
Commit
e0f1e5d
·
verified ·
1 Parent(s): af0d885

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -33
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=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
- "음성을 먼저 녹음해주세요.", # 상태 메시지
679
- gr.update(visible=False), # 분석 결과
680
- gr.update(visible=True), # blessing_section visibility
681
- gr.update(visible=False) # entry_guide_section visibility
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, # state
717
- "축원이 완료되었습니다. 이제 굿판으로 입장하실 수 있습니다.", # 상태 메시지
718
- gr.update(value=analysis_text, visible=True), # 분석 결과
719
- gr.update(visible=False), # blessing_section visibility
720
- gr.update(visible=True) # entry_guide_section visibility
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
- all_reflections = db.get_all_reflections()
940
- for ref in all_reflections:
941
- display_data.append([
942
- ref["timestamp"],
943
- ref["reflection"],
944
- ref["sentiment"]
945
- ])
946
-
947
  # 상태 업데이트
948
- state = safe_state_update(state, {"reflections": display_data})
949
 
950
- return state, display_data
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():