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 9d35f90e
authored
Mar 15, 2024
by
杨林龙
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
优化日志打印
1 parent
9e307ed4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
19 deletions
main.py
main.py
View file @
9d35f90
...
@@ -22,23 +22,13 @@ from funasr.download.file import download_from_url
...
@@ -22,23 +22,13 @@ from funasr.download.file import download_from_url
import
multiprocessing
import
multiprocessing
app
=
FastAPI
()
app
=
FastAPI
()
#全局进程池
#
全局进程池
pool
=
multiprocessing
.
Pool
(
processes
=
4
)
pool
=
multiprocessing
.
Pool
(
processes
=
1
)
db
=
MysqlHelper
.
MysqlHelper
(
db
=
MysqlHelper
.
MysqlHelper
(
DbConect
.
ali_asr_model
DbConect
.
ali_asr_model
)
)
model
=
AutoModel
(
model
=
"paraformer-zh"
,
vad_model
=
"fsmn-vad"
,
punc_model
=
"ct-punc-c"
,
spk_model
=
"cam++"
,
# openai_model="Whisper-large-v3",
ncpu
=
2
,
)
class
BaseResponse
(
BaseModel
):
class
BaseResponse
(
BaseModel
):
code
:
int
=
pydantic
.
Field
(
200
,
description
=
"HTTP status code"
)
code
:
int
=
pydantic
.
Field
(
200
,
description
=
"HTTP status code"
)
msg
:
str
=
pydantic
.
Field
(
"success"
,
description
=
"HTTP status message"
)
msg
:
str
=
pydantic
.
Field
(
"success"
,
description
=
"HTTP status message"
)
...
@@ -172,7 +162,7 @@ async def create_upload_file(file: UploadFile):
...
@@ -172,7 +162,7 @@ async def create_upload_file(file: UploadFile):
)
)
consuming_end_time
=
time
.
perf_counter
()
consuming_end_time
=
time
.
perf_counter
()
print
(
f
"Function create_upload_file executed in {(consuming_end_time - consuming_start_time)} 秒"
)
print
(
f
"Function create_upload_file executed in {(consuming_end_time - consuming_start_time)} 秒"
)
log
ger
.
info
(
log
.
info
(
f
"Function create_upload_file executed in {(consuming_end_time - consuming_start_time)} 秒"
f
"Function create_upload_file executed in {(consuming_end_time - consuming_start_time)} 秒"
)
)
os
.
remove
(
save_file
)
os
.
remove
(
save_file
)
...
@@ -208,7 +198,9 @@ def deal_worker(url: str, task_id: str):
...
@@ -208,7 +198,9 @@ def deal_worker(url: str, task_id: str):
要执行的函数,在子进程中运行
要执行的函数,在子进程中运行
"""
"""
try
:
try
:
log
.
info
(
f
"Worker {task_id} is running..."
)
# 获取当前进程的名字
name
=
multiprocessing
.
current_process
()
.
name
log
.
info
(
f
"Worker {task_id} is running...进程名字 {name}"
)
consuming_start_time
=
time
.
perf_counter
()
consuming_start_time
=
time
.
perf_counter
()
# 解析音频
# 解析音频
res
=
FunasrService
(
url
)
.
transform
()
res
=
FunasrService
(
url
)
.
transform
()
...
@@ -248,10 +240,13 @@ def deal_worker(url: str, task_id: str):
...
@@ -248,10 +240,13 @@ def deal_worker(url: str, task_id: str):
except
Exception
as
e
:
except
Exception
as
e
:
updateSql
=
(
f
"update ali_asr_model_res t set t.task_status = 2 where t.task_id = '{task_id}';"
)
updateSql
=
(
f
"update ali_asr_model_res t set t.task_status = 2 where t.task_id = '{task_id}';"
)
db
.
execute_modify
(
updateSql
)
db
.
execute_modify
(
updateSql
)
log
.
error
(
f
"Worker error
:
{e}"
)
log
.
error
(
f
"Worker error{e}"
)
traceback
.
print_exc
()
traceback
.
print_exc
()
return
{
"Worker error"
:
str
(
e
)}
return
{
"Worker error"
:
str
(
e
)}
def
deal_worker_wrap
(
args
):
return
deal_worker
(
*
args
)
class
UrlParam
(
BaseModel
):
class
UrlParam
(
BaseModel
):
url
:
str
url
:
str
...
@@ -265,11 +260,12 @@ async def create_url(param: UrlParam):
...
@@ -265,11 +260,12 @@ async def create_url(param: UrlParam):
insertSql
=
(
insertSql
=
(
f
"INSERT INTO dj_smartcarlife.ali_asr_model_res (task_id,file_url,task_status) VALUES ('{task_id}','{url}',0);"
)
f
"INSERT INTO dj_smartcarlife.ali_asr_model_res (task_id,file_url,task_status) VALUES ('{task_id}','{url}',0);"
)
res
=
db
.
execute_modify
(
insertSql
)
res
=
db
.
execute_modify
(
insertSql
)
process
=
multiprocessing
.
Process
(
target
=
deal_worker
,
args
=
(
url
,
task_id
,))
# process = multiprocessing.Process(target=deal_worker, args=(url, task_id,))
log
.
info
(
f
"process:{process}"
)
# log.info(f"process:{process}")
process
.
start
()
# process.start()
# pool.map_async(target=deal_worker_wrap,[(url,task_id)])
# pool.map_async()
response
=
BaseResponse
(
response
=
BaseResponse
(
code
=
200
,
code
=
200
,
msg
=
"success"
,
msg
=
"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