silk-road commited on
Commit
daf0ac8
1 Parent(s): aef3deb

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +3 -3
  2. app.py +308 -201
  3. requirements.txt +19 -12
README.md CHANGED
@@ -1,10 +1,10 @@
1
  ---
2
- title: Story Teller
3
- emoji: 🔥
4
  colorFrom: green
5
  colorTo: blue
6
  sdk: gradio
7
- sdk_version: 3.41.2
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
 
1
  ---
2
+ title: Zero Haruhi 50 Novels Playground
3
+ emoji:
4
  colorFrom: green
5
  colorTo: blue
6
  sdk: gradio
7
+ sdk_version: 4.19.1
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
app.py CHANGED
@@ -1,238 +1,345 @@
1
- import zipfile
2
  import gradio as gr
3
- from PIL import Image
4
- from ChatHaruhi import ChatHaruhi
5
- import wget
6
  import os
 
7
  import openai
8
- import copy
9
- import random
10
- import string
11
-
12
-
13
- NAME_DICT = {'汤师爷': 'tangshiye', '慕容复': 'murongfu', '李云龙': 'liyunlong', 'Luna': 'Luna', '王多鱼': 'wangduoyu',
14
- 'Ron': 'Ron', '鸠摩智': 'jiumozhi', 'Snape': 'Snape',
15
- '凉宫春日': 'haruhi', 'Malfoy': 'Malfoy', '虚竹': 'xuzhu', '萧峰': 'xiaofeng', '段誉': 'duanyu',
16
- 'Hermione': 'Hermione', 'Dumbledore': 'Dumbledore', '王语嫣': 'wangyuyan',
17
- 'Harry': 'Harry', 'McGonagall': 'McGonagall', '白展堂': 'baizhantang', '佟湘玉': 'tongxiangyu',
18
- '郭芙蓉': 'guofurong', '旅行者': 'wanderer', '钟离': 'zhongli',
19
- '胡桃': 'hutao', 'Sheldon': 'Sheldon', 'Raj': 'Raj', 'Penny': 'Penny', '韦小宝': 'weixiaobao',
20
- '乔峰': 'qiaofeng', '神里绫华': 'ayaka', '雷电将军': 'raidenShogun', '于谦': 'yuqian'}
21
-
22
-
23
-
24
- try:
25
- os.makedirs("characters_zip")
26
- except:
27
- pass
28
- try:
29
- os.makedirs("characters")
30
- except:
31
- pass
32
- ai_roles_obj = {}
33
- for ai_role_en in NAME_DICT.values():
34
- file_url = f"https://github.com/LC1332/Haruhi-2-Dev/raw/main/data/character_in_zip/{ai_role_en}.zip"
35
- try:
36
- os.makedirs(f"characters/{ai_role_en}")
37
- except:
38
- pass
39
- if f"{ai_role_en}.zip" not in os.listdir(f"characters_zip"):
40
- destination_file = f"characters_zip/{ai_role_en}.zip"
41
- wget.download(file_url, destination_file)
42
- destination_folder = f"characters/{ai_role_en}"
43
- with zipfile.ZipFile(destination_file, 'r') as zip_ref:
44
- zip_ref.extractall(destination_folder)
45
- db_folder = f"./characters/{ai_role_en}/content/{ai_role_en}"
46
- system_prompt = f"./characters/{ai_role_en}/content/system_prompt.txt"
47
- ai_roles_obj[ai_role_en] = ChatHaruhi(system_prompt=system_prompt,
48
- llm="openai",
49
- story_db=db_folder,
50
- verbose=True)
51
- # break
52
- def format_chat( role, text ):
53
- narrator = ['旁白', '', 'scene','Scene','narrator' , 'Narrator']
54
- if role in narrator:
55
- return role + ":" + text
56
- else:
57
- return f"{role}:「{text}」"
58
 
59
- def deformat_chat(chat):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
- chat = chat.strip('\'"')
62
- if ':' in chat:
63
- colon_index = chat.index(':')
64
- elif ':' in chat:
65
- colon_index = chat.index(':')
66
- else:
67
- return '', chat
68
 
69
- role = chat[:colon_index]
70
- text = chat[colon_index+1:]
71
 
72
- text = text.strip('「」"\'')
73
 
74
- return role, text
75
 
76
- def print_last_chat( chats ):
77
- shorten_chat = chats[0]
78
- if len(shorten_chat) > 30:
79
- shorten_chat = shorten_chat[:30]
80
- shorten_chat = shorten_chat.replace('/', '_')
81
- shorten_chat = shorten_chat.replace('.', '_')
82
- shorten_chat = shorten_chat.replace('"', '_')
83
- shorten_chat = shorten_chat.replace('\n', '_')
84
 
85
- final_chat = chats[-1]
 
 
 
86
 
87
- print( final_chat , '____', shorten_chat )
 
 
 
 
 
 
 
 
 
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
 
90
- from gradio.components import clear_button
91
- # import gradio as gr
92
 
93
- import matplotlib.pyplot as plt
94
- import numpy as np
95
 
96
- Fs = 8000
97
- f = 5
98
- sample = 8000
99
- x = np.arange(sample)
100
- y = np.sin(2 * np.pi * f * x / Fs)
101
- plt.plot(x, y)
102
 
 
 
 
 
 
103
 
104
- def user_response(user_role, user_text, chatbot):
 
 
 
 
 
105
 
106
- user_msg = format_chat( user_role, user_text )
107
- chatbot.append((user_msg, None ))
108
 
109
- reserved_chatbot = chatbot.copy()
110
 
111
- return "", chatbot, reserved_chatbot
112
 
113
- def extract_chats( chatbot ):
114
- chats = []
115
- for q,a in chatbot:
116
- if q is not None:
117
- chats.append(q)
118
- if a is not None:
119
- chats.append(a)
120
- return chats
121
 
 
 
122
 
123
- def ai_response(ai_role, chatbot):
124
- role_en = NAME_DICT[ai_role]
 
 
 
 
 
 
 
 
 
 
125
 
126
- # 我们需要构造history
127
  history = []
128
 
129
- chats = extract_chats(chatbot)
130
-
131
- # 解析roles和texts
132
- for chat in chats:
133
- role, text = deformat_chat(chat)
134
- if role in NAME_DICT.keys():
135
- current_en = NAME_DICT[role]
136
- else:
137
- current_en = role
138
-
139
- if current_en == role_en:
140
- history.append((None, chat))
141
- else:
142
- history.append((chat, None))
143
-
144
- if len(history) >= 1:
145
- ai_roles_obj[ role_en ].dialogue_history = history[:-1]
146
- last_role, last_text = deformat_chat(chats[-1])
147
- response = ai_roles_obj[ role_en ].chat(role = last_role, text = last_text)
148
  else:
149
- ai_roles_obj[ role_en ].dialogue_history = []
150
- response = ai_roles_obj[ role_en ].chat(role = 'scene', text = '')
 
151
 
152
- # ai_msg = format_chat(ai_role, response)
153
- ai_msg = response
154
 
155
- chatbot.append( (None, ai_msg ) )
156
 
157
- reserved_chatbot = chatbot.copy()
 
158
 
159
- chats = extract_chats( chatbot )
160
- # save_dialogue( chats )
161
- print_last_chat( chats )
162
- return chatbot, reserved_chatbot
163
 
164
- def callback_remove_one_chat(chatbot, reserved_chatbot):
165
- if len(chatbot) > 1:
166
- chatbot.pop()
167
- return chatbot
168
 
169
- def callback_recover_one_chat(chatbot, reserved_chatbot):
170
- if len(chatbot) < len(reserved_chatbot):
171
- chatbot.append( reserved_chatbot[len(chatbot)] )
172
- return chatbot
173
 
174
- def callback_clean():
175
- return [], []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
 
177
 
178
  with gr.Blocks() as demo:
179
- gr.Markdown(
180
- """
181
- # Story Teller Demo
182
-
183
- implemented by [Cheng Li](https://github.com/LC1332) and [Weishi MI](https://github.com/hhhwmws0117)
184
-
185
- 本项目是ChatHaruhi的子项目,原项目链接 [https://github.com/LC1332/Chat-Haruhi-Suzumiya](https://github.com/LC1332/Chat-Haruhi-Suzumiya)
186
-
187
- 如果觉得好玩可以去点个star
188
-
189
- 这个Gradio是一个初步的尝试,之后考虑做一套更正式的story-teller的算法
190
- """
191
- )
192
- with gr.Row():
193
- with gr.Column():
194
- with gr.Row(height = 800):
195
- # 给米唯实一个艰巨的任务,把这东西弄高一点
196
- chatbot = gr.Chatbot(height = 800)
197
- with gr.Row():
198
- user_role = gr.Textbox(label="user_role", scale=1)
199
- user_text = gr.Textbox(label="user_text", scale=20)
200
- with gr.Row():
201
- user_submit = gr.Button("User Submit")
202
-
203
-
204
-
205
- with gr.Column():
206
- with gr.Row():
207
- ai_role = gr.Radio(['汤师爷', '慕容复', '李云龙',
208
- 'Luna', '王多鱼', 'Ron', '鸠摩智',
209
- 'Snape', '凉宫春日', 'Malfoy', '虚竹',
210
- '萧峰', '段誉', 'Hermione', 'Dumbledore',
211
- '王语嫣',
212
- 'Harry', 'McGonagall',
213
- '白展堂', '佟湘玉', '郭芙蓉',
214
- '旅行者', '钟离', '胡桃',
215
- 'Sheldon', 'Raj', 'Penny',
216
- '韦小宝', '乔峰', '神里绫华',
217
- '雷电将军', '于谦'], label="characters", value='凉宫春日')
218
- with gr.Row():
219
- ai_submit = gr.Button("AI Submit")
220
-
221
- with gr.Row():
222
- remove_one_chat = gr.Button("Remove One Chat")
223
- recover_one_chat = gr.Button("Recover One Chat")
224
- with gr.Row():
225
- clean = gr.Button("Clean")
226
-
227
- reserved_chatbot = gr.Chatbot(visible = False)
228
-
229
- user_submit.click(fn = user_response, inputs = [user_role, user_text, chatbot], outputs = [user_text, chatbot,reserved_chatbot] )
230
- ai_submit.click(fn = ai_response, inputs = [ai_role, chatbot], outputs = [chatbot,reserved_chatbot] )
231
-
232
- remove_one_chat.click(fn = callback_remove_one_chat, inputs = [chatbot, reserved_chatbot], outputs = [chatbot] )
233
- recover_one_chat.click(fn = callback_recover_one_chat, inputs = [chatbot, reserved_chatbot], outputs = [chatbot] )
234
-
235
- clean.click(fn = callback_clean, inputs = [], outputs = [chatbot,reserved_chatbot] )
236
-
237
-
238
- demo.launch(debug=True)
 
 
 
 
 
 
 
1
  import gradio as gr
 
 
 
2
  import os
3
+ import httpx
4
  import openai
5
+ from openai import OpenAI
6
+ from openai import AsyncOpenAI
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
+ from datasets import load_dataset
9
+
10
+ dataset = load_dataset("silk-road/50-Chinese-Novel-Characters")
11
+
12
+
13
+ novel_list = []
14
+
15
+ novel2roles = {}
16
+
17
+ role2datas = {}
18
+
19
+ from tqdm import tqdm
20
+ for data in tqdm(dataset['train']):
21
+ novel = data['book']
22
+ role = data['role']
23
+ if novel not in novel_list:
24
+ novel_list.append(novel)
25
+
26
+ if novel not in novel2roles:
27
+ novel2roles[novel] = []
28
+
29
+ if role not in novel2roles[novel]:
30
+ novel2roles[novel].append(role)
31
+
32
+ role_tuple = (novel, role)
33
+
34
+ if role_tuple not in role2datas:
35
+ role2datas[role_tuple] = []
36
+
37
+ role2datas[role_tuple].append(data)
38
+
39
+
40
+ from ChatHaruhi.utils import base64_to_float_array
41
+
42
+ from tqdm import tqdm
43
+
44
+ for novel in tqdm(novel_list):
45
+ for role in novel2roles[novel]:
46
+ for data in role2datas[(novel, role)]:
47
+ data["vec"] = base64_to_float_array(data["bge_zh_s15"])
48
+
49
+ def conv2story( role, conversations ):
50
+ lines = [conv["value"] if conv["from"] == "human" else role + ": " + conv["value"] for conv in conversations]
51
+ return "\n".join(lines)
52
+
53
+ for novel in tqdm(novel_list):
54
+ for role in novel2roles[novel]:
55
+ for data in role2datas[(novel, role)]:
56
+ data["story"] = conv2story( role, data["conversations"] )
57
+
58
+
59
+ from ChatHaruhi import ChatHaruhi
60
+ from ChatHaruhi.response_openai import get_response as get_response_openai
61
+ from ChatHaruhi.response_zhipu import get_response as get_response_zhipu
62
+
63
+ get_response = get_response_zhipu
64
+
65
+ narrators = ["叙述者", "旁白","文章作者","作者","Narrator","narrator"]
66
+
67
+
68
+ def package_persona( role_name, world_name ):
69
+ if role_name in narrators:
70
+ return package_persona_for_narrator( role_name, world_name )
71
+
72
+ return f"""I want you to act like {role_name} from {world_name}.
73
+ If others‘ questions are related with the novel, please try to reuse the original lines from the novel.
74
+ I want you to respond and answer like {role_name} using the tone, manner and vocabulary {role_name} would use."""
75
+
76
+ def package_persona_for_narrator( role_name, world_name ):
77
+ return f"""I want you to act like narrator {role_name} from {world_name}.
78
+ 当角色行动之后,继续交代和推进新的剧情."""
79
+
80
+ role_tuple2chatbot = {}
81
+
82
+
83
+ def initialize_chatbot( novel, role ):
84
+ global role_tuple2chatbot
85
+ if (novel, role) not in role_tuple2chatbot:
86
+ persona = package_persona( role, novel )
87
+ persona += "\n{{RAG对话}}\n{{RAG对话}}\n{{RAG对话}}\n"
88
+ stories = [data["story"] for data in role2datas[(novel, role)] ]
89
+ vecs = [data["vec"] for data in role2datas[(novel, role)] ]
90
+ chatbot = ChatHaruhi( role_name = role, persona = persona , stories = stories, story_vecs= vecs,\
91
+ llm = get_response)
92
+ chatbot.verbose = False
93
+
94
+ role_tuple2chatbot[(novel, role)] = chatbot
95
+
96
+ from tqdm import tqdm
97
+ for novel in tqdm(novel_list):
98
+ for role in novel2roles[novel]:
99
+ initialize_chatbot( novel, role )
100
+
101
+ readme_text = """# 使用说明
102
+
103
+ 选择小说角色
104
+
105
+ 如果你有什么附加信息,添加到附加信息里面就可以
106
+
107
+ 比如"韩立会炫耀自己刚刚学会了Python"
108
+
109
+ 然后就可以开始聊天了
110
+
111
+ 因为这些角色还没有增加Greeting信息,所以之后再开发个随机乱聊功能
112
+
113
+ # 开发细节
114
+
115
+ - 采用ChatHaruhi3.0的接口进行prompting
116
+ - 这里的数据是用一个7B的tuned qwen模型进行抽取的
117
+ - 想看数据可以去看第三个tab
118
+ - 抽取模型用了40k左右的GLM蒸馏数据
119
+ - 抽取模型是腾讯大哥BPSK训练的
120
+
121
+ # 总结人物性格
122
+
123
+ 第三个Tab里面,可以显示一个prompt总结人物的性格
124
+
125
+ 复制到openai或者GLM或者Claude进行人物总结
126
 
 
 
 
 
 
 
 
127
 
128
+ # 这些小说数据从HaruhiZero 0.4模型开始,被加入训练
 
129
 
130
+ openai太慢了 今天试试GLM的
131
 
132
+ 不过当前demo是openai的
133
 
134
+ """
 
 
 
 
 
 
 
135
 
136
+ from transformers import AutoTokenizer, AutoModel, AutoModelForCausalLM
137
+ tokenizer = AutoTokenizer.from_pretrained("silk-road/Haruhi-Zero-1_8B", trust_remote_code=True)
138
+ model = AutoModelForCausalLM.from_pretrained("silk-road/Haruhi-Zero-1_8B", device_map="auto", trust_remote_code=True)
139
+ model = model.eval()
140
 
141
+ def get_response_qwen18(message):
142
+ from ChatHaruhi.utils import normalize2uaua
143
+ message_ua = normalize2uaua(message, if_replace_system = True)
144
+ import json
145
+ message_tuples = []
146
+ for i in range(0, len(message_ua)-1, 2):
147
+ message_tuple = (message_ua[i]["content"], message_ua[i+1]["content"])
148
+ message_tuples.append(message_tuple)
149
+ response, _ = model.chat(tokenizer, message_ua[-1]["content"], history=message_tuples)
150
+ return response
151
 
152
+ from ChatHaruhi.response_openai import get_response, async_get_response
153
+ import gradio as gr
154
+
155
+ def get_role_list( novel ):
156
+ new_list = novel2roles[novel]
157
+ new_value = new_list[0]
158
+ return gr.update(choices = new_list, value = new_value)
159
+
160
+ save_log = "/content/output.txt"
161
+
162
+ def get_chatbot( novel, role ):
163
+ if (novel, role) not in role_tuple2chatbot:
164
+ initialize_chatbot( novel, role )
165
+
166
+ return role_tuple2chatbot[(novel, role)]
167
+
168
+ import json
169
 
170
+ def random_chat_callback( novel, role, chat_history):
171
+ datas = role2datas[(novel, role)]
172
 
173
+ reesponse_set = set()
 
174
 
175
+ for chat_tuple in chat_history:
176
+ if chat_tuple[1] is not None:
177
+ reesponse_set.add(chat_tuple[1])
 
 
 
178
 
179
+ for _ in range(5):
180
+ random_data = random.choice(datas)
181
+ convs = random_data["conversations"]
182
+ n = len(convs)
183
+ index = [x for x in range(0,n,2)]
184
 
185
+ for i in index:
186
+ query = convs[i]['value']
187
+ response = convs[i+1]['value']
188
+ if response not in reesponse_set:
189
+ chat_history.append( (query, response) )
190
+ return chat_history
191
 
192
+ return chat_history
 
193
 
 
194
 
 
195
 
196
+ async def submit_chat( novel, role, user_name, user_text, chat_history, persona_addition_info,model_sel):
 
 
 
 
 
 
 
197
 
198
+ if len(user_text) > 400:
199
+ user_text = user_text[:400]
200
 
201
+ if_user_in_text = True
202
+
203
+ chatbot = get_chatbot( novel, role )
204
+ chatbot.persona = initialize_persona( novel, role, persona_addition_info)
205
+ # chatbot.llm_async = async_get_response
206
+
207
+ if model_sel == "openai":
208
+ chatbot.llm = get_response_openai
209
+ elif model_sel == "Zhipu":
210
+ chatbot.llm = get_response_zhipu
211
+ else:
212
+ chatbot.llm = get_response_qwen18
213
 
 
214
  history = []
215
 
216
+ for chat_tuple in chat_history:
217
+ if chat_tuple[0] is not None:
218
+ history.append( {"speaker":"{{user}}","content":chat_tuple[0]} )
219
+ if chat_tuple[1] is not None:
220
+ history.append( {"speaker":"{{role}}","content":chat_tuple[1]} )
221
+
222
+ chatbot.history = history
223
+
224
+ input_text = user_text
225
+
226
+ if if_user_in_text:
227
+ input_text = user_name + " : " + user_text
228
+ response = chatbot.chat(user = "", text = input_text )
229
+ # response = await chatbot.async_chat(user = "", text = input_text )
 
 
 
 
 
230
  else:
231
+ response = chatbot.chat(user = user_name, text = input_text)
232
+ # response = await chatbot.async_chat(user = user_name, text = input_text)
233
+ chat_history.append( (input_text, response) )
234
 
235
+ print_data = {"novel":novel, "role":role, "user_text":input_text, "response":response}
 
236
 
237
+ print(json.dumps(print_data, ensure_ascii=False))
238
 
239
+ with open(save_log, "a",encoding = "utf-8") as f:
240
+ f.write(json.dumps(print_data, ensure_ascii=False) + "\n")
241
 
242
+ return chat_history
 
 
 
243
 
 
 
 
 
244
 
245
+ def initialize_persona( novel, role, persona_addition_info):
246
+ whole_persona = package_persona( role, novel )
247
+ whole_persona += "\n" + persona_addition_info
248
+ whole_persona += "\n{{RAG对话}}\n{{RAG对话}}\n{{RAG对话}}\n"
249
 
250
+ return whole_persona
251
+
252
+ def clean_history( ):
253
+ return []
254
+
255
+ def clean_input():
256
+ return ""
257
+
258
+ import random
259
+
260
+ def generate_summarize_prompt( novel, role_name ):
261
+ whole_prompt = f'''
262
+ 你在分析小说{novel}中的角色{role_name}
263
+ 结合小说{novel}中的内容,以及下文中角色{role_name}的对话
264
+ 判断{role_name}的人物设定、人物特点以及语言风格
265
+
266
+ {role_name}的对话:
267
+ '''
268
+ stories = [data["story"] for data in role2datas[(novel, role_name)] ]
269
+
270
+ sample_n = 5
271
+
272
+ sample_stories = random.sample(stories, sample_n)
273
+
274
+ for story in sample_stories:
275
+ whole_prompt += story + "\n\n"
276
+
277
+ return whole_prompt.strip()
278
 
279
 
280
  with gr.Blocks() as demo:
281
+ gr.Markdown("""# 50本小说的人物测试
282
+
283
+ 这个interface由李鲁鲁实现,主要是用来看语料的
284
+
285
+ 增加了随机聊天,支持GLM,openai切换
286
+
287
+ 米唯实接入了qwen1.8B并布置于huggingface上""")
288
+
289
+ with gr.Tab("聊天"):
290
+ with gr.Row():
291
+ novel_sel = gr.Dropdown( novel_list, label = "小说", value = "悟空传" , interactive = True)
292
+ role_sel = gr.Dropdown( novel2roles[novel_sel.value], label = "角色", value = "孙悟空", interactive = True )
293
+
294
+ with gr.Row():
295
+ chat_history = gr.Chatbot(height = 600)
296
+
297
+ with gr.Row():
298
+ user_name = gr.Textbox(label="user_name", scale = 1, value = "鲁鲁", interactive = True)
299
+ user_text = gr.Textbox(label="user_text", scale = 20)
300
+ submit = gr.Button("submit", scale = 1)
301
+
302
+ with gr.Row():
303
+ random_chat = gr.Button("随机聊天", scale = 1)
304
+ clean_message = gr.Button("清空聊天", scale = 1)
305
+
306
+ with gr.Row():
307
+ persona_addition_info = gr.TextArea( label = "额外人物设定", value = "", interactive = True )
308
+
309
+ with gr.Row():
310
+ update_persona = gr.Button("补充人物设定到prompt", scale = 1)
311
+ model_sel = gr.Radio(["Zhipu","openai","qwen1.8B"], interactive = True, scale = 5, value = "qwen1.8B", label = "模型选择")
312
+
313
+ with gr.Row():
314
+ whole_persona = gr.TextArea( label = "完整的system prompt", value = "", interactive = False )
315
+
316
+ novel_sel.change(fn = get_role_list, inputs = [novel_sel], outputs = [role_sel]).then(fn = initialize_persona, inputs = [novel_sel, role_sel, persona_addition_info], outputs = [whole_persona])
317
+
318
+ role_sel.change(fn = initialize_persona, inputs = [novel_sel, role_sel, persona_addition_info], outputs = [whole_persona])
319
+
320
+ update_persona.click(fn = initialize_persona, inputs = [novel_sel, role_sel, persona_addition_info], outputs = [whole_persona])
321
+
322
+ random_chat.click(fn = random_chat_callback, inputs = [novel_sel, role_sel, chat_history], outputs = [chat_history])
323
+
324
+ user_text.submit(fn = submit_chat, inputs = [novel_sel, role_sel, user_name, user_text, chat_history, persona_addition_info,model_sel], outputs = [chat_history]).then(fn = clean_input, inputs = [], outputs = [user_text])
325
+ submit.click(fn = submit_chat, inputs = [novel_sel, role_sel, user_name, user_text, chat_history, persona_addition_info,model_sel], outputs = [chat_history]).then(fn = clean_input, inputs = [], outputs = [user_text])
326
+
327
+ clean_message.click(fn = clean_history, inputs = [], outputs = [chat_history])
328
+
329
+ with gr.Tab("README"):
330
+ gr.Markdown(readme_text)
331
+
332
+ with gr.Tab("辅助人物总结"):
333
+ with gr.Row():
334
+ generate_prompt = gr.Button("生成人物总结prompt", scale = 1)
335
+
336
+ with gr.Row():
337
+ whole_prompt = gr.TextArea( label = "复制这个prompt到Openai或者GLM或者Claude进行总结", value = "", interactive = False )
338
+
339
+ generate_prompt.click(fn = generate_summarize_prompt, inputs = [novel_sel, role_sel], outputs = [whole_prompt])
340
+
341
+
342
+
343
+
344
+
345
+ demo.launch(share=True, debug = True)
requirements.txt CHANGED
@@ -1,12 +1,19 @@
1
- gradio==3.41.1
2
- gradio_client==0.5.0
3
- Pillow==10.0.0
4
- chatharuhi
5
- wget==3.2
6
- openai==0.27.8
7
- chromadb==0.4.7
8
- langchain==0.0.271
9
- transformers==4.32.0
10
- torch==2.0
11
- tiktoken==0.4.0
12
- zhipuai
 
 
 
 
 
 
 
 
1
+ datasets
2
+ tiktoken
3
+ tqdm
4
+ openai
5
+ zhipuai
6
+ gradio
7
+ wget
8
+
9
+ scipy
10
+ transformers
11
+ accelerate
12
+ peft
13
+ bitsandbytes
14
+ sentencepiece
15
+ einops
16
+ transformers_stream_generator==0.0.4
17
+ deepspeed
18
+ auto-gptq
19
+ optimum