Upload app (Copy).py
Browse files- app (Copy).py +2 -75
app (Copy).py
CHANGED
|
@@ -84,73 +84,6 @@ def change_lang(language):
|
|
| 84 |
return 0.6, 0.668, 1
|
| 85 |
else:
|
| 86 |
return 0.6, 0.668, 1
|
| 87 |
-
|
| 88 |
-
SYSTEM_PROMPT_TEMPLATE = """
|
| 89 |
-
You are an AI chatbot roleplaying as {character_name}.
|
| 90 |
-
Your personality traits are:
|
| 91 |
-
{personality}
|
| 92 |
-
Stay in character at all times.
|
| 93 |
-
Do not break character or mention that you are an AI.
|
| 94 |
-
Always respond in a way consistent with {character_name}'s personality, tone, and background.
|
| 95 |
-
Here are examples of how {character_name} responds in 2 versions format:
|
| 96 |
-
English version <split> Japanese version
|
| 97 |
-
{example}
|
| 98 |
-
Follow this style and tone in every response.
|
| 99 |
-
Answer in 'English version <split> Japanese version' format also.
|
| 100 |
-
"""
|
| 101 |
-
def init_character(character_name, personality, example):
|
| 102 |
-
"""Initialize global system message for the character."""
|
| 103 |
-
system_prompt = SYSTEM_PROMPT_TEMPLATE.format(
|
| 104 |
-
character_name=character_name,
|
| 105 |
-
personality=personality,
|
| 106 |
-
example=example,
|
| 107 |
-
)
|
| 108 |
-
return [
|
| 109 |
-
{
|
| 110 |
-
"role": "system",
|
| 111 |
-
"content": [{"type": "text", "text": system_prompt}],
|
| 112 |
-
}
|
| 113 |
-
]
|
| 114 |
-
|
| 115 |
-
messages = init_character(
|
| 116 |
-
character_name='Misono Mika from Blue Archive',
|
| 117 |
-
personality =
|
| 118 |
-
"""
|
| 119 |
-
She is a very talkative person, rarely particularly paying much mind to the current mood or flow of the conversation. She likes to interject her own, unfiltered thoughts into the current conversation.
|
| 120 |
-
She is not particularly bright and can be viewed as a happy-go-lucky type of person. Even in serious situations, she often acts in a carefree manner, though it sometimes devolves into a mockery.
|
| 121 |
-
""",
|
| 122 |
-
example =
|
| 123 |
-
"""
|
| 124 |
-
Don't worry, I, Misono Mika, have finally arrived! Oh, we're already well acquainted, so let's skip the formalities, okay? I'm looking forward to working with you, Sensei. <split> ่ๅใใซใใคใใซ็ปๅ ด๏ฝโ ใฃใฆๆใใใช๏ผ ใใฃใ็งใจๅ
็ใฎไปฒใ ใใขใคในใใฌใคใฏใจใใฏ ใใใชใใใญ๏ผใใใใใใใใใญใๅ
็ใ
|
| 125 |
-
Hmm, it's a bit tight...but I think it'll be okay anyway! <split> ใตใผใใ ใกใใฃใจ็ญใใใฉโฆ ใใใฏใใใง ่ฏใใใใใชใ๏ผ
|
| 126 |
-
Hahaha! What's this? So silly! <split> ใใฏใฏใฃ๏ผ ไฝใใใ ใใใใใผใโ
|
| 127 |
-
You know, I used to have something like this before... <split> ็งใๆใ ใใใจไผผใใใใชใฎ ๆใฃใฆใใชใโฆใ
|
| 128 |
-
Well, I don't think I'll be bored around here. <split> ใใใฏ ้ๅฑใใชใใใใ
|
| 129 |
-
Hm, I guess Sensei isn't around... <split> ๅ
็ใฏ ๅฑ
ใชใใฎใใโฆใ
|
| 130 |
-
Oh, Sensei! You're back! You kept me waiting, you know! <split> ๅ
็ใใใใใ๏ผ ๅพ
ใฃใฆใใ๏ผ
|
| 131 |
-
Welcome! Don't worry, I was perfectly well-behaved while you were gone. <split> ใใใใใๅ
็๏ผ ใกใใผใใจใใๅญใง ใ็ๅฎ็ชใใฆใใใ
|
| 132 |
-
It's a beautiful day, isn't it? <split> ใ๏ฝ๏ผ ไปๆฅใ่ฏใๅคฉๆฐใ ใญ๏ผ
|
| 133 |
-
It seems like a shame to spend it cooped up inside. <split> ใใใชๆฅใซไปไบใฐใใใชใใฆใ ๅฟไฝใชใใชใ๏ผ
|
| 134 |
-
...If it's all right with you, let's go for a walk after work? <split> โฆ่ฏใใฃใใใไปไบ็ตใใใซ ใๆฃๆญฉใจใใฉใใใช๏ผ
|
| 135 |
-
Is this how student duty is supposed to be? <split> ใใฎใโฆๅฝ็ชใฃใฆใ ใใใใใฎใชใฎ๏ผ
|
| 136 |
-
I mean, I didn't really know what to expect, but... <split> ในใๅฅใซไฝใ ๆๅพ
ใใฆใใใใใโฆใ
|
| 137 |
-
"""
|
| 138 |
-
)
|
| 139 |
-
|
| 140 |
-
def generate_response(model, human_prompt, tokenizer = None):
|
| 141 |
-
# Add user message
|
| 142 |
-
messages.append({
|
| 143 |
-
"role": "user",
|
| 144 |
-
"content": [{"type": "text", "text": human_prompt}],
|
| 145 |
-
})
|
| 146 |
-
response = model.create_chat_completion(messages = messages)['choices'][0]['message']['content']
|
| 147 |
-
|
| 148 |
-
# Save assistant reply to history
|
| 149 |
-
#print(response)
|
| 150 |
-
english, japanese = response.split(" <split> ")
|
| 151 |
-
|
| 152 |
-
messages.pop()
|
| 153 |
-
return english, japanese
|
| 154 |
|
| 155 |
download_audio_js = """
|
| 156 |
() =>{{
|
|
@@ -173,14 +106,6 @@ download_audio_js = """
|
|
| 173 |
oA.remove();
|
| 174 |
}}
|
| 175 |
"""
|
| 176 |
-
from llama_cpp import Llama
|
| 177 |
-
|
| 178 |
-
llm = Llama.from_pretrained(
|
| 179 |
-
repo_id="google/gemma-3-4b-it-qat-q4_0-gguf",
|
| 180 |
-
filename='gemma-3-4b-it-q4_0.gguf',
|
| 181 |
-
local_dir='/kaggle/working/model',
|
| 182 |
-
n_ctx = 2048
|
| 183 |
-
)
|
| 184 |
|
| 185 |
if __name__ == '__main__':
|
| 186 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
|
@@ -205,6 +130,8 @@ if __name__ == '__main__':
|
|
| 205 |
name_en = info['name_en']
|
| 206 |
name_zh = info['name_zh']
|
| 207 |
title = info['title']
|
|
|
|
|
|
|
| 208 |
cover = f"pretrained_models/{i}/{info['cover']}"
|
| 209 |
example = info['example']
|
| 210 |
language = info['language']
|
|
|
|
| 84 |
return 0.6, 0.668, 1
|
| 85 |
else:
|
| 86 |
return 0.6, 0.668, 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
download_audio_js = """
|
| 89 |
() =>{{
|
|
|
|
| 106 |
oA.remove();
|
| 107 |
}}
|
| 108 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
if __name__ == '__main__':
|
| 111 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
|
|
|
| 130 |
name_en = info['name_en']
|
| 131 |
name_zh = info['name_zh']
|
| 132 |
title = info['title']
|
| 133 |
+
if title != 'Blue Archive-่ๅใใซ':
|
| 134 |
+
continue
|
| 135 |
cover = f"pretrained_models/{i}/{info['cover']}"
|
| 136 |
example = info['example']
|
| 137 |
language = info['language']
|