silk-road commited on
Commit
7ea0c61
1 Parent(s): df0f64f

Upload 35 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ images/guofurong[[:space:]].jpg filter=lfs diff=lfs merge=lfs -text
37
+ images/hutao.jpg filter=lfs diff=lfs merge=lfs -text
38
+ images/jiumozhi.jpg filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
10
+
11
+ NAME_DICT = {'汤师爷': 'tangshiye', '慕容复': 'murongfu', '李云龙': 'liyunlong', 'Luna': 'Luna', '王多鱼': 'wangduoyu',
12
+ 'Ron': 'Ron', '鸠摩智': 'jiumozhi', 'Snape': 'Snape',
13
+ '凉宫春日': 'haruhi', 'Malfoy': 'Malfoy', '虚竹': 'xuzhu', '萧峰': 'xiaofeng', '段誉': 'duanyu',
14
+ 'Hermione': 'Hermione', 'Dumbledore': 'Dumbledore', '王语嫣': 'wangyuyan',
15
+ 'Harry': 'Harry', 'McGonagall': 'McGonagall', '白展堂': 'baizhantang', '佟湘玉': 'tongxiangyu',
16
+ '郭芙蓉': 'guofurong', '旅行者': 'wanderer', '钟离': 'zhongli',
17
+ '胡桃': 'hutao', 'Sheldon': 'Sheldon', 'Raj': 'Raj', 'Penny': 'Penny', '韦小宝': 'weixiaobao',
18
+ '乔峰': 'qiaofeng', '神里绫华': 'ayaka', '雷电将军': 'raidenShogun', '于谦': 'yuqian'}
19
+
20
+
21
+
22
+ try:
23
+ os.makedirs("characters_zip")
24
+ except:
25
+ pass
26
+ try:
27
+ os.makedirs("characters")
28
+ except:
29
+ pass
30
+ ai_roles_obj = {}
31
+ for ai_role_en in NAME_DICT.values():
32
+ file_url = f"https://github.com/LC1332/Haruhi-2-Dev/raw/main/data/character_in_zip/{ai_role_en}.zip"
33
+ try:
34
+ os.makedirs(f"characters/{ai_role_en}")
35
+ except:
36
+ pass
37
+ if f"{ai_role_en}.zip" not in os.listdir(f"characters_zip"):
38
+ destination_file = f"characters_zip/{ai_role_en}.zip"
39
+ wget.download(file_url, destination_file)
40
+ destination_folder = f"characters/{ai_role_en}"
41
+ with zipfile.ZipFile(destination_file, 'r') as zip_ref:
42
+ zip_ref.extractall(destination_folder)
43
+ db_folder = f"./characters/{ai_role_en}/content/{ai_role_en}"
44
+ system_prompt = f"./characters/{ai_role_en}/content/system_prompt.txt"
45
+ ai_roles_obj[ai_role_en] = ChatHaruhi(system_prompt=system_prompt,
46
+ llm="ernie",
47
+ story_db=db_folder,
48
+ verbose=True)
49
+
50
+
51
+ async def get_response(user_role, user_text, ai_role, chatbot):
52
+ role_en = NAME_DICT[ai_role]
53
+ ai_roles_obj[role_en].dialogue_history = copy.deepcopy(chatbot)
54
+ response = ai_roles_obj[role_en].chat(role=user_role, text=user_text)
55
+ user_msg = user_role + ':「' + user_text + '」'
56
+ latest_msg = (user_msg, response)
57
+ print(latest_msg)
58
+ chatbot.append(latest_msg)
59
+ return chatbot
60
+
61
+ async def respond(user_role, user_text, ai_role, chatbot):
62
+ return await get_response(user_role, user_text, ai_role, chatbot), None
63
+
64
+
65
+ def clear(user_role, user_text, chatbot):
66
+ return None, None, []
67
+
68
+
69
+ def get_image(ai_role):
70
+ role_en = NAME_DICT[ai_role]
71
+ return Image.open(f'images/{role_en}.jpg'), None, None, []
72
+
73
+
74
+ with gr.Blocks() as demo:
75
+ gr.Markdown(
76
+ """
77
+ # Chat凉宫春日 ChatHaruhi
78
+ ## Reviving Anime Character in Reality via Large Language Model
79
+ ChatHaruhi2.0的BaichuanAPI 版本demo implemented by [Weishi MI](https://github.com/hhhwmws0117) and [chenxi](https://github.com/todochenxi)
80
+ 更多信息见项目github链接 [https://github.com/LC1332/Chat-Haruhi-Suzumiya](https://github.com/LC1332/Chat-Haruhi-Suzumiya)
81
+ 如果觉得有趣请拜托为我们点上star. If you find it interesting, please be kind enough to give us a star.
82
+ user_role 为用户扮演的人物 请尽量设置为与剧情相关的人物 且不要与主角同名
83
+ """
84
+ )
85
+ with gr.Row():
86
+ chatbot = gr.Chatbot()
87
+ role_image = gr.Image(height=400, value="./images/haruhi.jpg")
88
+ with gr.Row():
89
+ user_role = gr.Textbox(label="user_role")
90
+ user_text = gr.Textbox(label="user_text")
91
+ with gr.Row():
92
+ submit = gr.Button("Submit")
93
+ clean = gr.ClearButton(value="Clear")
94
+ ai_role = gr.Radio(['汤师爷', '慕容复', '李云龙',
95
+ 'Luna', '王多鱼', 'Ron', '鸠摩智',
96
+ 'Snape', '凉宫春日', 'Malfoy', '虚竹',
97
+ '萧峰', '段誉', 'Hermione', 'Dumbledore',
98
+ '王语嫣',
99
+ 'Harry', 'McGonagall',
100
+ '白展堂', '佟湘玉', '郭芙蓉',
101
+ '旅行者', '钟离', '胡桃',
102
+ 'Sheldon', 'Raj', 'Penny',
103
+ '韦小宝', '乔峰', '神里绫华',
104
+ '雷电将军', '于谦'], label="characters", value='凉宫春日')
105
+ ai_role.change(get_image, ai_role, [role_image, user_role, user_text, chatbot])
106
+ user_text.submit(fn=respond, inputs=[user_role, user_text, ai_role, chatbot], outputs=[chatbot, user_text])
107
+ submit.click(fn=respond, inputs=[user_role, user_text, ai_role, chatbot], outputs=[chatbot, user_text])
108
+ clean.click(clear, [user_role, user_text, chatbot], [user_role, user_text, chatbot])
109
+ demo.launch(debug=True)
images/Dumbledore.jpg ADDED
images/Harry.jpg ADDED
images/Hermione.jpg ADDED
images/Luna.jpg ADDED
images/Malfoy.jpg ADDED
images/McGonagall.jpg ADDED
images/Penny.jpg ADDED
images/Raj.jpg ADDED
images/Ron.jpg ADDED
images/Sheldon.jpg ADDED
images/Snape.jpg ADDED
images/ayaka.jpg ADDED
images/baizhantang.jpg ADDED
images/duanyu.jpg ADDED
images/guofurong .jpg ADDED

Git LFS Details

  • SHA256: 1ff65fed5dc4cf82c88317cc918fed7e924301f8171454bde7c3b83f47da77f9
  • Pointer size: 132 Bytes
  • Size of remote file: 1.15 MB
images/haruhi.jpg ADDED
images/hutao.jpg ADDED

Git LFS Details

  • SHA256: 583e5dea955c84a019a0755e35a61ee02a803c5b36cfb75889ab506a7b63a8d1
  • Pointer size: 132 Bytes
  • Size of remote file: 1.44 MB
images/jiumozhi.jpg ADDED

Git LFS Details

  • SHA256: 13aabaa056684239654dcd9e8aa07435c00474153d3db6b4aacb33334d6a132d
  • Pointer size: 132 Bytes
  • Size of remote file: 1.27 MB
images/liyunlong.jpg ADDED
images/murongfu.jpg ADDED
images/qiaofeng.jpg ADDED
images/raidenShogun.jpg ADDED
images/tangshiye.jpg ADDED
images/tongxinagyu.jpg ADDED
images/wanderer.jpg ADDED
images/wangduoyu.jpg ADDED
images/wangyuyan.jpg ADDED
images/weixiaobao.jpg ADDED
images/xiaofeng.jpg ADDED
images/xuzhu.jpg ADDED
images/yaemiko.jpg ADDED
images/yuqian.jpg ADDED
images/zhongli.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ erniebot