File size: 2,932 Bytes
bb63470
 
 
 
00ada4a
bb63470
7ec9920
 
00ada4a
7ec9920
 
 
 
 
00ada4a
7ec9920
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9f7512d
7ec9920
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9f7512d
7ec9920
 
 
 
9f7512d
7ec9920
 
00ada4a
7ec9920
 
00ada4a
9f7512d
7ec9920
 
00ada4a
9f7512d
7ec9920
 
 
 
 
 
 
 
 
 
 
 
9f7512d
00ada4a
bb63470
7ec9920
00ada4a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import gradio as gr
import numpy as np
import librosa
from transformers import pipeline
from datetime import datetime

# 모델 초기화
text_analyzer = pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment")

def create_interface():
    with gr.Blocks(theme=gr.themes.Soft()) as app:
        # 상태 관리
        state = gr.State({
            "stage": "intro",
            "reflections": [],
            "user_name": ""
        })
        
        # 헤더
        gr.Markdown("# 디지털 굿판")
        
        # 입장 화면
        with gr.Tab("입장"):
            name_input = gr.Textbox(label="이름을 알려주세요")
            start_button = gr.Button("여정 시작하기")
        
        # 청신 화면
        with gr.Tab("청신"):
            # 음악 플레이어
            audio_player = gr.Audio(
                value="assets/main_music.mp3",  # 음악 파일 경로
                type="filepath",
                label="온천천의 소리"
            )
            
            # 감상 입력
            reflection_text = gr.Textbox(
                label="현재 순간의 감상을 적어주세요",
                lines=3
            )
            save_button = gr.Button("감상 저장")
            reflections_display = gr.Dataframe(
                headers=["시간", "감상", "감정"],
                label="기록된 감상들"
            )
        
        # 기원 화면
        with gr.Tab("기원"):
            voice_input = gr.Audio(
                label="나누고 싶은 이야기를 들려주세요",
                sources=["microphone"],
                type="filepath"
            )
            analysis_output = gr.JSON(label="분석 결과")
        
        # 송신 화면
        with gr.Tab("송신"):
            final_prompt = gr.Textbox(label="생성된 프롬프트")
            
        # 함수 정의
        def save_reflection(text, state):
            if not text.strip():
                return state, None
            
            try:
                # 현재 시간
                current_time = datetime.now().strftime("%H:%M:%S")
                
                # 감정 분석
                sentiment = text_analyzer(text)[0]
                
                # 새로운 감상 추가
                new_reflection = [current_time, text, sentiment["label"]]
                state["reflections"].append(new_reflection)
                
                return state, state["reflections"]
            except Exception as e:
                return state, f"오류 발생: {str(e)}"
        
        # 이벤트 연결
        save_button.click(
            fn=save_reflection,
            inputs=[reflection_text, state],
            outputs=[state, reflections_display]
        )
    
    return app

# 앱 실행
if __name__ == "__main__":
    interface = create_interface()
    interface.launch()