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 3553fb41
authored
Mar 20, 2024
by
‘chizw’
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
日志路径优化
1 parent
5ed92549
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
4 deletions
kafka_service/test03.py
log/logger.py
main.py
kafka_service/test03.py
View file @
3553fb4
import
json
import
os
from
kafka
import
KafkaProducer
# 创建Kafka生产者
...
...
@@ -10,10 +10,17 @@ topic = "ocr_topic" # Kafka主题名称
key
=
b
"my-key"
# 消息的键(可选)
data
=
{
'orderId'
:
1234
,
'fileId'
:
31
,
'filePath'
:
'https://bhg.didihu.com.cn/group1/M00/22/05/wKgFDWWnocCAZllpAADp9tDJibY696.jpg'
,
'sns'
:
'96312110851'
,
'vin'
:
'VIN654321'
,
'fileType'
:
1
}
message
=
json
.
dumps
(
data
)
.
encode
(
'utf-8'
)
producer
.
send
(
topic
,
message
)
#
producer.send(topic,message)
# 等待所有消息发送完成
producer
.
flush
()
# 关闭生产者
producer
.
close
()
# 获取当前文件所在目录的绝对路径
current_dir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
print
(
f
"current_dir:{current_dir}"
)
# 将根目录添加到 Python 解释器的搜索路径中
root_dir
=
os
.
path
.
join
(
current_dir
,
'..'
)
# 假设根目录是当前目录的父目录
print
(
f
"root_dir:{root_dir}"
)
log/logger.py
View file @
3553fb4
...
...
@@ -3,6 +3,11 @@ import os
import
sys
from
logging.handlers
import
TimedRotatingFileHandler
# 获取当前文件所在目录的绝对路径
current_dir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
# 将根目录添加到 Python 解释器的搜索路径中
root_dir
=
os
.
path
.
join
(
current_dir
,
'..'
)
# 假设根目录是当前目录的父目录
sys
.
path
.
append
(
root_dir
)
def
setup_logging
(
log_file
):
"""
...
...
main.py
View file @
3553fb4
...
...
@@ -18,6 +18,7 @@ from kafka_service import funasr_consumer
app
=
FastAPI
()
class
BaseResponse
(
BaseModel
):
code
:
int
=
pydantic
.
Field
(
200
,
description
=
"HTTP status code"
)
msg
:
str
=
pydantic
.
Field
(
"success"
,
description
=
"HTTP status message"
)
...
...
@@ -173,10 +174,17 @@ class UrlParam(BaseModel):
@app.post
(
"/funasr/url/"
)
async
def
create_url
(
param
:
UrlParam
):
try
:
log
.
info
(
f
"funasr create_url api param:{param}"
)
task_id
=
str
(
uuid
.
uuid1
())
url
=
param
.
url
funasr_db
.
insert_ali_asr_model_res
(
task_id
,
url
)
funasr_producer
.
send_message_analysis
({
"task_id"
:
task_id
})
res
=
funasr_db
.
insert_ali_asr_model_res
(
task_id
,
url
)
if
res
is
None
or
(
isinstance
(
res
,
bool
)
and
res
is
False
):
return
BaseResponse
(
code
=-
1
,
msg
=
"error"
,
data
=
"数据库异常"
)
funasr_producer
.
send_message_analysis
({
"task_id"
:
task_id
})
# process = multiprocessing.Process(target=funasr_service.deal_worker, args=(url, task_id,))
# log.info(f"process:{process}")
# process.start()
...
...
@@ -192,6 +200,7 @@ async def create_url(param: UrlParam):
traceback
.
print_exc
()
return
{
"error"
:
str
(
e
)}
def
start_kafka
():
kafka_thread
=
threading
.
Thread
(
target
=
funasr_consumer
.
consume_kafka
)
kafka_thread
.
daemon
=
True
# 将线程设置为守护线程,当主线程结束时,该线程也会自动结束
...
...
@@ -199,6 +208,7 @@ def start_kafka():
if
__name__
==
"__main__"
:
log
.
info
(
"funasr main starting..."
)
start_kafka
()
funasr_producer
.
send_wait_task
()
save_path
=
"./audio/"
...
...
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