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 f38430d6
authored
Mar 18, 2024
by
杨林龙
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
优化配置项导入
1 parent
61152415
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
25 deletions
config/config.py
funasr.log
kafka_service/funasr_consumer.py
log/logger.py
main.py
config/config.py
View file @
f38430d
import
sys
import
sys
from
log.logger
import
log
from
log.logger
import
log
environment
=
sys
.
argv
[
1
]
if
len
(
sys
.
argv
)
>
1
else
"default"
class
ConfigInfo
:
# environment = os.environ.get('ENV')
environment
=
sys
.
argv
[
1
]
if
len
(
sys
.
argv
)
>
1
else
"dev"
if
environment
==
'pro'
:
# environment = os.environ.get('ENV')
from
config_release
import
Config
if
environment
==
'pro'
:
from
config.config_release
import
Config
log
.
info
(
vars
(
Config
))
log
.
info
(
vars
(
Config
))
elif
environment
==
'test'
:
elif
environment
==
'test'
:
from
config_test
import
Config
from
config.config_test
import
Config
log
.
info
(
vars
(
Config
))
log
.
info
(
vars
(
Config
))
else
:
else
:
from
config_dev
import
Config
from
config.config_dev
import
Config
log
.
info
(
vars
(
Config
))
log
.
info
(
vars
(
Config
))
class
ConfigInfo
:
DEBUG
=
Config
.
DEBUG
DEBUG
=
Config
.
DEBUG
env
=
Config
.
env
env
=
Config
.
env
# 数据库连接配置
# 数据库连接配置
...
@@ -30,5 +26,5 @@ class ConfigInfo:
...
@@ -30,5 +26,5 @@ class ConfigInfo:
kafka_consumer_bootstrap_servers
=
Config
.
kafka_consumer_bootstrap_servers
kafka_consumer_bootstrap_servers
=
Config
.
kafka_consumer_bootstrap_servers
kafka_consumer_group_id
=
Config
.
kafka_consumer_group_id
kafka_consumer_group_id
=
Config
.
kafka_consumer_group_id
kafka_consumer_auto_offset_reset
=
Config
.
kafka_consumer_auto_offset_reset
kafka_consumer_auto_offset_reset
=
Config
.
kafka_consumer_auto_offset_reset
kafka_consumer_
topic
=
Config
.
kafka_consumer
_topic
kafka_consumer_
analysis_topic
=
Config
.
kafka_consumer_analysis
_topic
charset
=
Config
.
charset
charset
=
Config
.
charset
funasr.log
View file @
f38430d
...
@@ -133,3 +133,12 @@
...
@@ -133,3 +133,12 @@
2024-03-15 18:39:43,949 12724 MysqlHelper.py[line:72] - INFO: execute_modify result:1
2024-03-15 18:39:43,949 12724 MysqlHelper.py[line:72] - INFO: execute_modify result:1
2024-03-15 18:39:43,949 12724 funasr_service.py[line:103] - INFO: Function create_upload_file executed in 40.10529479999968 s
2024-03-15 18:39:43,949 12724 funasr_service.py[line:103] - INFO: Function create_upload_file executed in 40.10529479999968 s
2024-03-15 18:39:43,949 12724 funasr_service.py[line:106] - INFO: Worker 3363630e-e2b8-11ee-b8f9-a0e70be87132 finished.
2024-03-15 18:39:43,949 12724 funasr_service.py[line:106] - INFO: Worker 3363630e-e2b8-11ee-b8f9-a0e70be87132 finished.
2024-03-18 11:03:06,031 24452 funasr_consumer.py[line:17] - INFO: 启动2
2024-03-18 11:03:06,170 24452 funasr_consumer.py[line:32] - INFO: 启动3
2024-03-18 11:05:22,236 21236 funasr_consumer.py[line:17] - INFO: 启动2
2024-03-18 11:05:22,617 21236 funasr_consumer.py[line:32] - INFO: 启动3
2024-03-18 11:05:22,640 21236 config.py[line:15] - INFO: {'__module__': 'config.config_dev', 'DEBUG': False, 'env': 'dev', 'host': '192.168.3.227', 'port': 3306, 'user': 'dev_user', 'password': 'df234fl', 'database': 'glsx_car_service', 'kafka_consumer_bootstrap_servers': '192.168.3.131:9092', 'kafka_consumer_group_id': 'funasr_dev', 'kafka_consumer_auto_offset_reset': 'earliest', 'kafka_consumer_analysis_topic': 'funasr_analysis_topic', 'charset': 'utf8', '__dict__': <attribute '__dict__' of 'Config' objects>, '__weakref__': <attribute '__weakref__' of 'Config' objects>, '__doc__': None}
2024-03-18 11:06:30,820 25204 funasr_consumer.py[line:17] - INFO: 启动2
2024-03-18 11:06:30,928 25204 funasr_consumer.py[line:32] - INFO: 启动3
2024-03-18 11:06:30,932 25204 config.py[line:15] - INFO: {'__module__': 'config.config_dev', 'DEBUG': False, 'env': 'dev', 'host': '192.168.3.227', 'port': 3306, 'user': 'dev_user', 'password': 'df234fl', 'database': 'glsx_car_service', 'kafka_consumer_bootstrap_servers': '192.168.3.131:9092', 'kafka_consumer_group_id': 'funasr_dev', 'kafka_consumer_auto_offset_reset': 'earliest', 'kafka_consumer_analysis_topic': 'funasr_analysis_topic', 'charset': 'utf8', '__dict__': <attribute '__dict__' of 'Config' objects>, '__weakref__': <attribute '__weakref__' of 'Config' objects>, '__doc__': None}
2024-03-18 11:06:30,967 21780 funasr_consumer.py[line:58] - INFO: 启动consume_kafka
kafka_service/funasr_consumer.py
View file @
f38430d
...
@@ -53,18 +53,18 @@ def execute_sql(sql):
...
@@ -53,18 +53,18 @@ def execute_sql(sql):
conn
.
close
()
conn
.
close
()
#
# 循环消费消息
def
consume_kafka
():
def
consume_kafka
():
log
.
info
(
"启动consume_kafka"
)
log
.
info
(
"启动consume_kafka"
)
# 消费消息并进行逻辑处理
# 消费消息并进行逻辑处理
try
:
try
:
for
m
sg
in
consumer
:
for
m
essage
in
consumer
:
if
m
sg
is
None
:
if
m
essage
is
None
:
continue
continue
# 处理逻辑
# 处理逻辑
start_time
=
time
.
time
()
start_time
=
time
.
time
()
# funasr_service.handle_process(msg)
# funasr_service.handle_process(message)
funasr_service
.
handle_process
(
str
(
message
.
value
.
decode
(
'utf-8'
)))
print
(
"task handle"
)
print
(
"task handle"
)
end_time
=
time
.
time
()
end_time
=
time
.
time
()
log
.
info
(
"handle_process耗时:"
+
str
(
end_time
-
start_time
))
log
.
info
(
"handle_process耗时:"
+
str
(
end_time
-
start_time
))
...
@@ -73,8 +73,8 @@ def consume_kafka():
...
@@ -73,8 +73,8 @@ def consume_kafka():
# 循环消费消息
# 循环消费消息
for
message
in
consumer
:
log
.
info
(
f
"Received message: {message.value}"
)
if
message
is
None
:
continue
funasr_service
.
handle_process
(
str
(
message
.
value
.
decode
(
'utf-8'
)))
\ No newline at end of file
\ No newline at end of file
# for message in consumer:
# log.info(f"Received message: {message.value}")
# if message is None:
# continue
# funasr_service.handle_process(str(message.value.decode('utf-8')))
\ No newline at end of file
\ No newline at end of file
log/logger.py
View file @
f38430d
...
@@ -33,4 +33,4 @@ def setup_logging(log_file):
...
@@ -33,4 +33,4 @@ def setup_logging(log_file):
return
logger
return
logger
log
=
setup_logging
(
'D:/software/python/project/funasr_web/log/funasr.log'
)
\ No newline at end of file
\ No newline at end of file
log
=
setup_logging
(
'funasr.log'
)
\ No newline at end of file
\ No newline at end of file
main.py
View file @
f38430d
...
@@ -14,6 +14,8 @@ from fastapi import FastAPI, File, UploadFile
...
@@ -14,6 +14,8 @@ from fastapi import FastAPI, File, UploadFile
from
funasr_service
import
FunasrService
from
funasr_service
import
FunasrService
from
pydantic
import
BaseModel
from
pydantic
import
BaseModel
from
mysql_service
import
funasr_db
from
mysql_service
import
funasr_db
from
kafka_service
import
funasr_consumer
from
config.config
import
ConfigInfo
app
=
FastAPI
()
app
=
FastAPI
()
...
@@ -191,8 +193,14 @@ async def create_url(param: UrlParam):
...
@@ -191,8 +193,14 @@ async def create_url(param: UrlParam):
traceback
.
print_exc
()
traceback
.
print_exc
()
return
{
"error"
:
str
(
e
)}
return
{
"error"
:
str
(
e
)}
def
start_kafka
():
kafka_thread
=
threading
.
Thread
(
target
=
funasr_consumer
.
consume_kafka
)
kafka_thread
.
daemon
=
True
# 将线程设置为守护线程,当主线程结束时,该线程也会自动结束
kafka_thread
.
start
()
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
start_kafka
()
save_path
=
"./audio/"
save_path
=
"./audio/"
if
os
.
path
.
exists
(
save_path
):
if
os
.
path
.
exists
(
save_path
):
shutil
.
rmtree
(
save_path
)
shutil
.
rmtree
(
save_path
)
...
...
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