Skip to content

Commit 8114713

Browse files
authored
refactor: adjust settings (#258)
1 parent 1cb1801 commit 8114713

File tree

5 files changed

+100
-69
lines changed

5 files changed

+100
-69
lines changed

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ zhconv==1.4.3
1313
bilitool==0.1.2
1414
google-generativeai>=0.7.2 # don't change this part
1515
zhipuai
16-
openai
16+
openai
17+
toml

settings.toml

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,57 @@
11
version = "1.0"
22
webhooks = []
33

4+
# bilive Settings
5+
[model]
6+
model_type = "append" # Can be pipeline, append, merge
7+
8+
# WARNING!: If you choose "deploy" local inference:
9+
# 1. Please check the VRAM requirements twice!
10+
# 2. Please make sure you have installed the Nvidia GPU driver and can check the cuda via `nvcc -V`!
11+
# WARNING!: If you choose "api":
12+
# due to the limitation of free tier, you should keep every video less than 30 minutes(around)
13+
# which means your MODEL_TYPE should not be "merge".
14+
[asr]
15+
asr_method = "none" # can be "deploy" or "api" or "none"
16+
whisper_api_key = "" # Apply for your own API key at https://console.groq.com/keys
17+
inference_model = "small" # If you choose "deploy", you should download the inference model from https://openaipublic.azureedge.net/main/whisper/models/9ecf779972d90ba49c06d968637d720dd632c55bbf19d441fb42bf17a411e794/small.pt
18+
19+
[video]
20+
# You can change the title as you like, eg.
21+
# f"{artist}直播回放-{date}-{title}" - Streamer直播回放-20250328-Live title
22+
# f"{date}-{artist}直播回放" - 20250328-Streamer直播回放
23+
title = "{artist}直播回放-{date}-{title}" # Key words: {artist}, {date}, {title}, {source_link}
24+
description = "{artist}直播回放,直播间地址:{source_link} 内容仅供娱乐,直播中主播的言论、观点和行为均由主播本人负责,不代表录播员的观点或立场。" # Key words: {artist}, {date}, {title}, {source_link}
25+
gift_price_filter = 1 # The gift whose price is less than this value will be filtered, unit: RMB
26+
reserve_for_fixing = false # If encounter MOOV crash error, delete the video or reserve for fixing
27+
upload_line = "auto" # The upload line to be used, default None is auto detect(recommended), if you want to specify, it can be "bldsa", "ws", "tx", "qn", "bda2".
28+
29+
[slice]
30+
auto_slice = false # General control
31+
slice_duration = 60 # better not exceed 300 seconds
32+
slice_num = 2
33+
slice_overlap = 30
34+
slice_step = 1
35+
min_video_size = 200 # The minimum video size to be sliced (MB)
36+
mllm_model = "gemini" # the multi-model LLMs, can be "gemini" or "zhipu" or "qwen"
37+
zhipu_api_key = "" # Apply for your own GLM-4v-Plus API key at https://www.bigmodel.cn/invite?icode=shBtZUfNE6FfdMH1R6NybGczbXFgPRGIalpycrEwJ28%3D
38+
gemini_api_key = "" # Apply for your own Gemini API key at https://aistudio.google.com/app/apikey
39+
qwen_api_key = "" # Apply for your own Qwen API key at https://bailian.console.aliyun.com/?apiKey=1
40+
41+
# blrec Settings
442
[[tasks]]
543
room_id = 173551
644
enable_monitor = true
745
enable_recorder = true
846

947
[output]
10-
path_template = "{roomid}/{roomid}_{year}{month}{day}-{hour}-{minute}-{second}"
48+
path_template = "{roomid}/{roomid}_{year}{month}{day}-{hour}-{minute}-{second}" # Don't change this
1149
filesize_limit = 0
1250
duration_limit = 1800
13-
out_dir = "./Videos"
51+
out_dir = "./Videos" # Don't change this
1452

1553
[logging]
16-
log_dir = "./logs/blrec"
54+
log_dir = "./logs/blrec" # Don't change this
1755
console_log_level = "INFO"
1856
backup_count = 30
1957

src/autoslice/mllm_sdk/gemini_new_sdk.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ def gemini_generate_title(video_path, artist):
1414
model='models/gemini-2.0-flash',
1515
contents=types.Content(
1616
parts=[
17-
types.Part(text=f'视频是{artist}的直播的切片,请根据该视频中的内容及弹幕信息,为这段视频起一个调皮并且吸引眼球的标题,只需要返回一个标题即可,无需返回其他内容'),
17+
types.Part(text=f'视频是{artist}的直播的切片,请根据该视频中的内容及弹幕信息,为这段视频起一个调皮并且吸引眼球的标题,只需要返回一个标题即可,无需返回其他内容,标题中不要有表情符号。'),
1818
types.Part(
1919
inline_data=types.Blob(data=video_bytes, mime_type='video/mp4')
2020
)
2121
]
2222
)
2323
)
2424
scan_log.info("使用 Gemini-2.0-flash 生成切片标题")
25-
scan_log.info(f"Prompt: 视频是{artist}的直播的切片,请根据该视频中的内容及弹幕信息,为这段视频起一个调皮并且吸引眼球的标题,只需要返回一个标题即可,无需返回其他内容")
25+
scan_log.info(f"Prompt: 视频是{artist}的直播的切片,请根据该视频中的内容及弹幕信息,为这段视频起一个调皮并且吸引眼球的标题,只需要返回一个标题即可,无需返回其他内容,标题中不要有表情符号。")
2626
scan_log.info(f"生成的切片标题为: {response.text}")
2727
return response.text

src/autoslice/mllm_sdk/gemini_old_sdk.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def gemini_generate_title(video_path, artist):
2222
raise ValueError(video_file.state.name)
2323

2424
# Create the prompt.
25-
prompt = f"视频是{artist}的直播的切片,请根据该视频中的内容及弹幕信息,为这段视频起一个调皮并且吸引眼球的标题,只返回该标题即可,无需返回其他内容"
25+
prompt = f"视频是{artist}的直播的切片,请根据该视频中的内容及弹幕信息,为这段视频起一个调皮并且吸引眼球的标题,只返回该标题即可,无需返回其他内容,标题中不要有表情符号。"
2626

2727
# Set the model to Gemini Flash.
2828
model = genai.GenerativeModel(model_name="models/gemini-2.0-flash")
@@ -32,6 +32,6 @@ def gemini_generate_title(video_path, artist):
3232
# delete the video file
3333
genai.delete_file(video_file.name)
3434
scan_log.info("使用 Gemini-2.0-flash 生成切片标题")
35-
scan_log.info(f"Prompt: 视频是{artist}的直播的切片,请根据该视频中的内容及弹幕信息,为这段视频起一个调皮并且吸引眼球的标题,只需要返回一个标题即可,无需返回其他内容")
35+
scan_log.info(f"Prompt: 视频是{artist}的直播的切片,请根据该视频中的内容及弹幕信息,为这段视频起一个调皮并且吸引眼球的标题,只需要返回一个标题即可,无需返回其他内容,标题中不要有表情符号。")
3636
scan_log.info(f"生成的切片标题为: {response.text}")
3737
return response.text

src/config.py

Lines changed: 53 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,78 +5,70 @@
55
from datetime import datetime
66
import configparser
77
import torch
8+
import toml
9+
import src.log.logger as scan_log
810
from db.conn import create_table
911

10-
# ============================ Your configuration ============================
11-
# Can be pipeline, append, merge
12-
MODEL_TYPE = "append"
12+
def load_config_from_toml(file_path):
13+
"""
14+
load config from toml file and update global variables
15+
"""
16+
try:
17+
with open(file_path, 'r', encoding='utf-8') as file:
18+
config = toml.load(file)
19+
return config
20+
except FileNotFoundError:
21+
scan_log.error(f"cannot find {file_path}")
22+
except toml.TomlDecodeError as e:
23+
scan_log.error(f"cannot parse {file_path} as a valid toml file, error: {e}")
24+
except Exception as e:
25+
scan_log.error(f"unknown error when loading config file, error: {e}")
26+
return None
1327

14-
# =============== The auto speech recognition configuration ============================
15-
# WARNING!: If you choose "deploy" local inference:
16-
# 1. Please check the VRAM requirements twice!
17-
# 2. Please make sure you have installed the Nvidia GPU driver and can check the cuda via `nvcc -V`!
18-
# WARNING!: If you choose "api":
19-
# due to the limitation of free tier, you should keep every video less than 30 minutes(around)
20-
# which means your MODEL_TYPE should not be "merge".
21-
ASR_METHOD = "none" # can be "deploy" or "api" or "none"
22-
# Apply for your own API key at https://console.groq.com/keys
23-
WHISPER_API_KEY = ""
24-
# If you choose "deploy", you should download the model from https://huggingface.co/openai/whisper-large-v3-turbo
25-
Inference_Model = "small" # the model to be deployed
28+
def get_model_path():
29+
SRC_DIR = str(Path(os.path.abspath(__file__)).parent)
30+
model_dir = os.path.join(SRC_DIR, 'subtitle', 'models')
31+
model_path = os.path.join(model_dir, f'{INFERENCE_MODEL}.pt')
32+
return model_path
2633

27-
# =============== The video configuration ============================
28-
TITLE = "{artist}直播回放-{date}-{title}"
29-
# You can change the title as you like, eg.
30-
# f"{artist}直播回放-{date}-{title}" - Streamer直播回放-20250328-Live title
31-
# f"{date}-{artist}直播回放" - 20250328-Streamer直播回放
32-
DESC = "{artist}直播回放,直播间地址:{source_link} 内容仅供娱乐,直播中主播的言论、观点和行为均由主播本人负责,不代表录播员的观点或立场。"
33-
# You can change the description as you like.
34-
GIFT_PRICE_FILTER = 1 # The gift whose price is less than this value will be filtered, unit: RMB
35-
RESERVE_FOR_FIXING = False # If encounter MOOV crash error, delete the video or reserve for fixing
36-
UPLOAD_LINE = None # The upload line to be used, default None is auto detect(recommended), if you want to specify, it can be "bldsa", "ws", "tx", "qn", "bda2".
34+
def get_interface_config():
35+
interface_config = configparser.ConfigParser()
36+
interface_dir = os.path.join(SRC_DIR, 'subtitle')
37+
interface_file = os.path.join(interface_dir, "en.ini")
38+
interface_config.read(interface_file, encoding='utf-8')
39+
return interface_config
3740

38-
# ============================ The video slice configuration ==================
39-
AUTO_SLICE = False
40-
SLICE_DURATION = 60 # better not exceed 300 seconds
41-
SLICE_NUM = 2
42-
SLICE_OVERLAP = 30
43-
SLICE_STEP = 1
44-
# The minimum video size to be sliced (MB)
45-
MIN_VIDEO_SIZE = 200
46-
# the multi-model LLMs, can be "gemini" or "zhipu" or "qwen"
47-
MLLM_MODEL = "gemini" # Please make sure you have the right API key for the LLM you choose
48-
# Apply for your own GLM-4v-Plus API key at https://www.bigmodel.cn/invite?icode=shBtZUfNE6FfdMH1R6NybGczbXFgPRGIalpycrEwJ28%3D
49-
ZHIPU_API_KEY = ""
50-
# Apply for your own Gemini API key at https://aistudio.google.com/app/apikey
51-
GEMINI_API_KEY = ""
52-
# Apply for your own Qwen API key at https://bailian.console.aliyun.com/?apiKey=1
53-
QWEN_API_KEY = ""
54-
# ============================ Basic configuration ============================
55-
GPU_EXIST = torch.cuda.is_available()
5641
SRC_DIR = str(Path(os.path.abspath(__file__)).parent)
5742
BILIVE_DIR = str(Path(SRC_DIR).parent)
5843
LOG_DIR = os.path.join(BILIVE_DIR, 'logs')
5944
VIDEOS_DIR = os.path.join(BILIVE_DIR, 'Videos')
60-
61-
6245
if not os.path.exists(SRC_DIR + '/db/data.db'):
63-
print("Initialize the database")
46+
scan_log.info("Initialize the database")
6447
create_table()
6548

66-
if not os.path.exists(VIDEOS_DIR):
67-
os.makedirs(VIDEOS_DIR)
68-
if not os.path.exists(VIDEOS_DIR + '/upload_conf'):
69-
os.makedirs(VIDEOS_DIR + '/upload_conf')
49+
config = load_config_from_toml(os.path.join(BILIVE_DIR, 'settings.toml'))
50+
if config is None:
51+
scan_log.error("failed to load config file, please check twice")
52+
exit(1)
7053

71-
def get_model_path():
72-
SRC_DIR = str(Path(os.path.abspath(__file__)).parent)
73-
model_dir = os.path.join(SRC_DIR, 'subtitle', 'models')
74-
model_path = os.path.join(model_dir, f'{Inference_Model}.pt')
75-
return model_path
54+
GPU_EXIST = torch.cuda.is_available()
55+
MODEL_TYPE = config.get('model', {}).get('model_type')
56+
ASR_METHOD = config.get('asr', {}).get('asr_method')
57+
WHISPER_API_KEY = config.get('asr', {}).get('whisper_api_key')
58+
INFERENCE_MODEL = config.get('asr', {}).get('inference_model')
7659

77-
def get_interface_config():
78-
interface_config = configparser.ConfigParser()
79-
interface_dir = os.path.join(SRC_DIR, 'subtitle')
80-
interface_file = os.path.join(interface_dir, "en.ini")
81-
interface_config.read(interface_file, encoding='utf-8')
82-
return interface_config
60+
TITLE = config.get('video', {}).get('title')
61+
DESC = config.get('video', {}).get('description')
62+
GIFT_PRICE_FILTER = config.get('video', {}).get('gift_price_filter')
63+
RESERVE_FOR_FIXING = config.get('video', {}).get('reserve_for_fixing')
64+
UPLOAD_LINE = config.get('video', {}).get('upload_line')
65+
AUTO_SLICE = config.get('slice', {}).get('auto_slice')
66+
SLICE_DURATION = config.get('slice', {}).get('slice_duration')
67+
SLICE_NUM = config.get('slice', {}).get('slice_num')
68+
SLICE_OVERLAP = config.get('slice', {}).get('slice_overlap')
69+
SLICE_STEP = config.get('slice', {}).get('slice_step')
70+
MIN_VIDEO_SIZE = config.get('slice', {}).get('min_video_size')
71+
MLLM_MODEL = config.get('slice', {}).get('mllm_model')
72+
ZHIPU_API_KEY = config.get('slice', {}).get('zhipu_api_key')
73+
GEMINI_API_KEY = config.get('slice', {}).get('gemini_api_key')
74+
QWEN_API_KEY = config.get('slice', {}).get('qwen_api_key')

0 commit comments

Comments
 (0)