Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F5021495
http_server.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
http_server.py
View Options
# -*- coding: UTF-8 -*-
"""
SVC处理逻辑
1. 根据跟定的vocal_url 判别男女
2. 根据男女信息选择适合的男女url
3. 模型推理
"""
import
gc
import
os
import
sys
sys
.
path
.
append
(
os
.
path
.
dirname
(
__file__
))
sys
.
path
.
append
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"../"
))
import
json
import
time
import
socket
import
logging
import
hashlib
from
flask
import
Flask
,
jsonify
,
request
,
abort
from
redis_helper
import
RedisHelper
from
feishu_helper
import
feishu_send
from
common
import
*
# 全局设置
logging
.
basicConfig
(
format
=
'
%(asctime)s
%(levelname)s
%(message)s
'
,
datefmt
=
'%Y-%m-
%d
%I:%M:%S'
,
level
=
logging
.
INFO
)
app
=
Flask
(
__name__
)
class
HttpServer
:
def
__init__
(
self
,
redis_conf
,
server_conf
):
st
=
time
.
time
()
self
.
redis_helper
=
RedisHelper
(
redis_conf
)
self
.
server_conf
=
server_conf
self
.
last_send_time
=
time
.
time
()
self
.
time_interval
=
60
logging
.
info
(
f
"HttpServer init conf={redis_conf}, {server_conf} sp={time.time() - st}"
)
def
process
(
self
,
in_data
):
msg
=
{
"status"
:
gs_err_code_params
,
"schedule"
:
100
,
"gender"
:
"unknown"
,
"target_song_url"
:
""
,
}
if
not
check_input
(
in_data
):
return
msg
num
=
self
.
redis_helper
.
llen
(
self
.
server_conf
[
"producer"
])
if
num
>
10
:
msg
[
"status"
]
=
gs_err_code_too_many_connections
if
time
.
time
()
-
self
.
last_send_time
>
60
:
err_msg
=
f
"ai meisheng process_async too many connections:{num}"
self
.
last_send_time
=
time
.
time
()
feishu_send
(
gs_feishu_conf
[
"url"
],
err_msg
,
gs_feishu_conf
[
"users"
])
return
msg
distinct_id
=
hashlib
.
md5
(
in_data
[
"record_song_url"
]
.
encode
())
.
hexdigest
()
distinct_key
=
self
.
server_conf
[
"ai_meisheng_key_prefix"
]
+
distinct_id
if
not
self
.
redis_helper
.
exists
(
distinct_key
):
msg
[
"status"
]
=
gs_err_code_pending
self
.
redis_helper
.
set
(
distinct_key
,
json
.
dumps
(
msg
))
self
.
redis_helper
.
lpush
(
self
.
server_conf
[
"producer"
],
json
.
dumps
(
in_data
))
self
.
redis_helper
.
expire
(
distinct_key
,
15
)
msg
=
self
.
redis_helper
.
get
(
distinct_key
)
return
json
.
loads
(
msg
)
gs_http_server
=
HttpServer
(
gs_redis_conf
,
gs_server_redis_conf
)
@app.route
(
"/ai_meisheng"
,
methods
=
[
"POST"
])
def
ai_meisheng
():
data
=
request
.
json
st
=
time
.
time
()
logging
.
info
(
f
"ai_meisheng:in:{data}"
)
msg
=
gs_http_server
.
process
(
data
)
json_msg
=
jsonify
(
msg
)
logging
.
info
(
f
"ai_meisheng:out:{data}-{msg}, sp={time.time() - st}"
)
return
json_msg
if
__name__
==
"__main__"
:
app
.
run
(
host
=
'0.0.0.0'
,
port
=
5000
,
threaded
=
False
)
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Mon, May 19, 07:52 (1 d, 6 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1433536
Default Alt Text
http_server.py (2 KB)
Attached To
R350 av_svc
Event Timeline
Log In to Comment