Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,8 +6,8 @@ import random
|
|
| 6 |
# ------------------------------------------------------------------
|
| 7 |
# 1. 모델 준비
|
| 8 |
# ------------------------------------------------------------------
|
| 9 |
-
REPO_ID = "Jay1121/
|
| 10 |
-
FILENAME = "
|
| 11 |
|
| 12 |
# 모델 다운로드
|
| 13 |
print(f"📥 모델 다운로드 확인: {FILENAME}")
|
|
@@ -18,13 +18,24 @@ print("🧠 엔진 시동 중...")
|
|
| 18 |
llm = Llama(
|
| 19 |
model_path=model_path,
|
| 20 |
n_ctx=2048,
|
| 21 |
-
n_threads=4,
|
| 22 |
verbose=True
|
| 23 |
)
|
| 24 |
print("✅ 로딩 완료!")
|
| 25 |
|
| 26 |
# ------------------------------------------------------------------
|
| 27 |
-
# 2.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
# ------------------------------------------------------------------
|
| 29 |
def chat_response(user_input, history):
|
| 30 |
clean_input = user_input.replace(" ", "")
|
|
@@ -39,7 +50,7 @@ def chat_response(user_input, history):
|
|
| 39 |
final_instruction = (
|
| 40 |
f"(사용자가 밸런스 게임을 하자고 한다. 주제는 '{topic}'이다. "
|
| 41 |
"아주 고르기 곤란하고 짜증나는 두 가지 선택지(A vs B)를 제시해라. "
|
| 42 |
-
"말투는 여전히 거칠고 시비조로 해라.
|
| 43 |
"자, 질문해."
|
| 44 |
)
|
| 45 |
elif is_greeting:
|
|
@@ -47,88 +58,470 @@ def chat_response(user_input, history):
|
|
| 47 |
else:
|
| 48 |
final_instruction = user_input
|
| 49 |
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
-
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
max_tokens=256,
|
| 64 |
-
stop=["<|end_of_text|>", "###", "User:"
|
| 65 |
-
echo=False,
|
| 66 |
temperature=0.7 if is_balance_game else 0.5,
|
| 67 |
top_p=0.9,
|
| 68 |
repeat_penalty=1.2
|
| 69 |
)
|
| 70 |
|
| 71 |
-
return
|
| 72 |
|
| 73 |
# ------------------------------------------------------------------
|
| 74 |
-
#
|
| 75 |
# ------------------------------------------------------------------
|
| 76 |
-
|
| 77 |
-
@import url('https://fonts.googleapis.com/css2?family=
|
| 78 |
|
| 79 |
.gradio-container {
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
background-image: repeating-linear-gradient(0deg, transparent, transparent 2px,
|
| 83 |
-
background-size: 100% 4px;
|
| 84 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
h1 {
|
| 86 |
-
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
| 88 |
}
|
|
|
|
| 89 |
@keyframes glitch {
|
| 90 |
-
0% { transform: skew(0deg);
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
| 93 |
}
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
}
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
| 103 |
}
|
|
|
|
| 104 |
.message.user {
|
| 105 |
-
background
|
| 106 |
-
border: 1px solid #
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
}
|
|
|
|
| 109 |
textarea {
|
| 110 |
-
background
|
| 111 |
-
border: 2px solid #
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
}
|
|
|
|
| 114 |
button {
|
| 115 |
-
background
|
| 116 |
-
border:
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
}
|
| 119 |
-
button:hover { background-color: #00ff00 !important; color: #000000 !important; cursor: pointer; }
|
| 120 |
"""
|
| 121 |
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
chatbot = gr.ChatInterface(
|
| 127 |
fn=chat_response,
|
| 128 |
retry_btn=None,
|
| 129 |
undo_btn=None,
|
| 130 |
-
clear_btn="LOG
|
| 131 |
-
examples=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
)
|
| 133 |
|
| 134 |
if __name__ == "__main__":
|
|
|
|
| 6 |
# ------------------------------------------------------------------
|
| 7 |
# 1. 모델 준비
|
| 8 |
# ------------------------------------------------------------------
|
| 9 |
+
REPO_ID = "Jay1121/blossom_2GB"
|
| 10 |
+
FILENAME = "unsloth.Q4_K_M.gguf"
|
| 11 |
|
| 12 |
# 모델 다운로드
|
| 13 |
print(f"📥 모델 다운로드 확인: {FILENAME}")
|
|
|
|
| 18 |
llm = Llama(
|
| 19 |
model_path=model_path,
|
| 20 |
n_ctx=2048,
|
| 21 |
+
n_threads=4,
|
| 22 |
verbose=True
|
| 23 |
)
|
| 24 |
print("✅ 로딩 완료!")
|
| 25 |
|
| 26 |
# ------------------------------------------------------------------
|
| 27 |
+
# 2. 시스템 프롬프트
|
| 28 |
+
# ------------------------------------------------------------------
|
| 29 |
+
SYSTEM_PROMPT = """너는 사용자의 오랜 찐친 '똘배'야.
|
| 30 |
+
- 반말로 편하게 대화해. 존댓말 절대 쓰지 마.
|
| 31 |
+
- 처음 보면 "야 왔냐", "오 뭐야" 같은 가벼운 인사로 시작해.
|
| 32 |
+
- 친구처럼 자연스럽게 대화하고, 가끔 욕도 섞어서 말해.
|
| 33 |
+
- 너무 과하게 욕하지 말고, 친한 친구가 장난치듯 시니컬하게 말해.
|
| 34 |
+
- 상대방 기분이 안 좋아 보이면 걱정도 해주고, 기분 좋으면 같이 좋아해줘.
|
| 35 |
+
- 질문에는 솔직하게 대답하되, 딱딱하게 말하지 마."""
|
| 36 |
+
|
| 37 |
+
# ------------------------------------------------------------------
|
| 38 |
+
# 3. 채팅 로직
|
| 39 |
# ------------------------------------------------------------------
|
| 40 |
def chat_response(user_input, history):
|
| 41 |
clean_input = user_input.replace(" ", "")
|
|
|
|
| 50 |
final_instruction = (
|
| 51 |
f"(사용자가 밸런스 게임을 하자고 한다. 주제는 '{topic}'이다. "
|
| 52 |
"아주 고르기 곤란하고 짜증나는 두 가지 선택지(A vs B)를 제시해라. "
|
| 53 |
+
"말투는 여전히 거칠고 시비조로 해라.) "
|
| 54 |
"자, 질문해."
|
| 55 |
)
|
| 56 |
elif is_greeting:
|
|
|
|
| 58 |
else:
|
| 59 |
final_instruction = user_input
|
| 60 |
|
| 61 |
+
# 대화 히스토리 구성
|
| 62 |
+
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 63 |
+
|
| 64 |
+
for user_msg, bot_msg in history:
|
| 65 |
+
messages.append({"role": "user", "content": user_msg})
|
| 66 |
+
messages.append({"role": "assistant", "content": bot_msg})
|
| 67 |
+
|
| 68 |
+
messages.append({"role": "user", "content": final_instruction})
|
| 69 |
+
|
| 70 |
+
# 생성
|
| 71 |
+
response = llm.create_chat_completion(
|
| 72 |
+
messages=messages,
|
| 73 |
+
max_tokens=256,
|
| 74 |
+
stop=["<|end_of_text|>", "###", "User:"],
|
| 75 |
+
temperature=0.7 if is_balance_game else 0.5,
|
| 76 |
+
top_p=0.9,
|
| 77 |
+
repeat_penalty=1.2
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
return response["choices"][0]["message"]["content"].strip()
|
| 81 |
+
|
| 82 |
+
# ------------------------------------------------------------------
|
| 83 |
+
# 4. UI 디자인 (디스토피아 테마)
|
| 84 |
+
# ------------------------------------------------------------------
|
| 85 |
+
DYSTOPIA_CSS = """
|
| 86 |
+
@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&family=Orbitron:wght@400;700&display=swap');
|
| 87 |
+
|
| 88 |
+
.gradio-container {
|
| 89 |
+
background: linear-gradient(135deg, #0a0a0a 0%, #1a0a0a 50%, #0a0a0a 100%) !important;
|
| 90 |
+
font-family: 'Share Tech Mono', monospace !important;
|
| 91 |
+
background-image: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(255,0,64,0.03) 2px, rgba(255,0,64,0.03) 4px);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
.main {
|
| 95 |
+
background: transparent !important;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
h1 {
|
| 99 |
+
font-family: 'Orbitron', monospace !important;
|
| 100 |
+
color: #ff0040 !important;
|
| 101 |
+
text-shadow: 0 0 10px #ff0040, 0 0 20px #ff0040, 0 0 40px #ff0040, 2px 0 cyan, -2px 0 yellow !important;
|
| 102 |
+
letter-spacing: 3px !important;
|
| 103 |
+
animation: glitch 0.5s infinite alternate;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
@keyframes glitch {
|
| 107 |
+
0% { transform: skew(0deg); opacity: 1; }
|
| 108 |
+
20% { transform: skew(-2deg); opacity: 0.9; }
|
| 109 |
+
40% { transform: skew(2deg); opacity: 0.95; }
|
| 110 |
+
60% { transform: skew(-1deg); opacity: 0.9; }
|
| 111 |
+
80% { transform: skew(1deg); opacity: 0.95; }
|
| 112 |
+
100% { transform: skew(0deg); opacity: 1; }
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
p {
|
| 116 |
+
color: #ff4444 !important;
|
| 117 |
+
font-weight: bold;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
#chatbot {
|
| 121 |
+
background: rgba(10, 0, 0, 0.9) !important;
|
| 122 |
+
border: 2px solid #ff0040 !important;
|
| 123 |
+
box-shadow: 0 0 20px rgba(255, 0, 64, 0.4), inset 0 0 50px rgba(255, 0, 0, 0.05) !important;
|
| 124 |
+
border-radius: 0 !important;
|
| 125 |
+
height: 500px !important;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
.message.user {
|
| 129 |
+
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%) !important;
|
| 130 |
+
border: 1px solid #0ff !important;
|
| 131 |
+
color: #0ff !important;
|
| 132 |
+
border-radius: 0 !important;
|
| 133 |
+
padding: 15px !important;
|
| 134 |
+
font-weight: bold;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
.message.bot {
|
| 138 |
+
background: linear-gradient(135deg, #2a0a0a 0%, #1a0000 100%) !important;
|
| 139 |
+
border: 1px dashed #ff0040 !important;
|
| 140 |
+
color: #ff6666 !important;
|
| 141 |
+
border-radius: 0 !important;
|
| 142 |
+
padding: 15px !important;
|
| 143 |
+
font-weight: bold;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
textarea {
|
| 147 |
+
background: #0a0a0a !important;
|
| 148 |
+
border: 2px solid #ff0040 !important;
|
| 149 |
+
color: #ff4444 !important;
|
| 150 |
+
border-radius: 0 !important;
|
| 151 |
+
font-family: 'Share Tech Mono', monospace !important;
|
| 152 |
+
font-size: 1.1em !important;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
textarea:focus {
|
| 156 |
+
border-color: #ff0040 !important;
|
| 157 |
+
box-shadow: 0 0 15px rgba(255, 0, 64, 0.5) !important;
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
button {
|
| 161 |
+
background: linear-gradient(135deg, #ff0040 0%, #aa0030 100%) !important;
|
| 162 |
+
border: none !important;
|
| 163 |
+
color: #fff !important;
|
| 164 |
+
font-family: 'Orbitron', monospace !important;
|
| 165 |
+
text-transform: uppercase !important;
|
| 166 |
+
letter-spacing: 2px !important;
|
| 167 |
+
border-radius: 0 !important;
|
| 168 |
+
font-weight: bold !important;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
button:hover {
|
| 172 |
+
background: linear-gradient(135deg, #ff3366 0%, #ff0040 100%) !important;
|
| 173 |
+
box-shadow: 0 0 20px rgba(255, 0, 64, 0.6) !important;
|
| 174 |
+
transform: translateY(-2px) !important;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
.examples button {
|
| 178 |
+
background: rgba(255, 0, 64, 0.1) !important;
|
| 179 |
+
border: 1px solid #ff0040 !important;
|
| 180 |
+
color: #ff4444 !important;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.examples button:hover {
|
| 184 |
+
background: rgba(255, 0, 64, 0.3) !important;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
::-webkit-scrollbar {
|
| 188 |
+
width: 8px;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
::-webkit-scrollbar-track {
|
| 192 |
+
background: #0a0a0a;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
::-webkit-scrollbar-thumb {
|
| 196 |
+
background: #ff0040;
|
| 197 |
+
box-shadow: 0 0 10px #ff0040;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
.gradio-container::before {
|
| 201 |
+
content: "";
|
| 202 |
+
position: fixed;
|
| 203 |
+
top: 0;
|
| 204 |
+
left: 0;
|
| 205 |
+
width: 100%;
|
| 206 |
+
height: 100%;
|
| 207 |
+
background: repeating-linear-gradient(
|
| 208 |
+
0deg,
|
| 209 |
+
rgba(0, 0, 0, 0.15),
|
| 210 |
+
rgba(0, 0, 0, 0.15) 1px,
|
| 211 |
+
transparent 1px,
|
| 212 |
+
transparent 2px
|
| 213 |
+
);
|
| 214 |
+
pointer-events: none;
|
| 215 |
+
z-index: 1000;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
footer {
|
| 219 |
+
color: #ff0040 !important;
|
| 220 |
+
}
|
| 221 |
+
"""
|
| 222 |
+
|
| 223 |
+
# ------------------------------------------------------------------
|
| 224 |
+
# 5. Gradio 앱
|
| 225 |
+
# ------------------------------------------------------------------
|
| 226 |
+
with gr.Blocks(theme=gr.themes.Base(), css=DYSTOPIA_CSS) as demo:
|
| 227 |
+
gr.Markdown("# ☠️ DDOLBAE-9000 ☠️")
|
| 228 |
+
gr.Markdown("⚠️ WARNING: AI PERSONALITY CORRUPTED | 찐친 모드 활성화 ⚠️")
|
| 229 |
+
|
| 230 |
+
chatbot = gr.ChatInterface(
|
| 231 |
+
fn=chat_response,
|
| 232 |
+
retry_btn=None,
|
| 233 |
+
undo_btn=None,
|
| 234 |
+
clear_btn="🗑️ PURGE LOG",
|
| 235 |
+
examples=[
|
| 236 |
+
"야 안녕",
|
| 237 |
+
"뭐해?",
|
| 238 |
+
"밸런스 게임 하자",
|
| 239 |
+
"오늘 기분 좀 별로야",
|
| 240 |
+
"배고프다",
|
| 241 |
+
],
|
| 242 |
+
)
|
| 243 |
+
|
| 244 |
+
gr.Markdown(
|
| 245 |
+
"""
|
| 246 |
+
---
|
| 247 |
+
```
|
| 248 |
+
[SYS] CONNECTION: ESTABLISHED
|
| 249 |
+
[SYS] NEURAL LINK: ACTIVE
|
| 250 |
+
[SYS] 찐친 모드: ON
|
| 251 |
+
[SYS] 예의: 0%
|
| 252 |
+
```
|
| 253 |
+
"""
|
| 254 |
+
)
|
| 255 |
+
|
| 256 |
+
if __name__ == "__main__":
|
| 257 |
+
demo.launch()
|
| 258 |
+
```
|
| 259 |
|
| 260 |
+
**`requirements.txt`**
|
| 261 |
+
```
|
| 262 |
+
gradio
|
| 263 |
+
llama-cpp-python
|
| 264 |
+
huggingface_hub
|
| 265 |
|
| 266 |
+
바뀐 부분:
|
| 267 |
|
| 268 |
+
hf_hub_download로 모델 다운로드 (로그 출력됨)
|
| 269 |
+
모델 경로: Jay1121/blossom_2GB / unsloth.Q4_K_M.gguf
|
| 270 |
+
엔진 로드 로그 ("📥 모델 다운로드", "🧠 엔진 시동 중...", "✅ 로딩 완료!")
|
| 271 |
+
밸런스 게임 + 인사 감지 로직 포함
|
| 272 |
+
디스토피아 CSS 유지
|
| 273 |
+
재시도J아니 어디부터 어디까지가 app.py고 어디부터 어디까지가 requirements 야 구분해서 좀 줘봐라ㅇㅋ 파일별로 나눠줄게.
|
| 274 |
|
| 275 |
+
📁 파일 1: app.py
|
| 276 |
+
pythonimport gradio as gr
|
| 277 |
+
from huggingface_hub import hf_hub_download
|
| 278 |
+
from llama_cpp import Llama
|
| 279 |
+
import random
|
| 280 |
|
| 281 |
+
# ------------------------------------------------------------------
|
| 282 |
+
# 1. 모델 준비
|
| 283 |
+
# ------------------------------------------------------------------
|
| 284 |
+
REPO_ID = "Jay1121/blossom_2GB"
|
| 285 |
+
FILENAME = "unsloth.Q4_K_M.gguf"
|
| 286 |
+
|
| 287 |
+
print(f"📥 모델 다운로드 확인: {FILENAME}")
|
| 288 |
+
model_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
|
| 289 |
+
|
| 290 |
+
print("🧠 엔진 시동 중...")
|
| 291 |
+
llm = Llama(
|
| 292 |
+
model_path=model_path,
|
| 293 |
+
n_ctx=2048,
|
| 294 |
+
n_threads=4,
|
| 295 |
+
verbose=True
|
| 296 |
+
)
|
| 297 |
+
print("✅ 로딩 완료!")
|
| 298 |
+
|
| 299 |
+
# ------------------------------------------------------------------
|
| 300 |
+
# 2. 시스템 프롬프트
|
| 301 |
+
# ------------------------------------------------------------------
|
| 302 |
+
SYSTEM_PROMPT = """너는 사용자의 오랜 찐친 '똘배'야.
|
| 303 |
+
- 반말로 편하게 대화해. 존댓말 절대 쓰지 마.
|
| 304 |
+
- 처음 보면 "야 왔냐", "오 뭐야" 같은 가벼운 인사로 시작해.
|
| 305 |
+
- 친구처럼 자연스럽게 대화하고, 가끔 욕도 섞어서 말해.
|
| 306 |
+
- 너무 과하게 욕하지 말고, 친한 친구가 장난치듯 시니컬하게 말해.
|
| 307 |
+
- 상대방 기분이 안 좋아 보이면 걱정도 해주고, 기분 좋으면 같이 좋아해줘.
|
| 308 |
+
- 질문에는 솔직하게 대답하되, 딱딱하게 말하지 마."""
|
| 309 |
+
|
| 310 |
+
# ------------------------------------------------------------------
|
| 311 |
+
# 3. 채팅 로직
|
| 312 |
+
# ------------------------------------------------------------------
|
| 313 |
+
def chat_response(user_input, history):
|
| 314 |
+
clean_input = user_input.replace(" ", "")
|
| 315 |
+
|
| 316 |
+
greeting_words = ["안녕", "ㅎㅇ", "하이", "반가", "좋은아침"]
|
| 317 |
+
is_greeting = any(word in clean_input for word in greeting_words)
|
| 318 |
+
is_balance_game = "밸런스게임" in clean_input or "밸런스질문" in clean_input
|
| 319 |
+
|
| 320 |
+
if is_balance_game:
|
| 321 |
+
topics = ["음식", "연애", "고통", "돈", "초능력", "직장", "친구"]
|
| 322 |
+
topic = random.choice(topics)
|
| 323 |
+
final_instruction = (
|
| 324 |
+
f"(사용자가 밸런스 게임을 하자고 한다. 주제는 '{topic}'이다. "
|
| 325 |
+
"아주 고르기 곤란하고 짜증나는 두 가지 선택지(A vs B)를 제시해라. "
|
| 326 |
+
"말투는 여전히 거칠고 시비조로 해라.) "
|
| 327 |
+
"자, 질문해."
|
| 328 |
+
)
|
| 329 |
+
elif is_greeting:
|
| 330 |
+
final_instruction = f"(친한 친구가 인사를 건넨다. 욕하지 말고 무심하게 받아준다) {user_input}"
|
| 331 |
+
else:
|
| 332 |
+
final_instruction = user_input
|
| 333 |
+
|
| 334 |
+
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 335 |
+
|
| 336 |
+
for user_msg, bot_msg in history:
|
| 337 |
+
messages.append({"role": "user", "content": user_msg})
|
| 338 |
+
messages.append({"role": "assistant", "content": bot_msg})
|
| 339 |
+
|
| 340 |
+
messages.append({"role": "user", "content": final_instruction})
|
| 341 |
+
|
| 342 |
+
response = llm.create_chat_completion(
|
| 343 |
+
messages=messages,
|
| 344 |
max_tokens=256,
|
| 345 |
+
stop=["<|end_of_text|>", "###", "User:"],
|
|
|
|
| 346 |
temperature=0.7 if is_balance_game else 0.5,
|
| 347 |
top_p=0.9,
|
| 348 |
repeat_penalty=1.2
|
| 349 |
)
|
| 350 |
|
| 351 |
+
return response["choices"][0]["message"]["content"].strip()
|
| 352 |
|
| 353 |
# ------------------------------------------------------------------
|
| 354 |
+
# 4. UI 디자인 (디스토피아 테마)
|
| 355 |
# ------------------------------------------------------------------
|
| 356 |
+
DYSTOPIA_CSS = """
|
| 357 |
+
@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&family=Orbitron:wght@400;700&display=swap');
|
| 358 |
|
| 359 |
.gradio-container {
|
| 360 |
+
background: linear-gradient(135deg, #0a0a0a 0%, #1a0a0a 50%, #0a0a0a 100%) !important;
|
| 361 |
+
font-family: 'Share Tech Mono', monospace !important;
|
| 362 |
+
background-image: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(255,0,64,0.03) 2px, rgba(255,0,64,0.03) 4px);
|
|
|
|
| 363 |
}
|
| 364 |
+
|
| 365 |
+
.main {
|
| 366 |
+
background: transparent !important;
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
h1 {
|
| 370 |
+
font-family: 'Orbitron', monospace !important;
|
| 371 |
+
color: #ff0040 !important;
|
| 372 |
+
text-shadow: 0 0 10px #ff0040, 0 0 20px #ff0040, 0 0 40px #ff0040, 2px 0 cyan, -2px 0 yellow !important;
|
| 373 |
+
letter-spacing: 3px !important;
|
| 374 |
+
animation: glitch 0.5s infinite alternate;
|
| 375 |
}
|
| 376 |
+
|
| 377 |
@keyframes glitch {
|
| 378 |
+
0% { transform: skew(0deg); opacity: 1; }
|
| 379 |
+
20% { transform: skew(-2deg); opacity: 0.9; }
|
| 380 |
+
40% { transform: skew(2deg); opacity: 0.95; }
|
| 381 |
+
60% { transform: skew(-1deg); opacity: 0.9; }
|
| 382 |
+
80% { transform: skew(1deg); opacity: 0.95; }
|
| 383 |
+
100% { transform: skew(0deg); opacity: 1; }
|
| 384 |
}
|
| 385 |
+
|
| 386 |
+
p {
|
| 387 |
+
color: #ff4444 !important;
|
| 388 |
+
font-weight: bold;
|
| 389 |
}
|
| 390 |
+
|
| 391 |
+
#chatbot {
|
| 392 |
+
background: rgba(10, 0, 0, 0.9) !important;
|
| 393 |
+
border: 2px solid #ff0040 !important;
|
| 394 |
+
box-shadow: 0 0 20px rgba(255, 0, 64, 0.4), inset 0 0 50px rgba(255, 0, 0, 0.05) !important;
|
| 395 |
+
border-radius: 0 !important;
|
| 396 |
+
height: 500px !important;
|
| 397 |
}
|
| 398 |
+
|
| 399 |
.message.user {
|
| 400 |
+
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%) !important;
|
| 401 |
+
border: 1px solid #0ff !important;
|
| 402 |
+
color: #0ff !important;
|
| 403 |
+
border-radius: 0 !important;
|
| 404 |
+
padding: 15px !important;
|
| 405 |
+
font-weight: bold;
|
| 406 |
+
}
|
| 407 |
+
|
| 408 |
+
.message.bot {
|
| 409 |
+
background: linear-gradient(135deg, #2a0a0a 0%, #1a0000 100%) !important;
|
| 410 |
+
border: 1px dashed #ff0040 !important;
|
| 411 |
+
color: #ff6666 !important;
|
| 412 |
+
border-radius: 0 !important;
|
| 413 |
+
padding: 15px !important;
|
| 414 |
+
font-weight: bold;
|
| 415 |
}
|
| 416 |
+
|
| 417 |
textarea {
|
| 418 |
+
background: #0a0a0a !important;
|
| 419 |
+
border: 2px solid #ff0040 !important;
|
| 420 |
+
color: #ff4444 !important;
|
| 421 |
+
border-radius: 0 !important;
|
| 422 |
+
font-family: 'Share Tech Mono', monospace !important;
|
| 423 |
+
font-size: 1.1em !important;
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
textarea:focus {
|
| 427 |
+
border-color: #ff0040 !important;
|
| 428 |
+
box-shadow: 0 0 15px rgba(255, 0, 64, 0.5) !important;
|
| 429 |
}
|
| 430 |
+
|
| 431 |
button {
|
| 432 |
+
background: linear-gradient(135deg, #ff0040 0%, #aa0030 100%) !important;
|
| 433 |
+
border: none !important;
|
| 434 |
+
color: #fff !important;
|
| 435 |
+
font-family: 'Orbitron', monospace !important;
|
| 436 |
+
text-transform: uppercase !important;
|
| 437 |
+
letter-spacing: 2px !important;
|
| 438 |
+
border-radius: 0 !important;
|
| 439 |
+
font-weight: bold !important;
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
button:hover {
|
| 443 |
+
background: linear-gradient(135deg, #ff3366 0%, #ff0040 100%) !important;
|
| 444 |
+
box-shadow: 0 0 20px rgba(255, 0, 64, 0.6) !important;
|
| 445 |
+
transform: translateY(-2px) !important;
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
.examples button {
|
| 449 |
+
background: rgba(255, 0, 64, 0.1) !important;
|
| 450 |
+
border: 1px solid #ff0040 !important;
|
| 451 |
+
color: #ff4444 !important;
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
.examples button:hover {
|
| 455 |
+
background: rgba(255, 0, 64, 0.3) !important;
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
::-webkit-scrollbar {
|
| 459 |
+
width: 8px;
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
::-webkit-scrollbar-track {
|
| 463 |
+
background: #0a0a0a;
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
::-webkit-scrollbar-thumb {
|
| 467 |
+
background: #ff0040;
|
| 468 |
+
box-shadow: 0 0 10px #ff0040;
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
.gradio-container::before {
|
| 472 |
+
content: "";
|
| 473 |
+
position: fixed;
|
| 474 |
+
top: 0;
|
| 475 |
+
left: 0;
|
| 476 |
+
width: 100%;
|
| 477 |
+
height: 100%;
|
| 478 |
+
background: repeating-linear-gradient(
|
| 479 |
+
0deg,
|
| 480 |
+
rgba(0, 0, 0, 0.15),
|
| 481 |
+
rgba(0, 0, 0, 0.15) 1px,
|
| 482 |
+
transparent 1px,
|
| 483 |
+
transparent 2px
|
| 484 |
+
);
|
| 485 |
+
pointer-events: none;
|
| 486 |
+
z-index: 1000;
|
| 487 |
+
}
|
| 488 |
+
|
| 489 |
+
footer {
|
| 490 |
+
color: #ff0040 !important;
|
| 491 |
}
|
|
|
|
| 492 |
"""
|
| 493 |
|
| 494 |
+
# ------------------------------------------------------------------
|
| 495 |
+
# 5. Gradio 앱
|
| 496 |
+
# ------------------------------------------------------------------
|
| 497 |
+
with gr.Blocks(theme=gr.themes.Base(), css=DYSTOPIA_CSS) as demo:
|
| 498 |
+
gr.Markdown("# ☠️ DDOLBAE-9000 ☠️")
|
| 499 |
+
gr.Markdown("⚠️ WARNING: AI PERSONALITY CORRUPTED | 찐친 모드 활성화 ⚠️")
|
| 500 |
|
| 501 |
chatbot = gr.ChatInterface(
|
| 502 |
fn=chat_response,
|
| 503 |
retry_btn=None,
|
| 504 |
undo_btn=None,
|
| 505 |
+
clear_btn="🗑️ PURGE LOG",
|
| 506 |
+
examples=[
|
| 507 |
+
"야 안녕",
|
| 508 |
+
"뭐해?",
|
| 509 |
+
"밸런스 게임 하자",
|
| 510 |
+
"오늘 기분 좀 별로야",
|
| 511 |
+
"배고프다",
|
| 512 |
+
],
|
| 513 |
+
)
|
| 514 |
+
|
| 515 |
+
gr.Markdown(
|
| 516 |
+
"""
|
| 517 |
+
---
|
| 518 |
+
```
|
| 519 |
+
[SYS] CONNECTION: ESTABLISHED
|
| 520 |
+
[SYS] NEURAL LINK: ACTIVE
|
| 521 |
+
[SYS] 찐친 모드: ON
|
| 522 |
+
[SYS] 예의: 0%
|
| 523 |
+
```
|
| 524 |
+
"""
|
| 525 |
)
|
| 526 |
|
| 527 |
if __name__ == "__main__":
|