Update app.py
Browse files
app.py
CHANGED
@@ -359,16 +359,18 @@ def create_interface():
|
|
359 |
|
360 |
gr.Markdown("# 디지털 굿판")
|
361 |
|
362 |
-
with gr.Tabs(selected=0) as tabs:
|
363 |
-
with gr.TabItem("입장") as tab_entrance:
|
364 |
-
gr.Markdown(WELCOME_MESSAGE)
|
365 |
name_input = gr.Textbox(
|
366 |
label="이름을 알려주세요",
|
367 |
placeholder="이름을 입력해주세요",
|
368 |
-
interactive=True
|
369 |
)
|
370 |
-
|
371 |
-
|
|
|
|
|
372 |
|
373 |
with gr.TabItem("기준 설정") as tab_baseline:
|
374 |
gr.Markdown("""### 축원의 문장을 평온한 마음으로 읽어주세요""")
|
@@ -460,53 +462,68 @@ def create_interface():
|
|
460 |
save_final_status = gr.Markdown("")
|
461 |
|
462 |
# 이벤트 연결 - gr.on 사용
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
463 |
start_btn.click(
|
464 |
-
fn=
|
465 |
-
WORLDVIEW_MESSAGE if name.strip() else "이름을 입력해주세요",
|
466 |
-
gr.update(visible=True) if name.strip() else gr.update(visible=False),
|
467 |
-
{**state, "user_name": name} if name.strip() else state
|
468 |
-
),
|
469 |
inputs=[name_input, state],
|
470 |
-
outputs=[
|
471 |
)
|
472 |
|
473 |
set_baseline_btn.click(
|
474 |
-
fn=
|
475 |
-
{**s, "baseline_features": calculate_baseline_features(x)},
|
476 |
-
"기준점이 설정되었습니다."
|
477 |
-
),
|
478 |
inputs=[baseline_audio, state],
|
479 |
outputs=[state, baseline_status]
|
480 |
)
|
481 |
|
482 |
-
save_btn.click(
|
483 |
-
fn=save_reflection,
|
484 |
-
inputs=[reflection_input, state],
|
485 |
-
outputs=[state, reflections_display]
|
486 |
-
)
|
487 |
-
|
488 |
-
clear_btn.click(
|
489 |
-
fn=lambda: gr.update(value=None),
|
490 |
-
outputs=[voice_input]
|
491 |
-
)
|
492 |
-
|
493 |
analyze_btn.click(
|
494 |
-
fn=
|
495 |
inputs=[voice_input, state],
|
496 |
outputs=[state, transcribed_text, voice_emotion, text_emotion, final_prompt]
|
497 |
)
|
498 |
|
499 |
generate_btn.click(
|
500 |
-
fn=
|
501 |
inputs=[final_prompt],
|
502 |
outputs=[result_image]
|
503 |
)
|
504 |
|
505 |
save_final_btn.click(
|
506 |
-
fn=lambda t, s: (
|
507 |
-
db.save_wish(s.get("user_name", "익명"), t),
|
508 |
-
"감상이 저장되었습니다."
|
509 |
-
),
|
510 |
inputs=[final_reflection, state],
|
511 |
outputs=[save_final_status]
|
512 |
)
|
@@ -522,8 +539,6 @@ if __name__ == "__main__":
|
|
522 |
demo = create_interface()
|
523 |
demo.launch(
|
524 |
debug=True,
|
525 |
-
share=True,
|
526 |
-
show_error=True,
|
527 |
server_name="0.0.0.0",
|
528 |
server_port=7860
|
529 |
-
)
|
|
|
359 |
|
360 |
gr.Markdown("# 디지털 굿판")
|
361 |
|
362 |
+
with gr.Tabs(selected=0) as tabs:
|
363 |
+
with gr.TabItem("입장") as tab_entrance:
|
364 |
+
name_display = gr.Markdown(WELCOME_MESSAGE) # worldview_display 대신 하나의 Markdown 사용
|
365 |
name_input = gr.Textbox(
|
366 |
label="이름을 알려주세요",
|
367 |
placeholder="이름을 입력해주세요",
|
368 |
+
interactive=True
|
369 |
)
|
370 |
+
start_btn = gr.Button("여정 시작하기", variant="primary")
|
371 |
+
|
372 |
+
|
373 |
+
# variant 추가
|
374 |
|
375 |
with gr.TabItem("기준 설정") as tab_baseline:
|
376 |
gr.Markdown("""### 축원의 문장을 평온한 마음으로 읽어주세요""")
|
|
|
462 |
save_final_status = gr.Markdown("")
|
463 |
|
464 |
# 이벤트 연결 - gr.on 사용
|
465 |
+
def handle_start(name, current_state):
|
466 |
+
if not name.strip():
|
467 |
+
return "이름을 입력해주세요", gr.update(selected=0), current_state
|
468 |
+
current_state = {**current_state, "user_name": name}
|
469 |
+
return WORLDVIEW_MESSAGE, gr.update(selected=1), current_state
|
470 |
+
|
471 |
+
def handle_baseline(audio_data, current_state):
|
472 |
+
try:
|
473 |
+
features = calculate_baseline_features(audio_data)
|
474 |
+
if features:
|
475 |
+
current_state = {**current_state, "baseline_features": features}
|
476 |
+
return current_state, "기준점이 설정되었습니다."
|
477 |
+
return current_state, "기준점 설정에 실패했습니다."
|
478 |
+
except Exception as e:
|
479 |
+
return current_state, f"오류 발생: {str(e)}"
|
480 |
+
|
481 |
+
def handle_analysis(audio_data, current_state):
|
482 |
+
try:
|
483 |
+
result = analyze_voice(audio_data, current_state)
|
484 |
+
if isinstance(result, tuple) and len(result) == 5:
|
485 |
+
return result
|
486 |
+
return current_state, "분석 실패", "", "", ""
|
487 |
+
except Exception as e:
|
488 |
+
return current_state, f"오류 발생: {str(e)}", "", "", ""
|
489 |
+
|
490 |
+
def handle_image_generation(prompt):
|
491 |
+
if not prompt:
|
492 |
+
return None
|
493 |
+
try:
|
494 |
+
image_data = generate_image_from_prompt(prompt)
|
495 |
+
return image_data[0] if image_data else None
|
496 |
+
except Exception as e:
|
497 |
+
print(f"Image generation error: {str(e)}")
|
498 |
+
return None
|
499 |
+
|
500 |
+
# 이벤트 연결
|
501 |
start_btn.click(
|
502 |
+
fn=handle_start,
|
|
|
|
|
|
|
|
|
503 |
inputs=[name_input, state],
|
504 |
+
outputs=[name_display, tabs, state]
|
505 |
)
|
506 |
|
507 |
set_baseline_btn.click(
|
508 |
+
fn=handle_baseline,
|
|
|
|
|
|
|
509 |
inputs=[baseline_audio, state],
|
510 |
outputs=[state, baseline_status]
|
511 |
)
|
512 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
513 |
analyze_btn.click(
|
514 |
+
fn=handle_analysis,
|
515 |
inputs=[voice_input, state],
|
516 |
outputs=[state, transcribed_text, voice_emotion, text_emotion, final_prompt]
|
517 |
)
|
518 |
|
519 |
generate_btn.click(
|
520 |
+
fn=handle_image_generation,
|
521 |
inputs=[final_prompt],
|
522 |
outputs=[result_image]
|
523 |
)
|
524 |
|
525 |
save_final_btn.click(
|
526 |
+
fn=lambda t, s: "감상이 저장되었습니다." if db.save_wish(s.get("user_name", "익명"), t) else "저장 실패",
|
|
|
|
|
|
|
527 |
inputs=[final_reflection, state],
|
528 |
outputs=[save_final_status]
|
529 |
)
|
|
|
539 |
demo = create_interface()
|
540 |
demo.launch(
|
541 |
debug=True,
|
|
|
|
|
542 |
server_name="0.0.0.0",
|
543 |
server_port=7860
|
544 |
+
)
|