Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
funasr_web
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 53a42b26
authored
Mar 25, 2024
by
‘chizw’
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]oom优化
1 parent
24d7884e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
11 deletions
funasr_service.py
kafka_service/funasr_consumer.py
mysql_service/funasr_db.py
utils/ap_scheduler_util.py
funasr_service.py
View file @
53a42b2
...
@@ -20,9 +20,9 @@ model = AutoModel(
...
@@ -20,9 +20,9 @@ model = AutoModel(
device
=
"cpu"
,
device
=
"cpu"
,
batch_size_s
=
100
,
batch_size_s
=
100
,
batch_size_threshold_s
=
60
*
60
batch_size_threshold_s
=
60
*
60
# model="iic/speech_paraformer-large-vad-punc_asr_nat-zh-cn-16k-common-vocab8404-pytorch",
# model="iic/speech_paraformer-large-vad-punc_asr_nat-zh-cn-16k-common-vocab8404-pytorch",
# vad_model="iic/speech_fsmn_vad_zh-cn-16k-common-pytorch",
# vad_model="iic/speech_fsmn_vad_zh-cn-16k-common-pytorch",
# punc_model="iic/punc_ct-transformer_cn-en-common-vocab471067-large",
# punc_model="iic/punc_ct-transformer_cn-en-common-vocab471067-large",
)
)
...
@@ -101,7 +101,7 @@ def deal_worker(task_id: str):
...
@@ -101,7 +101,7 @@ def deal_worker(task_id: str):
or
exception_msg
==
"local variable 'raw_text' referenced before assignment"
:
or
exception_msg
==
"local variable 'raw_text' referenced before assignment"
:
funasr_db
.
update_ali_asr_model_res_skip
(
task_id
)
funasr_db
.
update_ali_asr_model_res_skip
(
task_id
)
return
return
funasr_db
.
update_process_task
(
task_id
,
str
(
multiprocessing
.
current_process
()
.
name
))
funasr_db
.
update_process_task
(
task_id
,
str
(
multiprocessing
.
current_process
()
.
name
))
url
=
sql_res
[
0
][
"file_url"
]
url
=
sql_res
[
0
][
"file_url"
]
if
url
==
""
or
len
(
url
)
<
1
or
not
url
.
startswith
(
"http"
):
if
url
==
""
or
len
(
url
)
<
1
or
not
url
.
startswith
(
"http"
):
funasr_db
.
update_ali_asr_model_res_skip
(
task_id
)
funasr_db
.
update_ali_asr_model_res_skip
(
task_id
)
...
@@ -159,3 +159,15 @@ def merge_spk_transform_output(sentence_info):
...
@@ -159,3 +159,15 @@ def merge_spk_transform_output(sentence_info):
output
.
append
(
model_output
(
spk
,
offset
,
duration
,
content
)
.
to_dict
())
output
.
append
(
model_output
(
spk
,
offset
,
duration
,
content
)
.
to_dict
())
json_output
=
json
.
dumps
(
output
,
ensure_ascii
=
False
)
json_output
=
json
.
dumps
(
output
,
ensure_ascii
=
False
)
return
json_output
return
json_output
def
task_compensate_send
():
try
:
log
.
info
(
"task_compensate_send start"
)
res
=
funasr_db
.
select_time_out_task
()
if
res
is
not
None
and
len
(
res
)
>
0
:
for
item
in
res
:
funasr_producer
.
send_task_id
(
item
[
"task_id"
])
log
.
info
(
"task_compensate_send end"
)
except
Exception
as
e
:
log
.
error
(
"task_compensate_send error"
,
e
)
kafka_service/funasr_consumer.py
View file @
53a42b2
...
@@ -117,13 +117,13 @@ def consumer_process_init():
...
@@ -117,13 +117,13 @@ def consumer_process_init():
def
consumer_process_callback
(
res
):
def
consumer_process_callback
(
res
):
log
.
info
(
f
"consumer_process_callback:{multiprocessing.current_process().name}, res:{res}"
)
log
.
info
(
f
"consumer_process_callback:{multiprocessing.current_process().name}, res:{res}"
)
count
=
funasr_db
.
select_process_all_end
()
#
count = funasr_db.select_process_all_end()
if
count
is
not
None
and
int
(
count
)
==
0
:
#
if count is not None and int(count) == 0:
res
=
funasr_db
.
select_ali_asr_model_wait
()
#
res = funasr_db.select_ali_asr_model_wait()
if
res
is
not
None
and
len
(
res
)
>
0
:
#
if res is not None and len(res) > 0:
data
=
{
"task_id"
:
res
[
0
][
"task_id"
]}
#
data = {"task_id": res[0]["task_id"]}
message
=
json
.
dumps
(
data
)
.
encode
(
'utf-8'
)
#
message = json.dumps(data).encode('utf-8')
funasr_service
.
handle_process
(
str
(
message
))
#
funasr_service.handle_process(str(message))
def
consumer_process_error_callback
(
err
):
def
consumer_process_error_callback
(
err
):
...
...
mysql_service/funasr_db.py
View file @
53a42b2
...
@@ -79,9 +79,19 @@ def update_process_task(task_id: str, process_name: str):
...
@@ -79,9 +79,19 @@ def update_process_task(task_id: str, process_name: str):
)
)
return
pool
.
update_one
(
update_sql
,
(
process_name
,
task_id
))
return
pool
.
update_one
(
update_sql
,
(
process_name
,
task_id
))
def
select_process_all_end
():
def
select_process_all_end
():
sql
=
(
sql
=
(
"select count(aamr.id) from ali_asr_model_res aamr where aamr.del_flag = 0 "
"select count(aamr.id) from ali_asr_model_res aamr where aamr.del_flag = 0 "
"and aamr.execute_process_name is not null and aamr.task_status =
%
s;"
"and aamr.execute_process_name is not null and aamr.task_status =
%
s;"
)
)
return
pool
.
select_all
(
sql
,
(
0
))
return
pool
.
select_all
(
sql
,
(
0
))
def
select_time_out_task
():
sql
=
(
"select id,task_id,file_url,task_status from ali_asr_model_res aamr where aamr.del_flag = 0 "
"and aamr.output_data is null and aamr.execute_process_name is not null and exception_limit < 3"
"and aamr.updated_time < TIMESTAMPADD(MINUTE, -
%
s, NOW());"
)
return
pool
.
select_all
(
sql
,
(
30
))
utils/ap_scheduler_util.py
0 → 100644
View file @
53a42b2
import
datetime
import
time
import
funasr_service
from
apscheduler.schedulers.blocking
import
BlockingScheduler
from
apscheduler.schedulers.background
import
BackgroundScheduler
from
apscheduler.jobstores.mongodb
import
MongoDBJobStore
from
apscheduler.jobstores.memory
import
MemoryJobStore
from
apscheduler.executors.pool
import
ThreadPoolExecutor
,
ProcessPoolExecutor
from
log.logger
import
log
jobstores
=
{
'default'
:
MemoryJobStore
()
}
executors
=
{
'default'
:
ThreadPoolExecutor
(
2
),
# 'processpool': ProcessPoolExecutor(3)
}
job_defaults
=
{
'coalesce'
:
True
,
'max_instances'
:
3
}
def
job_func
():
print
(
datetime
.
datetime
.
utcnow
()
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S.
%
f"
)[:
-
3
])
def
scheduler_start
():
log
.
info
(
"scheduler_starting..."
)
scheduler
=
BackgroundScheduler
(
executors
=
executors
,
job_defaults
=
job_defaults
)
scheduler
.
add_job
(
funasr_service
.
task_compensate_send
,
'interval'
,
minutes
=
30
)
scheduler
.
start
()
log
.
info
(
"scheduler_start success"
)
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment