Skip to content

Commit 3895431

Browse files
authored
style: formatting (#278)
1 parent 5565a7f commit 3895431

38 files changed

Lines changed: 728 additions & 389 deletions

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pysrt==1.1.2
88
six==1.16.0
99
tiktoken==0.4.0
1010
torch==1.11.0
11-
triton==3.1.0
11+
# triton==3.1.0
1212
zhconv==1.4.3
1313
Pillow>=5.2.0
1414
PyYAML>=6.0.2

src/autoslice/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import sys
44
import os
5+
56
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
67
from .auto_slice_video.autosv import slice_video_by_danmaku
78

8-
__all__ = ["slice_video_by_danmaku"]
9+
__all__ = ["slice_video_by_danmaku"]

src/autoslice/inject_metadata.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,26 @@
33
import subprocess
44
from src.log.logger import scan_log
55

6+
67
# https://stackoverflow.com/questions/64849478/cant-insert-stream-metadata-into-mp4
78
def inject_metadata(video_path, generate_title, output_path):
89
"""Slice the video using ffmpeg."""
910
command = [
10-
'ffmpeg',
11-
'-i', video_path,
12-
'-metadata:g', f'generate={generate_title}',
13-
'-c:v', 'copy',
14-
'-c:a', 'copy',
15-
output_path
11+
"ffmpeg",
12+
"-i",
13+
video_path,
14+
"-metadata:g",
15+
f"generate={generate_title}",
16+
"-c:v",
17+
"copy",
18+
"-c:a",
19+
"copy",
20+
output_path,
1621
]
1722
try:
1823
result = subprocess.run(command, check=True, capture_output=True, text=True)
1924
scan_log.debug(f"FFmpeg output: {result.stdout}")
2025
if result.stderr:
2126
scan_log.debug(f"FFmpeg debug: {result.stderr}")
2227
except subprocess.CalledProcessError as e:
23-
scan_log.error(f"Error: {e.stderr}")
28+
scan_log.error(f"Error: {e.stderr}")
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
from google import genai
2-
from google.genai import types
2+
from google.genai import types
33
from src.log.logger import scan_log
44
from src.config import GEMINI_API_KEY, SLICE_PROMPT
55

6+
67
def gemini_generate_title(video_path, artist):
78

89
client = genai.Client(api_key=GEMINI_API_KEY)
910

1011
# Only for videos of size <20Mb
11-
video_bytes = open(video_path, 'rb').read()
12+
video_bytes = open(video_path, "rb").read()
1213

1314
response = client.models.generate_content(
14-
model='models/gemini-2.0-flash',
15+
model="models/gemini-2.0-flash",
1516
contents=types.Content(
1617
parts=[
1718
types.Part(text=SLICE_PROMPT),
1819
types.Part(
19-
inline_data=types.Blob(data=video_bytes, mime_type='video/mp4')
20-
)
20+
inline_data=types.Blob(data=video_bytes, mime_type="video/mp4")
21+
),
2122
]
22-
)
23+
),
2324
)
2425
scan_log.info("使用 Gemini-2.0-flash 生成切片标题")
2526
scan_log.info(f"Prompt: {SLICE_PROMPT}")
2627
scan_log.info(f"生成的切片标题为: {response.text}")
27-
return response.text
28+
return response.text

src/autoslice/mllm_sdk/gemini_old_sdk.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# the new gemini sdk has the conflicts pydantic version in project, so we use the old one
77
# https://github.com/google-gemini/deprecated-generative-ai-python
88

9+
910
def gemini_generate_title(video_path, artist):
1011

1112
genai.configure(api_key=GEMINI_API_KEY)
@@ -27,11 +28,12 @@ def gemini_generate_title(video_path, artist):
2728
# Set the model to Gemini Flash.
2829
model = genai.GenerativeModel(model_name="models/gemini-2.0-flash")
2930

30-
response = model.generate_content([prompt, video_file],
31-
request_options={"timeout": 600})
31+
response = model.generate_content(
32+
[prompt, video_file], request_options={"timeout": 600}
33+
)
3234
# delete the video file
3335
genai.delete_file(video_file.name)
3436
scan_log.info("使用 Gemini-2.0-flash 生成切片标题")
3537
scan_log.info(f"Prompt: {SLICE_PROMPT}")
3638
scan_log.info(f"生成的切片标题为: {response.text}")
37-
return response.text
39+
return response.text

src/autoslice/mllm_sdk/qwen_sdk.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
import os
55
import base64
66

7+
78
def encode_video(video_path):
89
with open(video_path, "rb") as video_file:
910
return base64.b64encode(video_file.read()).decode("utf-8")
1011

12+
1113
def qwen_generate_title(video_path, artist):
1214
client = OpenAI(
1315
api_key=QWEN_API_KEY,
@@ -20,7 +22,8 @@ def qwen_generate_title(video_path, artist):
2022
messages=[
2123
{
2224
"role": "system",
23-
"content": [{"type":"text","text": "你是一个视频切片员"}]},
25+
"content": [{"type": "text", "text": "你是一个视频切片员"}],
26+
},
2427
{
2528
"role": "user",
2629
"content": [
@@ -30,7 +33,7 @@ def qwen_generate_title(video_path, artist):
3033
},
3134
{"type": "text", "text": SLICE_PROMPT},
3235
],
33-
}
36+
},
3437
],
3538
)
3639
scan_log.info("使用 Qwen-2.5-72B-Instruct 生成切片标题")

src/autoslice/mllm_sdk/zhipu_sdk.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,25 @@
55
from zhipuai import ZhipuAI
66
from src.log.logger import scan_log
77

8+
89
def zhipu_glm_4v_plus_generate_title(video_path, artist):
9-
with open(video_path, 'rb') as video_file:
10-
video_base = base64.b64encode(video_file.read()).decode('utf-8')
10+
with open(video_path, "rb") as video_file:
11+
video_base = base64.b64encode(video_file.read()).decode("utf-8")
1112

1213
client = ZhipuAI(api_key=ZHIPU_API_KEY)
1314
response = client.chat.completions.create(
1415
model="glm-4v-plus-0111",
1516
messages=[
16-
{
17-
"role": "user",
18-
"content": [
19-
{
20-
"type": "video_url",
21-
"video_url": {
22-
"url" : video_base
23-
}
24-
},
2517
{
26-
"type": "text",
27-
"text": SLICE_PROMPT
18+
"role": "user",
19+
"content": [
20+
{"type": "video_url", "video_url": {"url": video_base}},
21+
{"type": "text", "text": SLICE_PROMPT},
22+
],
2823
}
29-
]
30-
}
31-
]
24+
],
3225
)
3326
scan_log.info("使用 Zhipu-glm-4v-plus 生成切片标题")
3427
scan_log.info(f"Prompt: {SLICE_PROMPT}")
3528
scan_log.info(f"生成的切片标题为: {response.choices[0].message.content}")
36-
return response.choices[0].message.content.replace("《", "").replace("》", "")
29+
return response.choices[0].message.content.replace("《", "").replace("》", "")

src/autoslice/title_generator.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,38 @@
22
from src.log.logger import scan_log
33
from src.config import MLLM_MODEL
44

5+
56
def title_generator(model_type):
67
"""Decorator to select title generation function based on model type
78
Args:
89
model_type: str, type of model to use
910
Returns:
1011
function: wrapped title generation function
1112
"""
13+
1214
def decorator(func):
1315
def wrapper(video_path, artist):
1416
if model_type == "zhipu":
1517
from .mllm_sdk.zhipu_sdk import zhipu_glm_4v_plus_generate_title
18+
1619
return zhipu_glm_4v_plus_generate_title(video_path, artist)
1720
elif model_type == "gemini":
1821
from .mllm_sdk.gemini_old_sdk import gemini_generate_title
22+
1923
return gemini_generate_title(video_path, artist)
2024
elif model_type == "qwen":
2125
from .mllm_sdk.qwen_sdk import qwen_generate_title
26+
2227
return qwen_generate_title(video_path, artist)
2328
else:
2429
scan_log.error(f"Unsupported model type: {model_type}")
2530
return None
31+
2632
return wrapper
33+
2734
return decorator
2835

36+
2937
@title_generator(MLLM_MODEL)
3038
def generate_title(video_path, artist):
3139
"""Generate title for video
@@ -35,4 +43,4 @@ def generate_title(video_path, artist):
3543
Returns:
3644
str: generated title
3745
"""
38-
pass # The actual implementation is handled by the decorator
46+
pass # The actual implementation is handled by the decorator

src/burn/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
import sys
44
import os
5-
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
5+
6+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

0 commit comments

Comments
 (0)