Toggle navigation
Toggle navigation
This project
Loading...
Sign in
lizhengwei
/
aigc-embedding-service
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
lizhengwei
2026-06-01 16:54:22 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
cfcc7f7a49783c5cae6e05b8fd453f746ec6a025
cfcc7f7a
1 parent
4eda21f1
jira:NYJ-1656 desc: config api_key
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
15 deletions
src/football_replay_match/cfg/config.yaml
src/football_replay_match/core/api.py
src/football_replay_match/core/api_test.py
src/football_replay_match/core/utils/llm_image.py
src/football_replay_match/core/utils/my_logger.py
src/football_replay_match/cfg/config.yaml
View file @
cfcc7f7
...
...
@@ -24,6 +24,7 @@ llm:
base_url
:
http://192.168.1.59:11434/v1
model_name
:
Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf
temperature
:
0.7
api_key
:
"
no_key"
common:
cache_dir
:
./videos_cache
...
...
src/football_replay_match/core/api.py
View file @
cfcc7f7
...
...
@@ -22,12 +22,16 @@ class FootballReplayMatch:
llm_base_url
=
value_or_default
(
settings
.
llm
.
base_url
,
None
)
model_name
=
value_or_default
(
settings
.
llm
.
model_name
,
None
)
temperature
=
value_or_default
(
settings
.
llm
.
temperature
,
0.7
)
api_key
=
value_or_default
(
settings
.
llm
.
api_key
,
'no_key'
)
self
.
cache_dir
=
value_or_default
(
settings
.
common
.
cache_dir
,
None
)
self
.
task_log_dir
=
value_or_default
(
settings
.
common
.
task_log_dir
,
None
)
save_frames_enable
=
value_or_default
(
settings
.
save_frames_enable
,
False
)
self
.
videoEventRecognition
=
FootballReplayVideoEvent
(
llm_base_url
,
model_name
,
temperature
,
'no_key'
,
self
.
cache_dir
,
save_frames_enable
)
self
.
videoMatchLive
=
FootballReplayMatchLive
(
llm_base_url
,
model_name
,
temperature
,
'no_key'
,
self
.
cache_dir
,
save_frames_enable
)
self
.
videoEventRecognition
=
FootballReplayVideoEvent
(
llm_base_url
,
model_name
,
temperature
,
api_key
,
self
.
cache_dir
,
save_frames_enable
)
self
.
videoMatchLive
=
FootballReplayMatchLive
(
llm_base_url
,
model_name
,
temperature
,
api_key
,
self
.
cache_dir
,
save_frames_enable
)
def
match_by_time
(
self
,
replay
,
events
):
...
...
@@ -103,7 +107,10 @@ class FootballReplayMatch:
# print(f"判断是否是进球耗时: {end_time - start_time} 秒")
replay_event_name
=
replay_det_info
.
get
(
'event_name'
,
''
)
if
replay_event_name
==
'进球'
:
start_time1
=
time
.
time
()
matched_event
=
self
.
match_by_llm
(
replay_info
,
goal_live_events
,
task_id
)
end_time1
=
time
.
time
()
logger
.
info
(
f
"LLM_match_all_cost_time:{end_time1-start_time1:.2f}seconds"
)
if
matched_event
is
None
:
logger
.
info
(
f
"{task_id}_LLM_think_{replay_info['url']}_{replay_start_utc}_{replay_end_utc}_is_goal_but_no_matched_event"
)
# print(f"{task_id}_LLM认为视频{replay_info['url']}_{replay_start_utc}_{replay_end_utc} 是进球但是未能找到匹配的事件")
...
...
src/football_replay_match/core/api_test.py
View file @
cfcc7f7
...
...
@@ -45,8 +45,8 @@ def _fake_settings(match_by_time_threshold: int = 30, cache_dir_tag: str = "test
temperature
=
0.7
,
api_key
=
'no_key'
),
common
=
SimpleNamespace
(
cache_dir
=
f
"/root/lzw/tmp_0528_replay_cache_{cache_dir_tag}/videos_cache"
,
task_log_dir
=
f
"/root/lzw/tmp_0528_replay_cache_{cache_dir_tag}/tasks_log"
common
=
SimpleNamespace
(
cache_dir
=
f
"/root/lzw/tmp_0601_replay_cache_{cache_dir_tag}/videos_cache"
,
task_log_dir
=
f
"/root/lzw/tmp_0601_replay_cache_{cache_dir_tag}/tasks_log"
),
save_frames_enable
=
True
,
)
...
...
@@ -112,6 +112,8 @@ def test_match_by_time_success():
replays_and_events_pair
=
get_replays_and_events_pair
()
for
replays_mp4_dir
,
events_mp4_dir
in
replays_and_events_pair
:
# replays_mp4_dir = "/root/lzw/finished/69e5102bfd87d43d09bba90d-auto-10154993/replays/videos"
# events_mp4_dir = r"/root/lzw/finished/69e5102bfd87d43d09bba90d-auto-10154993/live/videos"
print
(
100
*
"="
)
print
(
f
"replays_mp4_dir: {replays_mp4_dir}, events_mp4_dir: {events_mp4_dir}"
)
...
...
@@ -121,13 +123,15 @@ def test_match_by_time_success():
frm
=
FootballReplayMatch
(
settings
)
# replays_mp4_dir = "/root/lzw/finished/69dd5845dd0412067b8d5587-auto-1776074760653/replays/videos"
relays_mp4_names
=
get_video_files_pathlib
(
replays_mp4_dir
)
# events_mp4_dir = r"/root/lzw/finished/69dd5845dd0412067b8d5587-auto-1776074760653/live/videos"
event_list
=
get_event_list
(
events_mp4_dir
)
all_time
=
0.0
max_time
=
0.0
for
i
,
replay_name
in
enumerate
(
relays_mp4_names
):
...
...
src/football_replay_match/core/utils/llm_image.py
View file @
cfcc7f7
...
...
@@ -4,15 +4,22 @@ import subprocess
import
sys
from
pathlib
import
Path
from
typing
import
Optional
import
time
import
os
from
urllib.parse
import
urlparse
import
cv2
from
aabd.stream_chain
import
video2frames
import
json
import
logging
import
hashlib
logger
=
logging
.
getLogger
(
__name__
)
try
:
from
.my_logger
import
get_logger
except
:
from
my_logger
import
get_logger
logger
=
get_logger
()
_IS_ABSOLUTE_UTC_THRESHOLD
=
1
_000_000_000
...
...
@@ -81,7 +88,10 @@ class Video2Frame:
if
not
download_video_path
.
exists
():
logger
.
info
(
f
"download_video: {url} -> {download_video_path}"
)
video_root_path
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
start_time
=
time
.
time
()
download_to_mp4
(
url
,
str
(
download_video_path
),
duration
=
None
)
end_time
=
time
.
time
()
logger
.
info
(
f
"download_video_cost_time:{end_time - start_time:.2f}seconds"
)
logger
.
info
(
f
"video_path: {download_video_path}"
)
...
...
@@ -95,6 +105,7 @@ class Video2Frame:
with
cache_name
.
open
(
'r'
,
encoding
=
'utf-8'
)
as
f
:
return
json
.
load
(
f
)
else
:
start_time
=
time
.
time
()
cache_dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
data
=
{
'fps'
:
fps
,
...
...
@@ -104,7 +115,7 @@ class Video2Frame:
cache_frames
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
for
f
in
self
.
iter_mp4
(
str
(
download_video_path
),
start
,
end
,
fps
):
frame
=
f
[
'frame'
]
time
=
f
[
'src_frame_time'
]
duration
=
f
[
'src_frame_time'
]
fps
=
f
[
'fps'
]
data
[
'fps'
]
=
fps
if
roi
is
not
None
:
...
...
@@ -116,10 +127,10 @@ class Video2Frame:
_
,
buffer
=
cv2
.
imencode
(
'.jpg'
,
frame
)
b64_str
=
base64
.
b64encode
(
buffer
)
.
decode
(
'utf-8'
)
data
[
'frames'
]
.
append
({
'time'
:
time
,
'image'
:
b64_str
})
data
[
'frames'
]
.
append
({
'time'
:
duration
,
'image'
:
b64_str
})
if
self
.
save_frames_enable
:
frame_path
=
cache_frames
/
f
"{
time
:015d}.jpg"
frame_path
=
cache_frames
/
f
"{
duration
:015d}.jpg"
cv2
.
imwrite
(
frame_path
,
frame
)
cache_name
.
parent
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
...
...
@@ -127,6 +138,8 @@ class Video2Frame:
with
cache_name
.
open
(
'w'
,
encoding
=
'utf-8'
)
as
f
:
json
.
dump
(
data
,
f
,
indent
=
4
)
logger
.
info
(
f
"save_cache: {cache_name}"
)
end_time
=
time
.
time
()
logger
.
info
(
f
"to_frames_cost_time:{end_time - start_time:.2f}seconds"
)
return
data
def
to_llm_contents
(
self
,
url
,
cache
=
None
,
fps
=
None
,
start
=
None
,
end
=
None
,
roi
=
None
,
max_px_area
=
None
,
...
...
src/football_replay_match/core/utils/my_logger.py
View file @
cfcc7f7
...
...
@@ -2,6 +2,7 @@ import os
import
time
import
logging
from
functools
import
lru_cache
from
logging.handlers
import
TimedRotatingFileHandler
# 引入按时间切割的处理器
@lru_cache
(
maxsize
=
1
)
def
get_logger
():
...
...
@@ -10,7 +11,6 @@ def get_logger():
logger
.
setLevel
(
logging
.
INFO
)
# 1. 配置日志输出格式
# 修改点:增加了 %(filename)s:%(lineno)d 来显示文件名和行号
formatter
=
logging
.
Formatter
(
'
%(asctime)
s.
%(msecs)03
d -
%(name)
s -
%(levelname)
s - [
%(filename)
s:
%(lineno)
d] -
%(message)
s'
,
datefmt
=
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
...
...
@@ -21,13 +21,27 @@ def get_logger():
console_handler
.
setFormatter
(
formatter
)
logger
.
addHandler
(
console_handler
)
# 3. 创建文件处理器
# 3. 创建
按天自动切割的
文件处理器
log_dir
=
"logs"
if
not
os
.
path
.
exists
(
log_dir
):
os
.
makedirs
(
log_dir
)
log_file
=
os
.
path
.
join
(
log_dir
,
f
"run_{time.strftime('
%
Y
%
m
%
d')}.log"
)
file_handler
=
logging
.
FileHandler
(
log_file
,
encoding
=
'utf-8'
)
# 基础日志文件名
base_log_file
=
os
.
path
.
join
(
log_dir
,
"run.log"
)
# TimedRotatingFileHandler 参数说明:
# when='midnight' : 每天凌晨自动切割
# interval=1 : 每1个单位(即每天)切割一次
# backupCount=30 : 保留最近30天的日志,超出的会自动删除(防止硬盘被写满)
# encoding='utf-8': 防止中文乱码
file_handler
=
TimedRotatingFileHandler
(
base_log_file
,
when
=
'midnight'
,
interval
=
1
,
backupCount
=
30
,
encoding
=
'utf-8'
)
file_handler
.
suffix
=
"
%
Y
%
m
%
d"
# 切割后的旧日志会自动带上日期后缀,如 run.log.20260601
file_handler
.
setFormatter
(
formatter
)
logger
.
addHandler
(
file_handler
)
...
...
Please
register
or
login
to post a comment