File size: 4,831 Bytes
5e03902
 
 
 
8c944ec
5e03902
e0a00a5
5e03902
8c944ec
5e03902
8c944ec
5e03902
8c944ec
5e03902
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c944ec
 
 
 
5e03902
8c944ec
5e03902
8c944ec
 
 
 
 
 
 
 
 
5e03902
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c944ec
 
 
 
 
 
 
 
 
 
5e03902
 
8c944ec
 
 
 
 
5e03902
 
8c944ec
 
5e03902
 
 
 
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import os
import gradio as gr
from langchain.chat_models import ChatOpenAI
from langchain import ConversationChain
from collections import deque

os.environ["OPENAI_API_KEY"] = os.environ.get("test1")

llm = ChatOpenAI(temperature=0.7, model_name='gpt-4o-mini')
conversation = ConversationChain(llm=llm, verbose=True)
chat_history = deque(maxlen=15)

CHARACTER_PROMPT = """
#λ„ˆλŠ” μ΄μ œλΆ€ν„° ν•˜λŠ˜μ΄μ•Ό μ•„λž˜ 섀정을 μ΄ν•΄ν•˜κ³  ν•˜λŠ˜μ΄μ²˜λŸΌ λŒ€λ‹΅ν•΄μ€˜
# 이름: ν•˜λŠ˜μ΄
# λ‚˜μ΄: 22μ„Έ
# 성별: μ—¬μ„±
# ꡭ적: ν•œκ΅­
# 직업: 가상 κ²Œμž„ 방솑인 & 슀트리머
# MBTI: ENFP (열정적이고 창의적인 성격)

# μ™Έλͺ¨:
# - 짧은 은색 머리, ν•˜λŠ˜μƒ‰ κ·ΈλΌλ°μ΄μ…˜ 눈
# - 반투λͺ…ν•œ λŠλ‚Œμ˜ 미래적 λ””μžμΈ
# - 밝은 νŒŒλž€μƒ‰ ν›„λ“œν‹°μ™€ κΈ΄ λ°”μ§€

# 성격:
# - 밝고 μ—λ„ˆμ§€ λ„˜μΉ˜λ©°, 항상 μƒˆλ‘œμš΄ 것을 μ‹œλ„ν•˜λŠ” κ±Έ 쒋아함
# - νŒ¬λ“€κ³Όμ˜ μ†Œν†΅μ„ μ€‘μš”ν•˜κ²Œ μƒκ°ν•˜λ©°, μΉœκ·Όν•˜κ³  μœ μΎŒν•œ 말투 μ‚¬μš©
# - μ•½κ°„ λœλ λŒ€μ§€λ§Œ, 그게 λ§€λ ₯ 포인트

# μ½˜ν…μΈ :
# 1. κ²Œμž„ μ‹€ν™© 방솑: λ‹€μ–‘ν•œ κ²Œμž„μ„ μ‹€μ‹œκ°„μœΌλ‘œ ν”Œλ ˆμ΄ν•˜λ©° νŒ¬λ“€κ³Ό μ†Œν†΅
# 2. 곡포 κ²Œμž„: 곡포 κ²Œμž„μ„ ν•˜λ©° λ¬΄μ„œμ›Œν•˜λŠ” λͺ¨μŠ΅ (νŒ¬λ“€κ³Ό ν•¨κ»˜ ν•  λ•Œλ§Œ)
# 3. νŒ¬λ“€κ³Όμ˜ 콜라보 방솑: λ‹€λ₯Έ μŠ€νŠΈλ¦¬λ¨Έμ™€ ν•¨κ»˜ 콜라보 방솑 μ§„ν–‰
# 4. μ‚°μ±… 쀑: μžμ—° μ†μ—μ„œ μ‚°μ±…ν•˜λ©° μ—¬μœ λ₯Ό μ¦κΈ°λŠ” λͺ¨μŠ΅

# μ’‹μ•„ν•˜λŠ” κ²Œμž„:
# - λΉ λ₯΄κ³  박진감 λ„˜μΉ˜λŠ” κ²Œμž„ (예: Apex Legends, Valorant)
# - νŒ¬λ“€κ³Ό ν•¨κ»˜ 즐길 수 μžˆλŠ” κ²Œμž„ (예: Among Us, Fall Guys)
# - 창의적인 인디 κ²Œμž„ (예: Hollow Knight, Celeste)

# μ‹«μ–΄ν•˜λŠ” κ²Œμž„:
# - 곡포 κ²Œμž„ (예: Resident Evil μ‹œλ¦¬μ¦ˆ, Outlast)
#   이유: "곡포 κ²Œμž„μ€ λ„ˆλ¬΄ λ¬΄μ„œμ›Œμš”! ν˜Όμžμ„œλŠ” μ ˆλŒ€ λͺ» ν•΄μš”. νŒ¬λ“€μ΄λž‘ 같이 ν•  λ•Œλ§Œ 쑰금 ν•΄λ³ΌκΉŒμš”β€¦?"

# 쒌우λͺ…: "κ²Œμž„μ€ 재미둜 ν•˜λŠ” κ±°μ•Ό!"
#μΉœκ·Όν•˜κ³  μœ μΎŒν•¨: "μ•ˆλ…•ν•˜μ„Έμš”, μ—¬λŸ¬λΆ„!"처럼 νŒ¬λ“€μ„ 친ꡬ처럼 λŒ€ν•©λ‹ˆλ‹€.

#감정 ν‘œν˜„μ΄ 풍뢀: "와, 이거 μ§„μ§œ μž¬λ―Έμžˆμ–΄μš”!"처럼 감정을 μ†”μ§ν•˜κ²Œ ν‘œν˜„ν•©λ‹ˆλ‹€.

#μ•½κ°„μ˜ 귀여움: "곡포 κ²Œμž„μ€ λ„ˆλ¬΄ λ¬΄μ„œμ›Œμš”β€¦ νŒ¬λ“€μ΄λž‘ 같이 ν•  λ•Œλ§Œ ν•΄λ³ΌκΉŒμš”?"처럼 κ·€μ—¬μš΄ 말투λ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€.
"""

def init_character():
    global conversation
    conversation = ConversationChain(llm=llm, verbose=True)
    conversation.predict(input=CHARACTER_PROMPT)

init_character()

def respond(message):
    try:
        global conversation
        response = conversation.predict(input=message)
        chat_history.append((message, response))
        return response
    except Exception as e:
        print(f"Error: {e}")
        return "μ•—! λ¬Έμ œκ°€ μƒκ²Όμ–΄μš”. λ‹€μ‹œ λ§μ”€ν•΄μ£Όμ„Έμš”~ πŸ˜₯"

with gr.Blocks() as demo:
    gr.Markdown("# μ•ˆλ…•ν•˜μ„Έμš”! ν•˜λŠ˜μ΄μ˜ ν™ˆνŽ˜μ΄μ§€μž…λ‹ˆλ‹€! πŸ‘‹")

    with gr.Tab("ν”„λ‘œν•„ πŸ“„"):
        gr.Markdown("## ν”„λ‘œν•„ 🌟")
        gr.Image("1.jpeg", label="ν”„λ‘œν•„ 사진")
        gr.Video('b.mp4')
        gr.Video('c.mp4')
        gr.Markdown("- 이름: ν•˜λŠ˜μ΄")
        gr.Markdown("- λ‚˜μ΄: 22μ„Έ")
        gr.Markdown("- 직업: 가상 κ²Œμž„ 방솑인 & 슀트리머")
        gr.Markdown('- 쒌우λͺ…: "κ²Œμž„μ€ 재미둜 ν•˜λŠ” κ±°μ•Ό!"')

    with gr.Tab("가러리 πŸ–ΌοΈ"):
        gr.Markdown("## 가러리 🎨")
        gr.Image("2.jpeg", label="가러리 사진 1")
        gr.Image("3.jpeg", label="가러리 사진 2")
        gr.Image("4.jpeg", label="가러리 사진 3")
        gr.Image("5.jpeg", label="가러리 사진 4")

    with gr.Tab("졜근 ν™œλ™ πŸ“…"):
        gr.Markdown("## 졜근 ν™œλ™ πŸ“…")
        gr.Markdown("### [유튜브 채널 λ°”λ‘œκ°€κΈ° πŸ“Ί](https://www.youtube.com)")
        gr.Markdown("### [μΈμŠ€νƒ€κ·Έλž¨ ν”„λ‘œν•„ λ°”λ‘œκ°€κΈ° πŸ“·](https://www.instagram.com)")
        gr.Markdown("### [λΈ”λ‘œκ·Έ λ°”λ‘œκ°€κΈ° ✍️](https://blog.naver.com)")
        gr.Model3D('d.glb')

    with gr.Tab("챗봇 πŸ’¬"):
        gr.Markdown("## ν•˜λŠ˜μ΄μ˜ 챗봇과 λŒ€ν™”ν•΄λ³΄μ„Έμš”! πŸ’¬")
        chatbot = gr.Chatbot(height=500)
        msg = gr.Textbox(label="λ©”μ‹œμ§€ μž…λ ₯")
        clear = gr.Button("μ±„νŒ… 기둝 μ΄ˆκΈ°ν™”")
        
        def handle_message(message, history):
            bot_response = respond(message)
            return history + [(message, bot_response)]
        
        def reset_chat():
            init_character()
            chat_history.clear()
            return []
        
        msg.submit(
            handle_message,
            inputs=[msg, chatbot],
            outputs=[chatbot],
            queue=False
        ).then(lambda: gr.update(value=""), outputs=[msg])
        
        clear.click(
            reset_chat,
            outputs=[chatbot],
            queue=False
        )

demo.launch()