Spaces:
Running
on
Zero
Running
on
Zero
tori29umai
commited on
Commit
•
5a94012
1
Parent(s):
c3199d5
Update app.py
Browse files
app.py
CHANGED
@@ -26,7 +26,7 @@ def save_settings_to_ini(settings, filename='character_settings.ini'):
|
|
26 |
'gender': settings['gender'],
|
27 |
'situation': '\n'.join(settings['situation']),
|
28 |
'orders': '\n'.join(settings['orders']),
|
29 |
-
'
|
30 |
'example_quotes': '\n'.join(settings['example_quotes'])
|
31 |
}
|
32 |
with open(filename, 'w', encoding='utf-8') as configfile:
|
@@ -49,7 +49,7 @@ def load_settings_from_ini(filename='character_settings.ini'):
|
|
49 |
'gender': config['Settings']['gender'],
|
50 |
'situation': config['Settings']['situation'].split('\n'),
|
51 |
'orders': config['Settings']['orders'].split('\n'),
|
52 |
-
'
|
53 |
'example_quotes': config['Settings']['example_quotes'].split('\n')
|
54 |
}
|
55 |
return settings
|
@@ -121,12 +121,12 @@ class CharacterMaker:
|
|
121 |
self.history.append({"user": input_str, "assistant": res_text})
|
122 |
return res_text
|
123 |
|
124 |
-
def make_prompt(self, name: str, gender: str, situation: list, orders: list,
|
125 |
with open('test_prompt.jinja2', 'r', encoding='utf-8') as f:
|
126 |
prompt = f.readlines()
|
127 |
fix_example_quotes = [quote+"<END>" for quote in example_quotes]
|
128 |
prompt = "".join(prompt)
|
129 |
-
prompt = Template(prompt).render(name=name, gender=gender, situation=situation, orders=orders,
|
130 |
return prompt
|
131 |
|
132 |
def _generate_aki(self, input_str: str):
|
@@ -135,7 +135,7 @@ class CharacterMaker:
|
|
135 |
self.settings["gender"],
|
136 |
self.settings["situation"],
|
137 |
self.settings["orders"],
|
138 |
-
self.settings["
|
139 |
self.settings["example_quotes"],
|
140 |
input_str
|
141 |
)
|
@@ -153,13 +153,13 @@ class CharacterMaker:
|
|
153 |
character_maker = CharacterMaker()
|
154 |
|
155 |
# 設定を更新する関数
|
156 |
-
def update_settings(name, gender, situation, orders,
|
157 |
new_settings = {
|
158 |
"name": name,
|
159 |
"gender": gender,
|
160 |
"situation": [s.strip() for s in situation.split('\n') if s.strip()],
|
161 |
"orders": [o.strip() for o in orders.split('\n') if o.strip()],
|
162 |
-
"
|
163 |
"example_quotes": [e.strip() for e in example_quotes.split('\n') if e.strip()]
|
164 |
}
|
165 |
character_maker.update_settings(new_settings)
|
@@ -221,7 +221,7 @@ with gr.Blocks(css=custom_css) as iface:
|
|
221 |
gender_input = gr.Textbox(label="性別", value=character_maker.settings["gender"])
|
222 |
situation_input = gr.Textbox(label="状況設定", value="\n".join(character_maker.settings["situation"]), lines=5)
|
223 |
orders_input = gr.Textbox(label="指示", value="\n".join(character_maker.settings["orders"]), lines=5)
|
224 |
-
|
225 |
example_quotes_input = gr.Textbox(label="例文", value="\n".join(character_maker.settings["example_quotes"]), lines=5)
|
226 |
|
227 |
update_button = gr.Button("設定を更新")
|
@@ -229,7 +229,7 @@ with gr.Blocks(css=custom_css) as iface:
|
|
229 |
|
230 |
update_button.click(
|
231 |
update_settings,
|
232 |
-
inputs=[name_input, gender_input, situation_input, orders_input,
|
233 |
outputs=[update_output]
|
234 |
)
|
235 |
|
|
|
26 |
'gender': settings['gender'],
|
27 |
'situation': '\n'.join(settings['situation']),
|
28 |
'orders': '\n'.join(settings['orders']),
|
29 |
+
'talk_list': '\n'.join(settings['talk_list']),
|
30 |
'example_quotes': '\n'.join(settings['example_quotes'])
|
31 |
}
|
32 |
with open(filename, 'w', encoding='utf-8') as configfile:
|
|
|
49 |
'gender': config['Settings']['gender'],
|
50 |
'situation': config['Settings']['situation'].split('\n'),
|
51 |
'orders': config['Settings']['orders'].split('\n'),
|
52 |
+
'talk_list': config['Settings']['talk_list'].split('\n'),
|
53 |
'example_quotes': config['Settings']['example_quotes'].split('\n')
|
54 |
}
|
55 |
return settings
|
|
|
121 |
self.history.append({"user": input_str, "assistant": res_text})
|
122 |
return res_text
|
123 |
|
124 |
+
def make_prompt(self, name: str, gender: str, situation: list, orders: list, talk_list: list, example_quotes: list, input_str: str):
|
125 |
with open('test_prompt.jinja2', 'r', encoding='utf-8') as f:
|
126 |
prompt = f.readlines()
|
127 |
fix_example_quotes = [quote+"<END>" for quote in example_quotes]
|
128 |
prompt = "".join(prompt)
|
129 |
+
prompt = Template(prompt).render(name=name, gender=gender, situation=situation, orders=orders, talk_list=talk_list, example_quotes=fix_example_quotes, histories=self.history, input_str=input_str)
|
130 |
return prompt
|
131 |
|
132 |
def _generate_aki(self, input_str: str):
|
|
|
135 |
self.settings["gender"],
|
136 |
self.settings["situation"],
|
137 |
self.settings["orders"],
|
138 |
+
self.settings["talk_list"],
|
139 |
self.settings["example_quotes"],
|
140 |
input_str
|
141 |
)
|
|
|
153 |
character_maker = CharacterMaker()
|
154 |
|
155 |
# 設定を更新する関数
|
156 |
+
def update_settings(name, gender, situation, orders, talk_list, example_quotes):
|
157 |
new_settings = {
|
158 |
"name": name,
|
159 |
"gender": gender,
|
160 |
"situation": [s.strip() for s in situation.split('\n') if s.strip()],
|
161 |
"orders": [o.strip() for o in orders.split('\n') if o.strip()],
|
162 |
+
"talk_list": [d.strip() for d in talk_list.split('\n') if d.strip()],
|
163 |
"example_quotes": [e.strip() for e in example_quotes.split('\n') if e.strip()]
|
164 |
}
|
165 |
character_maker.update_settings(new_settings)
|
|
|
221 |
gender_input = gr.Textbox(label="性別", value=character_maker.settings["gender"])
|
222 |
situation_input = gr.Textbox(label="状況設定", value="\n".join(character_maker.settings["situation"]), lines=5)
|
223 |
orders_input = gr.Textbox(label="指示", value="\n".join(character_maker.settings["orders"]), lines=5)
|
224 |
+
talk_input = gr.Textbox(label="語彙リスト", value="\n".join(character_maker.settings["talk_list"]), lines=5)
|
225 |
example_quotes_input = gr.Textbox(label="例文", value="\n".join(character_maker.settings["example_quotes"]), lines=5)
|
226 |
|
227 |
update_button = gr.Button("設定を更新")
|
|
|
229 |
|
230 |
update_button.click(
|
231 |
update_settings,
|
232 |
+
inputs=[name_input, gender_input, situation_input, orders_input, talk_input, example_quotes_input],
|
233 |
outputs=[update_output]
|
234 |
)
|
235 |
|