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 f131d936
authored
Mar 19, 2024
by
‘chizw’
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
模型日志优化
1 parent
9bacdebc
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
60 additions
and
16 deletions
config/DbConect.py
config/config_dev.py
funasr_service.py
kafka_service/funasr_consumer.py
mysql_service/MysqlHelper.py
mysql_service/funasr_db.py
mysql_service/test_db.py
config/DbConect.py
View file @
f131d93
# 广联DJ
ali_asr_model
=
{
"host"
:
'192.168.3.227'
,
"port"
:
3306
,
"user"
:
'os_user'
,
"password"
:
'os#123'
,
"db"
:
'dj_smartcarlife'
,
"charset"
:
'utf8'
}
\ No newline at end of file
ali_asr_model
=
{
"host"
:
'192.168.1.39'
,
"port"
:
3306
,
"user"
:
'wechat_user'
,
"password"
:
'b4WRTkl'
,
"db"
:
'dj_smartcarlife'
,
"charset"
:
'utf8'
}
\ No newline at end of file
config/config_dev.py
View file @
f131d93
...
...
@@ -2,11 +2,11 @@ class Config:
DEBUG
=
False
env
=
'dev'
# 数据库连接配置
host
=
'192.168.3.227
'
host
=
'192.168.1.39
'
port
=
3306
user
=
'
dev
_user'
password
=
'
df234f
l'
database
=
'
glsx_car_servic
e'
user
=
'
wechat
_user'
password
=
'
b4WRTk
l'
database
=
'
dj_smartcarlif
e'
# Kafka consumer配置
kafka_consumer_bootstrap_servers
=
'192.168.3.131:9092'
kafka_consumer_group_id
=
'funasr_dev'
...
...
funasr_service.py
View file @
f131d93
...
...
@@ -14,7 +14,7 @@ model = AutoModel(
vad_model
=
"fsmn-vad"
,
punc_model
=
"ct-punc"
,
spk_model
=
"cam++"
,
ncpu
=
8
,
ncpu
=
4
,
)
...
...
@@ -37,7 +37,7 @@ class FunasrService(object):
@timeit
def
transform
(
self
):
res
=
model
.
generate
(
input
=
self
.
path
,
batch_size_s
=
3
00
,
hotword
=
"问界 80"
)
res
=
model
.
generate
(
input
=
self
.
path
,
batch_size_s
=
1
00
,
hotword
=
"问界 80"
)
# print(res)
return
res
...
...
@@ -76,7 +76,7 @@ def deal_worker(task_id: str):
"""
try
:
res
=
funasr_db
.
select_ali_asr_model_res
(
task_id
)
if
res
is
None
or
len
(
res
)
<
1
:
if
res
is
None
or
isinstance
(
res
,
bool
)
or
len
(
res
)
<
1
:
return
output_data
=
json
.
loads
(
res
)[
0
][
"output_data"
]
if
output_data
is
not
None
:
...
...
@@ -88,7 +88,7 @@ def deal_worker(task_id: str):
res
=
FunasrService
(
url
)
.
transform
()
if
len
(
res
)
<
1
:
log
.
info
(
"res:
%
s"
%
res
)
funasr_db
.
update_ali_asr_model_res
(
task_id
,
res
)
funasr_db
.
update_ali_asr_model_res
(
task_id
,
res
,
0
)
return
sentence_info
=
res
[
0
][
"sentence_info"
]
log
.
info
(
"res.sentence_info:
%
s"
%
sentence_info
)
...
...
@@ -112,9 +112,10 @@ def deal_worker(task_id: str):
output
.
append
(
model_output
(
spk
,
offset
,
duration
,
content
)
.
to_dict
())
json_output
=
json
.
dumps
(
output
,
ensure_ascii
=
False
)
log
.
info
(
f
"output:{json_output}"
)
funasr_db
.
update_ali_asr_model_res
(
task_id
,
json_output
)
execute_time
=
time
.
perf_counter
()
-
consuming_start_time
funasr_db
.
update_ali_asr_model_res
(
task_id
,
json_output
,
int
((
execute_time
*
1000
)))
log
.
info
(
f
"Function create_upload_file executed in {
(time.perf_counter() - consuming_start_time)
} s"
f
"Function create_upload_file executed in {
execute_time
} s"
)
log
.
info
(
f
"Worker {task_id} finished."
)
except
Exception
as
e
:
...
...
kafka_service/funasr_consumer.py
View file @
f131d93
import
time
import
traceback
from
kafka
import
KafkaConsumer
import
funasr_service
...
...
@@ -70,6 +72,7 @@ def consume_kafka():
end_time
=
time
.
time
()
log
.
info
(
"handle_process耗时:"
+
str
(
end_time
-
start_time
))
except
Exception
as
e
:
traceback
.
print_exc
()
log
.
error
(
"ocr consumer Exception: "
+
str
(
e
))
...
...
mysql_service/MysqlHelper.py
View file @
f131d93
#import os,sys
import
json
import
traceback
import
pymysql
from
config
import
DbConect
from
log.logger
import
log
...
...
@@ -74,6 +74,7 @@ class MysqlHelper:
result
=
True
except
Exception
as
e
:
log
.
error
(
e
)
traceback
.
print_exc
()
self
.
con
.
rollback
result
=
False
return
result
...
...
@@ -96,6 +97,7 @@ class MysqlHelper:
return
res
except
Exception
as
e
:
log
.
error
(
e
)
traceback
.
print_exc
()
return
False
finally
:
pass
...
...
@@ -112,6 +114,7 @@ class MysqlHelper:
return
res
except
Exception
as
e
:
log
.
error
(
e
)
traceback
.
print_exc
()
return
False
finally
:
pass
...
...
mysql_service/funasr_db.py
View file @
f131d93
from
mysql_service
import
MysqlHelper
from
config
import
DbConect
from
config.config
import
ConfigInfo
db
=
MysqlHelper
.
MysqlHelper
(
DbConect
.
ali_asr_model
...
...
@@ -12,15 +13,15 @@ def insert_ali_asr_model_res(task_id: str, url: str):
return
db
.
execute_modify
(
insert_sql
)
def
update_ali_asr_model_res
(
task_id
:
str
,
json_output
:
str
):
def
update_ali_asr_model_res
(
task_id
:
str
,
json_output
:
str
,
execute_time
:
int
):
update_sql
=
(
f
"update ali_asr_model_res t set t.output_data = '{json_output}',t.task_status = 1 where t.task_id = '{task_id}';"
)
f
"update ali_asr_model_res t set t.output_data = '{json_output}',t.task_status = 1
, t.execute_time = {execute_time}
where t.task_id = '{task_id}';"
)
return
db
.
execute_modify
(
update_sql
)
def
update_ali_asr_model_res_fail
(
task_id
:
str
):
def
update_ali_asr_model_res_fail
(
task_id
:
str
,
exception
:
str
):
update_sql
=
(
f
"update ali_asr_model_res t set t.task_status = 2 where t.task_id = '{task_id}';"
)
f
"update ali_asr_model_res t set t.task_status = 2
, t.exception_log = '{exception}'
where t.task_id = '{task_id}';"
)
return
db
.
execute_modify
(
update_sql
)
...
...
mysql_service/test_db.py
0 → 100644
View file @
f131d93
import
time
import
traceback
from
log.logger
import
log
from
mysql_service
import
funasr_db
from
mysql_service
import
MysqlHelper
from
config
import
DbConect
consuming_start_time
=
time
.
perf_counter
()
db
=
MysqlHelper
.
MysqlHelper
(
DbConect
.
ali_asr_model
)
task_id
=
str
(
"63764ce2-e5cb-11ee-928c-b083fec01e48"
)
url
=
"https://smartcard-1253080096.cos.ap-guangzhou.myqcloud.com/audio/4827E2F0CD24_1709084561_4827E2F0CD24-1709084561.MP3"
# res = funasr_db.insert_ali_asr_model_res(task_id, url)
# print(f"res:{res}")
sql
=
"INSERT INTO dj_smartcarlife.ali_asr_model_res (task_id,file_url,task_status) VALUES ("
\
"'47f9402c-e5cc-11ee-928c-b083fec01e48','https://img01.glsx.com.cn/weapp/resource/wav/122m4a.wav',0);"
res
=
db
.
execute_modify
(
sql
)
print
(
res
)
try
:
time
.
sleep
(
2
)
execute_time
=
time
.
perf_counter
()
-
consuming_start_time
log
.
info
(
f
"Function create_upload_file executed in {execute_time} s"
)
funasr_db
.
update_ali_asr_model_res
(
task_id
,
task_id
,
int
((
execute_time
*
1000
)))
if
res
is
None
or
isinstance
(
res
,
bool
)
or
len
(
res
)
<
1
:
print
(
"======"
)
except
Exception
as
e
:
print
(
f
"e:{traceback.format_exc()}"
)
funasr_db
.
update_ali_asr_model_res_fail
(
task_id
,
str
(
traceback
.
format_exc
()))
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