Shiro2 commited on
Commit
cc26414
ยท
verified ยท
1 Parent(s): b9da3a2

Upload app (Copy).py

Browse files
Files changed (1) hide show
  1. 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']