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 2792e8b0
authored
Mar 13, 2024
by
杨林龙
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
添加mysql工具类
1 parent
6c1e1115
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
4 deletions
main.py
mysql_utils.py
main.py
View file @
2792e8b
...
@@ -174,21 +174,40 @@ def deal_worker(url):
...
@@ -174,21 +174,40 @@ def deal_worker(url):
"""
"""
要执行的函数,在子进程中运行
要执行的函数,在子进程中运行
"""
"""
consuming_start_time
=
time
.
perf_counter
()
print
(
f
"Worker {url} is running..."
)
print
(
f
"Worker {url} is running..."
)
# 解析音频
# 解析音频
res
=
FunasrService
(
url
)
.
transform
()
res
=
FunasrService
(
url
)
.
transform
()
time
.
sleep
(
1
)
answer
=
[]
print
(
str
(
res
[
0
][
"sentence_info"
]))
for
one
in
res
[
0
][
"sentence_info"
]:
start_time
=
one
[
'start'
]
end_time
=
one
[
'end'
]
answer
.
append
(
f
'{"角色1" if one["spk"] == 0 else "角色2"} : {one["text"]} -- 时长:{end_time - start_time}ms'
)
consuming_end_time
=
time
.
perf_counter
()
print
(
f
"Function create_upload_file executed in {(consuming_end_time - consuming_start_time)} 秒"
)
logger
.
info
(
f
"Function create_upload_file executed in {(consuming_end_time - consuming_start_time)} 秒"
)
print
(
f
"Worker {url} finished."
)
print
(
f
"Worker {url} finished."
)
class
UrlParam
(
BaseModel
):
class
UrlParam
(
BaseModel
):
url
:
str
url
:
str
@app.post
(
"/funasr/url"
)
@app.post
(
"/funasr/url
/
"
)
async
def
create_url
(
param
:
UrlParam
):
async
def
create_url
(
param
:
UrlParam
):
try
:
try
:
process
=
multiprocessing
.
Process
(
target
=
deal_worker
,
args
=
(
param
.
url
))
process
=
multiprocessing
.
Process
(
target
=
deal_worker
,
args
=
(
param
.
url
,
))
process
.
start
()
process
.
start
()
return
BaseResponse
(
code
=
200
,
msg
=
"OK"
,
data
=
"你好"
,
time_consuming
=
0
,
)
except
Exception
as
e
:
except
Exception
as
e
:
return
{
"error"
:
str
(
e
)}
return
{
"error"
:
str
(
e
)}
...
@@ -198,7 +217,7 @@ if __name__ == "__main__":
...
@@ -198,7 +217,7 @@ if __name__ == "__main__":
shutil
.
rmtree
(
save_path
)
shutil
.
rmtree
(
save_path
)
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"--host"
,
type
=
str
,
default
=
"0.0.0.0"
)
parser
.
add_argument
(
"--host"
,
type
=
str
,
default
=
"0.0.0.0"
)
parser
.
add_argument
(
"--port"
,
type
=
int
,
default
=
78
88
)
parser
.
add_argument
(
"--port"
,
type
=
int
,
default
=
78
65
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
uvicorn
.
run
(
uvicorn
.
run
(
app
=
"main:app"
,
app
=
"main:app"
,
...
...
mysql_utils.py
0 → 100644
View file @
2792e8b
import
logging
from
mysql.connector
import
pooling
logger
=
logging
.
getLogger
()
# 创建连接池对象
connection_pool
=
pooling
.
MySQLConnectionPool
(
pool_name
=
"mypool"
,
pool_size
=
32
,
pool_reset_session
=
True
,
host
=
""
,
port
=
""
,
database
=
""
,
user
=
""
,
password
=
""
,
autocommit
=
True
,
)
# 从连接池获取连接
def
get_connection
():
logger
.
info
(
"connection_pool size:"
+
str
(
connection_pool
.
_cnx_queue
.
qsize
()))
# 从连接池获取连接
return
connection_pool
.
get_connection
()
def
execute_sql
(
sql
):
try
:
conn
=
get_connection
()
cursor
=
conn
.
cursor
()
cursor
.
execute
(
sql
)
conn
.
commit
()
logger
.
info
(
"sql 执行结束"
)
except
Exception
as
msg
:
logger
.
error
(
"sql执行Exception: "
+
str
(
msg
))
finally
:
cursor
.
close
()
conn
.
close
()
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