haepada commited on
Commit
9cd7892
·
verified ·
1 Parent(s): 2f860d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -9
app.py CHANGED
@@ -21,7 +21,7 @@ WELCOME_MESSAGE = """
21
  """
22
 
23
  WORLDVIEW_MESSAGE = """
24
- ## 굿판의 세계관 🌌
25
 
26
  온천천의 물줄기는 신성한 금샘에서 시작됩니다. 금샘은 생명과 창조의 원천이며,
27
  천상의 생명이 지상에서 숨을 틔우는 자리입니다. 도시의 소음 속에서도 신성한 생명력을 느껴보세요.
@@ -374,6 +374,26 @@ def save_reflection_fixed(text, state):
374
  print(f"Error saving reflection: {e}")
375
  return state, state.get("reflections", [])
376
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
377
  def create_interface():
378
  db = SimpleDB()
379
 
@@ -384,10 +404,22 @@ def create_interface():
384
  "wish": None,
385
  "final_prompt": "",
386
  "image_path": None,
387
- "current_tab": 0 # 탭 상태 추가
 
 
388
  }
389
 
390
- with gr.Blocks(theme=gr.themes.Soft()) as app:
 
 
 
 
 
 
 
 
 
 
391
  state = gr.State(value=initial_state)
392
 
393
  gr.Markdown("# 디지털 굿판")
@@ -415,12 +447,20 @@ def create_interface():
415
  sources=["microphone"],
416
  type="numpy",
417
  streaming=False
 
 
418
  )
419
  set_baseline_btn = gr.Button("기준점 설정 완료", variant="primary")
420
  baseline_status = gr.Markdown("")
421
 
422
  with gr.TabItem("청신") as tab_listen:
423
  gr.Markdown("## 청신 - 소리로 정화하기")
 
 
 
 
 
 
424
  play_music_btn = gr.Button("온천천의 소리 듣기", variant="secondary")
425
  with gr.Row():
426
  audio = gr.Audio(
@@ -475,7 +515,7 @@ def create_interface():
475
  )
476
 
477
  with gr.TabItem("송신") as tab_send:
478
- gr.Markdown("## 송신 - 마음의 그림을 남기고, 보내기")
479
  final_prompt = gr.Textbox(
480
  label="생성된 프롬프트",
481
  interactive=False,
@@ -485,6 +525,8 @@ def create_interface():
485
  result_image = gr.Image(
486
  label="생성된 이미지",
487
  show_download_button=True
 
 
488
  )
489
 
490
  gr.Markdown("## 온천천에 전하고 싶은 소원을 남겨주세요")
@@ -650,8 +692,16 @@ def create_interface():
650
  if __name__ == "__main__":
651
  demo = create_interface()
652
  demo.launch(
653
- debug=True,
654
- share=True, # 추가
655
- server_name="0.0.0.0",
656
- server_port=7860
657
- )
 
 
 
 
 
 
 
 
 
21
  """
22
 
23
  WORLDVIEW_MESSAGE = """
24
+ ## 온천천 이야기 🌌
25
 
26
  온천천의 물줄기는 신성한 금샘에서 시작됩니다. 금샘은 생명과 창조의 원천이며,
27
  천상의 생명이 지상에서 숨을 틔우는 자리입니다. 도시의 소음 속에서도 신성한 생명력을 느껴보세요.
 
374
  print(f"Error saving reflection: {e}")
375
  return state, state.get("reflections", [])
376
 
377
+ def is_mobile(user_agent):
378
+ return any(device in user_agent.lower() for device in ['mobile', 'android', 'iphone'])
379
+
380
+ def handle_tab_change(tab_index, state):
381
+ """탭 변경 시 상태 유지"""
382
+ state = {**state, "current_tab": tab_index}
383
+ return state
384
+
385
+ def safe_state_update(state, updates):
386
+ """안전한 상태 업데이트"""
387
+ try:
388
+ new_state = {**state, **updates}
389
+ return new_state
390
+ except Exception as e:
391
+ print(f"State update error: {e}")
392
+ return state
393
+
394
+ # 상태 업데이트 시 사용
395
+ state = safe_state_update(state, {"user_name": name})
396
+
397
  def create_interface():
398
  db = SimpleDB()
399
 
 
404
  "wish": None,
405
  "final_prompt": "",
406
  "image_path": None,
407
+ "current_tab": 0,
408
+ "is_mobile": False, # 모바일 여부
409
+ "session_active": True # 세션 상태
410
  }
411
 
412
+ with gr.Blocks(
413
+ theme=gr.themes.Soft(),
414
+ css="""
415
+ @media (max-width: 600px) {
416
+ .container { padding: 10px; }
417
+ .gradio-row { flex-direction: column; }
418
+ .gradio-button { width: 100%; margin: 5px 0; }
419
+ .gradio-textbox { width: 100%; }
420
+ }
421
+ """
422
+ ) as app:
423
  state = gr.State(value=initial_state)
424
 
425
  gr.Markdown("# 디지털 굿판")
 
447
  sources=["microphone"],
448
  type="numpy",
449
  streaming=False
450
+ min_width=300, # 최소 너비 설정
451
+ elem_id="audio-recorder" # CSS 식별자 추가
452
  )
453
  set_baseline_btn = gr.Button("기준점 설정 완료", variant="primary")
454
  baseline_status = gr.Markdown("")
455
 
456
  with gr.TabItem("청신") as tab_listen:
457
  gr.Markdown("## 청신 - 소리로 정화하기")
458
+ gr.Markdown("""
459
+ 온천천의 소리를 들으며 마음을 정화해보세요.
460
+
461
+ 💫 이 앱은 온천천의 사운드스케이프를 녹음하여 제작되었으며,
462
+ 온천천 온천장역에서 장전역까지 걸으며 더 깊은 체험이 가능합니다.
463
+ """)
464
  play_music_btn = gr.Button("온천천의 소리 듣기", variant="secondary")
465
  with gr.Row():
466
  audio = gr.Audio(
 
515
  )
516
 
517
  with gr.TabItem("송신") as tab_send:
518
+ gr.Markdown("## 송신 -소지(소원지)를 그려 날려 태워봅시다")
519
  final_prompt = gr.Textbox(
520
  label="생성된 프롬프트",
521
  interactive=False,
 
525
  result_image = gr.Image(
526
  label="생성된 이미지",
527
  show_download_button=True
528
+ min_width=300,
529
+ elem_id="result-image"
530
  )
531
 
532
  gr.Markdown("## 온천천에 전하고 싶은 소원을 남겨주세요")
 
692
  if __name__ == "__main__":
693
  demo = create_interface()
694
  demo.launch(
695
+ debug=True,
696
+ share=True,
697
+ server_name="0.0.0.0",
698
+ server_port=7860,
699
+ enable_queue=True, # 큐 활성화
700
+ cache_examples=True, # 캐시 활성화
701
+ max_threads=4, # 스레드 제한
702
+ show_error=True,
703
+ # 모바일 최적화를 위한 설정
704
+ height=None, # 자동 높이 조정
705
+ width="100%", # 전체 너비 사용
706
+ allow_flagging=False, # 불필요한 기능 비활성화
707
+ )