-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathconfig.py
More file actions
87 lines (70 loc) · 2.46 KB
/
config.py
File metadata and controls
87 lines (70 loc) · 2.46 KB
1
2
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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
import os
import torch
# 设置Gradio临时目录
os.environ['GRADIO_TEMP_DIR'] = '/data/tmp/gradio'
def get_available_gpus():
"""获取所有可用的GPU设备"""
if torch.cuda.is_available():
return list(range(torch.cuda.device_count()))
return []
def get_device_config():
"""设置设备配置"""
gpus = get_available_gpus()
# 检查环境变量是否指定了GPU
cuda_visible = os.getenv('CUDA_VISIBLE_DEVICES', '')
if cuda_visible:
try:
# 解析环境变量中的GPU索引
selected_gpus = [int(x.strip()) for x in cuda_visible.split(',') if
x.strip()]
return 'cuda', selected_gpus
except ValueError:
pass
# 如果没有指定但检测到GPU
if gpus:
return 'cuda', gpus
# 默认使用CPU
return 'cpu', []
# 文件上传配置
ALLOWED_EXTENSIONS = ['mp4', 'avi', 'mov', 'mkv', 'ts', 'mxf', 'mp3', 'wav',
'flac']
MAX_FILE_SIZE = 10 * 1024 * 1024 * 1024 # 10GB
MAX_FILE_NUMBERS = 10 # 最大文件数量
# 临时文件夹
TEMP_FOLDER = "temp"
# 输出文件夹
OUTPUT_FOLDER = "output"
# 语音识别模型配置
SPEECH_RECOGNIZER_TYPE = 'faster-whisper' # whisperx, faster-whisper
DEVICE_TYPE, AVAILABLE_GPUS = get_device_config()
# Whisper配置
WHISPER_MODEL_SIZE = 'large-v2' # 模型大小 (tiny, base, small, medium, large, large-v2, large-v3)
WHISPER_DEVICE = DEVICE_TYPE
WHISPER_GPU_IDS = AVAILABLE_GPUS
WHISPER_COMPUTE_TYPE = 'float16' if WHISPER_DEVICE == 'cuda' else 'float32' # float16, float32, int8
WHISPER_BATCH_SIZE = 16 # 批处理大小
FASTER_WHISPER_BEAM_SIZE = 5
# 语音文字对齐模型
ENABLE_ALIGNMENT = True # 是否启用对齐
ALIGNMENT_DEVICE = DEVICE_TYPE # 对齐模型使用的设备
ALIGNMENT_MODEL = 'ctc-forced-aligner' # 使用的对齐模型, whisperx, ctc-forced-aligner
# OpenAI API配置
LLM_MODEL_OPTIONS = [
{
"model": "deepseek-v3-0324",
"base_url": "https://api.lkeap.cloud.tencent.com/v1",
"api_key_env_name": "DEEPSEEK_V3_API_KEY",
"label": "DeepSeek-V3-0324",
"max_tokens": 4096
},
{
"model": "doubao-1-5-pro-32k-250115",
"base_url": "https://ark.cn-beijing.volces.com/api/v3",
"api_key_env_name": "DOUBAO_1_5_PRO_API_KEY",
"label": "豆包",
"max_tokens": 4096
}
]
# 创建必要的目录
for folder in [TEMP_FOLDER, OUTPUT_FOLDER]:
os.makedirs(folder, exist_ok=True)