Xinonria commited on
Commit
0ce4f54
1 Parent(s): dd12bff

compress upload data

Browse files
Files changed (3) hide show
  1. api.py +5 -3
  2. i18n/emotion.json +0 -122
  3. i18n/translate.py +0 -63
api.py CHANGED
@@ -11,6 +11,7 @@ import os
11
  from dotenv import load_dotenv
12
  from pymongo import MongoClient
13
  from bson import Binary, ObjectId
 
14
 
15
  # 尝试直接获取环境变量
16
  BASE_URL = os.environ.get("BASE_URL")
@@ -106,9 +107,9 @@ def load_characters_csv(lang):
106
 
107
  async def generate_voice(avatar, name, emotion, tags, gender, audio_data, language):
108
  # 将图像数据转换为二进制
109
- avatar_binary = pickle.dumps(avatar)
110
  # 将音频数据转换为二进制
111
- audio_binary = pickle.dumps(audio_data)
112
 
113
  # 创建声音对象
114
  voice = {
@@ -120,7 +121,8 @@ async def generate_voice(avatar, name, emotion, tags, gender, audio_data, langua
120
  "audio_data": Binary(audio_binary),
121
  "language": language,
122
  "create_at": datetime.now().isoformat(),
123
- "is_public": False
 
124
  }
125
  result = create_collection.insert_one(voice)
126
  return result.inserted_id
 
11
  from dotenv import load_dotenv
12
  from pymongo import MongoClient
13
  from bson import Binary, ObjectId
14
+ import zlib
15
 
16
  # 尝试直接获取环境变量
17
  BASE_URL = os.environ.get("BASE_URL")
 
107
 
108
  async def generate_voice(avatar, name, emotion, tags, gender, audio_data, language):
109
  # 将图像数据转换为二进制
110
+ avatar_binary = zlib.compress(pickle.dumps(avatar))
111
  # 将音频数据转换为二进制
112
+ audio_binary = zlib.compress(pickle.dumps(audio_data))
113
 
114
  # 创建声音对象
115
  voice = {
 
121
  "audio_data": Binary(audio_binary),
122
  "language": language,
123
  "create_at": datetime.now().isoformat(),
124
+ "is_public": False,
125
+ "is_reviewed": False
126
  }
127
  result = create_collection.insert_one(voice)
128
  return result.inserted_id
i18n/emotion.json DELETED
@@ -1,122 +0,0 @@
1
- {
2
- "zh": {
3
- "正常": "正常",
4
- "生气": "生气",
5
- "悲伤": "悲伤",
6
- "惊讶": "惊讶",
7
- "害怕": "害怕",
8
- "厌恶": "厌恶",
9
- "开心": "开心",
10
- "失望": "失望",
11
- "紧张": "紧张",
12
- "不屑": "不屑",
13
- "不甘": "不甘",
14
- "愉悦": "愉悦",
15
- "戏谑": "戏谑",
16
- "疑惑": "疑惑",
17
- "尴尬": "尴尬",
18
- "伤心": "伤心",
19
- "困倦": "困倦",
20
- "无奈": "无奈",
21
- "警惕": "警惕",
22
- "坚决": "坚决",
23
- "委屈": "委屈",
24
- "害羞": "害羞",
25
- "傲娇": "傲娇",
26
- "女主": "女主",
27
- "平淡": "平淡",
28
- "疑问": "疑问",
29
- "男主": "男主",
30
- "警惕 ": "警惕 "
31
- },
32
- "en": {
33
- "正常": "normal",
34
- "生气": "angry",
35
- "悲伤": "sad",
36
- "惊讶": "surprise",
37
- "害怕": "fear",
38
- "厌恶": "disgust",
39
- "开心": "happy",
40
- "失望": "disappointment",
41
- "紧张": "nervous",
42
- "女主": "female",
43
- "平淡": "indifferent",
44
- "疑问": "question",
45
- "戏谑": "playful",
46
- "困倦": "sleepy",
47
- "男主": "male",
48
- "疑惑": "puzzled",
49
- "无奈": "helpless",
50
- "不甘": "unwilling",
51
- "傲娇": "tsundere",
52
- "警惕": "vigilant",
53
- "害羞": "shy",
54
- "警惕 ": "vigilant ",
55
- "尴尬": "embarrassed",
56
- "坚决": "determined",
57
- "不屑": "disdainful",
58
- "愉悦": "joyful",
59
- "委屈": "aggrieved",
60
- "伤心": "heartbroken"
61
- },
62
- "ja": {
63
- "正常": "正常",
64
- "生气": "怒り",
65
- "悲伤": "悲しい",
66
- "惊讶": "驚き",
67
- "害怕": "恐れ",
68
- "厌恶": "嫌悪",
69
- "开心": "嬉しい",
70
- "失望": "失望",
71
- "紧张": "緊張",
72
- "女主": "ヒロイン",
73
- "平淡": "平淡",
74
- "疑问": "疑問",
75
- "戏谑": "からかい",
76
- "困倦": "眠い",
77
- "男主": "主人公",
78
- "疑惑": "困惑",
79
- "无奈": "仕方ない",
80
- "不甘": "悔しい",
81
- "傲娇": "ツンデレ",
82
- "警惕": "警戒",
83
- "害羞": "恥ずかしい",
84
- "警惕 ": "警戒 ",
85
- "尴尬": "気まずい",
86
- "坚决": "断固とした",
87
- "不屑": "軽蔑",
88
- "愉悦": "喜び",
89
- "委屈": "悔しい",
90
- "伤心": "悲しい"
91
- },
92
- "ko": {
93
- "正常": "보통",
94
- "生气": "화남",
95
- "悲伤": "슬픔",
96
- "惊讶": "놀람",
97
- "害怕": "두려움",
98
- "厌恶": "혐오",
99
- "开心": "행복",
100
- "失望": "실망",
101
- "紧张": "긴장",
102
- "女主": "여주인공",
103
- "平淡": "평범함",
104
- "疑问": "의문",
105
- "戏谑": "농담",
106
- "困倦": "피곤함",
107
- "男主": "남주인공",
108
- "疑惑": "의혹",
109
- "无奈": "어쩔 수 없음",
110
- "不甘": "불만",
111
- "傲娇": "츤데레",
112
- "警惕": "경계",
113
- "害羞": "부끄러움",
114
- "警惕 ": "경계 ",
115
- "尴尬": "당황",
116
- "坚决": "단호함",
117
- "不屑": "경멸",
118
- "愉悦": "즐거움",
119
- "委屈": "억울함",
120
- "伤心": "상심"
121
- }
122
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
i18n/translate.py DELETED
@@ -1,63 +0,0 @@
1
- import json
2
- import pandas as pd
3
- from typing import Literal
4
- import os
5
- import shutil
6
-
7
- os.chdir(os.path.dirname(os.path.abspath(__file__)))
8
-
9
- class LanguageConvertor:
10
- def __init__(self, lang: Literal["en", "ja", "ko"]):
11
- self.lang = lang
12
- self.emotion = json.load(open("emotion.json", "r", encoding="utf-8"))[lang]
13
- self.data = pd.read_csv(f"characters_{self.lang}.csv")
14
-
15
- def get_name(self):
16
- names = self.data["名称"].tolist()
17
- return [name for i, name in enumerate(names) if name not in names[:i]]
18
-
19
- def replace_emotion(self):
20
- emotion = self.emotion
21
- for i, row in self.data.iterrows():
22
- try:
23
- self.data.loc[i, "情绪"] = emotion[row["情绪"]]
24
- except KeyError:
25
- pass
26
-
27
- def generate_name_template(self, names: set[str]):
28
- res = "{\n"
29
- for i, name in enumerate(names):
30
- if i == len(names) - 1:
31
- res += f" \"{name}\": \"{name}\"\n"
32
- else:
33
- res += f" \"{name}\": \"{name}\",\n"
34
- with open(os.path.join("temp", f"translate_name_{self.lang}.json"), "w", encoding="utf-8") as f:
35
- f.write(res + "}")
36
-
37
- def replace_name(self):
38
- with open(os.path.join("temp", f"translate_name_{self.lang}.json"), "r", encoding="utf-8") as f:
39
- translate_name = json.load(f)
40
- for i, row in self.data.iterrows():
41
- self.data.loc[i, "名称"] = translate_name[row["名称"]]
42
-
43
- def to_file(self):
44
- self.data.to_csv(f"characters_{self.lang}.csv", index=False)
45
-
46
- if __name__ == "__main__":
47
- # step = 1为生成翻译模板
48
- # step = 2为生成翻译后的角色文件
49
- # 请确保第一步已完成再进行第二步
50
-
51
- step = 2
52
- convertors = [LanguageConvertor(lang) for lang in ["en", "ja", "ko"]]
53
- os.makedirs("temp", exist_ok=True)
54
- for convertor in convertors:
55
- convertor.replace_emotion()
56
- print(convertor.data)
57
- if step == 1:
58
- convertor.generate_name_template(convertor.get_name())
59
- if step == 2:
60
- for convertor in convertors:
61
- convertor.replace_name()
62
- convertor.to_file()
63
- # shutil.rmtree("temp")