haepada commited on
Commit
9300635
·
verified ·
1 Parent(s): 38bdcec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -13
app.py CHANGED
@@ -52,6 +52,9 @@ def serve_assets(path):
52
  def serve_wishes(path):
53
  return send_from_directory('data/wishes', path)
54
 
 
 
 
55
 
56
  class SimpleDB:
57
  def __init__(self, reflections_path="data/reflections.json", wishes_path="data/wishes.json"):
@@ -932,10 +935,6 @@ def create_interface():
932
  **청신 의식을 시작하려면 아래 버튼을 눌러주세요.**
933
  """)
934
  enter_btn = gr.Button("청신 의식 시작하기", variant="primary")
935
- enter_btn.click(
936
- fn=lambda: gr.update(selected=1),
937
- outputs=[tabs]
938
- )
939
 
940
  with gr.TabItem("청신") as tab_listen:
941
  gr.Markdown("## 청신 - 신을 부르기 위한 정화 의식")
@@ -955,19 +954,46 @@ def create_interface():
955
  gr.Markdown("## 聽身, 請神 (몸의 소리를 듣고 신을 청하다) ")
956
  # HTML로 오디오 플레이어를 직접 삽입
957
  gr.HTML("""
958
- <audio controls class="audio-player">
959
- <source src="/assets/main_music.mp3" type="audio/mpeg">
960
- 브라우저가 오디오 태그를 지원하지 않습니다.
961
- </audio>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
962
  """)
963
-
964
  with gr.Column():
965
  reflection_input = gr.Textbox(
966
- label="감상과 함께 마음의 번잡함을 내려놓으세요. 본 정보는 저장되지 않습니다.",
967
  lines=3,
968
  max_lines=5
969
  )
970
- save_btn = gr.Button("감상 저장하기", variant="secondary")
971
  reflections_display = gr.Dataframe(
972
  headers=["시간", "감상", "감정 분석"],
973
  label="기록된 감상들",
@@ -1159,6 +1185,9 @@ def create_interface():
1159
  print(f"Baseline error: {str(e)}")
1160
  return current_state, "오류가 발생했습니다. 다시 시도해주세요.", gr.update(selected=0)
1161
 
 
 
 
1162
  def handle_save_reflection(text, state):
1163
  if not text.strip():
1164
  return state, []
@@ -1296,8 +1325,8 @@ def create_interface():
1296
  )
1297
 
1298
  enter_btn.click(
1299
- fn=handle_enter,
1300
- outputs=[tabs]
1301
  )
1302
 
1303
  save_btn.click(
 
52
  def serve_wishes(path):
53
  return send_from_directory('data/wishes', path)
54
 
55
+ @app.route('/assets/<path:filename>')
56
+ def serve_audio(filename):
57
+ return send_from_directory('assets', filename, mimetype='audio/mp3')
58
 
59
  class SimpleDB:
60
  def __init__(self, reflections_path="data/reflections.json", wishes_path="data/wishes.json"):
 
935
  **청신 의식을 시작하려면 아래 버튼을 눌러주세요.**
936
  """)
937
  enter_btn = gr.Button("청신 의식 시작하기", variant="primary")
 
 
 
 
938
 
939
  with gr.TabItem("청신") as tab_listen:
940
  gr.Markdown("## 청신 - 신을 부르기 위한 정화 의식")
 
954
  gr.Markdown("## 聽身, 請神 (몸의 소리를 듣고 신을 청하다) ")
955
  # HTML로 오디오 플레이어를 직접 삽입
956
  gr.HTML("""
957
+ <div class="audio-player-container">
958
+ <audio id="bgMusic" controls="controls" style="width: 100%; max-width: 500px;">
959
+ <source src="assets/main_music.mp3" type="audio/mpeg">
960
+ </audio>
961
+ </div>
962
+ <script>
963
+ // 탭 변경을 감지하여 음악 재생
964
+ document.addEventListener('DOMContentLoaded', function() {
965
+ const audio = document.querySelector('#bgMusic');
966
+ if(audio) {
967
+ // 탭 진입 시 음악 재생
968
+ audio.play().catch(function(error) {
969
+ console.log("음악 자동재생 실패:", error);
970
+ });
971
+ }
972
+ });
973
+ </script>
974
+ <style>
975
+ .audio-player-container {
976
+ width: 100%;
977
+ margin: 20px auto;
978
+ text-align: center;
979
+ padding: 20px;
980
+ }
981
+ audio {
982
+ width: 100%;
983
+ max-width: 500px;
984
+ margin: 0 auto;
985
+ display: block;
986
+ }
987
+ </style>
988
  """)
989
+
990
  with gr.Column():
991
  reflection_input = gr.Textbox(
992
+ label="기록과 함께 마음의 번잡함을 내려놓으세요. 본 정보는 저장되지 않습니다.",
993
  lines=3,
994
  max_lines=5
995
  )
996
+ save_btn = gr.Button("기록 남기기", variant="secondary")
997
  reflections_display = gr.Dataframe(
998
  headers=["시간", "감상", "감정 분석"],
999
  label="기록된 감상들",
 
1185
  print(f"Baseline error: {str(e)}")
1186
  return current_state, "오류가 발생했습니다. 다시 시도해주세요.", gr.update(selected=0)
1187
 
1188
+ def move_to_chungshin():
1189
+ return gr.Tabs.update(selected="청신")
1190
+
1191
  def handle_save_reflection(text, state):
1192
  if not text.strip():
1193
  return state, []
 
1325
  )
1326
 
1327
  enter_btn.click(
1328
+ fn=lambda: gr.Tabs.update(selected="청신"),
1329
+ outputs=tabs
1330
  )
1331
 
1332
  save_btn.click(