Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lichenggang
/
bom_identify
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d283c820
authored
May 27, 2020
by
lzzzzl
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
修改proto
parent
9045bdce
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
51 additions
and
48 deletions
classify_server.py
client/client.py
protobuf/__pycache__/classify_pb2.cpython-36.pyc
protobuf/__pycache__/classify_pb2_grpc.cpython-36.pyc
protobuf/classify.proto
protobuf/classify_pb2.py
protobuf/classify_pb2_grpc.py
utils/predic_fac.py
classify_server.py
View file @
d283c820
...
...
@@ -9,16 +9,17 @@ from utils.predic_fac import PredictorFac
from
utils.log_manager
import
get_logger
log_server
=
get_logger
(
'server'
)
class
Classify
(
classify_pb2_grpc
.
classifyServicer
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
()
.
__init__
(
*
args
,
**
kwargs
)
log_server
.
info
(
'classify server start!'
)
self
.
predictorfac
=
PredictorFac
(
model_config
)
def
Single
Classify
(
self
,
request
,
context
):
def
Classify
(
self
,
request
,
context
):
log_server
.
debug
(
'接收数据: '
+
request
.
keyword
)
res
=
self
.
predictorfac
.
predic
(
request
.
keyword
)
return
classify_pb2
.
Single
ClassifyReply
(
message
=
'result {msg}'
.
format
(
msg
=
res
))
return
classify_pb2
.
ClassifyReply
(
message
=
'result {msg}'
.
format
(
msg
=
res
))
def
fac_test_predic
(
self
,
data
):
res
=
self
.
predictorfac
.
predic
(
data
)
...
...
client/client.py
View file @
d283c820
...
...
@@ -8,7 +8,7 @@ def run():
channel
=
grpc
.
insecure_channel
(
'localhost:50051'
)
# 调用 rpc 服务
stub
=
classify_pb2_grpc
.
classifyStub
(
channel
)
response
=
stub
.
SingleClassify
(
classify_pb2
.
Single
ClassifyRequest
(
keyword
=
'czl'
))
response
=
stub
.
Classify
(
classify_pb2
.
ClassifyRequest
(
keyword
=
'czl'
))
print
(
"Classify client received: "
+
response
.
message
)
if
__name__
==
'__main__'
:
...
...
protobuf/__pycache__/classify_pb2.cpython-36.pyc
View file @
d283c820
No preview for this file type
protobuf/__pycache__/classify_pb2_grpc.cpython-36.pyc
View file @
d283c820
No preview for this file type
protobuf/classify.proto
View file @
d283c820
// [python quickstart](https://grpc.io/docs/quickstart/python.html#run-a-grpc-application)
// python -m grpc_tools.protoc --python_out=. --grpc_python_out=. -I.
helloworld
.proto
// python -m grpc_tools.protoc --python_out=. --grpc_python_out=. -I.
classify
.proto
// 选择类型
syntax
=
"proto3"
;
service
classify
{
rpc
SingleClassify
(
SingleClassifyRequest
)
returns
(
Single
ClassifyReply
)
{}
rpc
Classify
(
ClassifyRequest
)
returns
(
ClassifyReply
)
{}
}
message
Single
ClassifyRequest
{
message
ClassifyRequest
{
string
keyword
=
1
;
}
message
Single
ClassifyReply
{
message
ClassifyReply
{
string
message
=
1
;
}
...
...
protobuf/classify_pb2.py
View file @
d283c820
...
...
@@ -18,21 +18,21 @@ DESCRIPTOR = _descriptor.FileDescriptor(
package
=
''
,
syntax
=
'proto3'
,
serialized_options
=
None
,
serialized_pb
=
b
'
\n\x0e\x63
lassify.proto
\"
(
\n\x15
SingleClassifyRequest
\x12\x0f\n\x07
keyword
\x18\x01
\x01
(
\t\"
&
\n\x13
SingleClassifyReply
\x12\x0f\n\x07
message
\x18\x01
\x01
(
\t
2L
\n\x08\x63
lassify
\x12
@
\n\x0e
SingleClassify
\x12\x16
.SingleClassifyRequest
\x1a\x14
.Single
ClassifyReply
\"\x00\x62\x06
proto3'
serialized_pb
=
b
'
\n\x0e\x63
lassify.proto
\"
\"\n\x0f\x43
lassifyRequest
\x12\x0f\n\x07
keyword
\x18\x01
\x01
(
\t\"
\n\r
ClassifyReply
\x12\x0f\n\x07
message
\x18\x01
\x01
(
\t
2:
\n\x08\x63
lassify
\x12
.
\n\x08\x43
lassify
\x12\x10
.ClassifyRequest
\x1a\x0e
.
ClassifyReply
\"\x00\x62\x06
proto3'
)
_
SINGLE
CLASSIFYREQUEST
=
_descriptor
.
Descriptor
(
name
=
'
Single
ClassifyRequest'
,
full_name
=
'
Single
ClassifyRequest'
,
_CLASSIFYREQUEST
=
_descriptor
.
Descriptor
(
name
=
'ClassifyRequest'
,
full_name
=
'ClassifyRequest'
,
filename
=
None
,
file
=
DESCRIPTOR
,
containing_type
=
None
,
fields
=
[
_descriptor
.
FieldDescriptor
(
name
=
'keyword'
,
full_name
=
'
Single
ClassifyRequest.keyword'
,
index
=
0
,
name
=
'keyword'
,
full_name
=
'ClassifyRequest.keyword'
,
index
=
0
,
number
=
1
,
type
=
9
,
cpp_type
=
9
,
label
=
1
,
has_default_value
=
False
,
default_value
=
b
""
.
decode
(
'utf-8'
),
message_type
=
None
,
enum_type
=
None
,
containing_type
=
None
,
...
...
@@ -51,19 +51,19 @@ _SINGLECLASSIFYREQUEST = _descriptor.Descriptor(
oneofs
=
[
],
serialized_start
=
18
,
serialized_end
=
5
8
,
serialized_end
=
5
2
,
)
_
SINGLE
CLASSIFYREPLY
=
_descriptor
.
Descriptor
(
name
=
'
Single
ClassifyReply'
,
full_name
=
'
Single
ClassifyReply'
,
_CLASSIFYREPLY
=
_descriptor
.
Descriptor
(
name
=
'ClassifyReply'
,
full_name
=
'ClassifyReply'
,
filename
=
None
,
file
=
DESCRIPTOR
,
containing_type
=
None
,
fields
=
[
_descriptor
.
FieldDescriptor
(
name
=
'message'
,
full_name
=
'
Single
ClassifyReply.message'
,
index
=
0
,
name
=
'message'
,
full_name
=
'ClassifyReply.message'
,
index
=
0
,
number
=
1
,
type
=
9
,
cpp_type
=
9
,
label
=
1
,
has_default_value
=
False
,
default_value
=
b
""
.
decode
(
'utf-8'
),
message_type
=
None
,
enum_type
=
None
,
containing_type
=
None
,
...
...
@@ -81,27 +81,27 @@ _SINGLECLASSIFYREPLY = _descriptor.Descriptor(
extension_ranges
=
[],
oneofs
=
[
],
serialized_start
=
60
,
serialized_end
=
98
,
serialized_start
=
54
,
serialized_end
=
86
,
)
DESCRIPTOR
.
message_types_by_name
[
'
SingleClassifyRequest'
]
=
_SINGLE
CLASSIFYREQUEST
DESCRIPTOR
.
message_types_by_name
[
'
SingleClassifyReply'
]
=
_SINGLE
CLASSIFYREPLY
DESCRIPTOR
.
message_types_by_name
[
'
ClassifyRequest'
]
=
_
CLASSIFYREQUEST
DESCRIPTOR
.
message_types_by_name
[
'
ClassifyReply'
]
=
_
CLASSIFYREPLY
_sym_db
.
RegisterFileDescriptor
(
DESCRIPTOR
)
SingleClassifyRequest
=
_reflection
.
GeneratedProtocolMessageType
(
'Single
ClassifyRequest'
,
(
_message
.
Message
,),
{
'DESCRIPTOR'
:
_
SINGLE
CLASSIFYREQUEST
,
ClassifyRequest
=
_reflection
.
GeneratedProtocolMessageType
(
'
ClassifyRequest'
,
(
_message
.
Message
,),
{
'DESCRIPTOR'
:
_CLASSIFYREQUEST
,
'__module__'
:
'classify_pb2'
# @@protoc_insertion_point(class_scope:
Single
ClassifyRequest)
# @@protoc_insertion_point(class_scope:ClassifyRequest)
})
_sym_db
.
RegisterMessage
(
Single
ClassifyRequest
)
_sym_db
.
RegisterMessage
(
ClassifyRequest
)
SingleClassifyReply
=
_reflection
.
GeneratedProtocolMessageType
(
'Single
ClassifyReply'
,
(
_message
.
Message
,),
{
'DESCRIPTOR'
:
_
SINGLE
CLASSIFYREPLY
,
ClassifyReply
=
_reflection
.
GeneratedProtocolMessageType
(
'
ClassifyReply'
,
(
_message
.
Message
,),
{
'DESCRIPTOR'
:
_CLASSIFYREPLY
,
'__module__'
:
'classify_pb2'
# @@protoc_insertion_point(class_scope:
Single
ClassifyReply)
# @@protoc_insertion_point(class_scope:ClassifyReply)
})
_sym_db
.
RegisterMessage
(
Single
ClassifyReply
)
_sym_db
.
RegisterMessage
(
ClassifyReply
)
...
...
@@ -111,16 +111,16 @@ _CLASSIFY = _descriptor.ServiceDescriptor(
file
=
DESCRIPTOR
,
index
=
0
,
serialized_options
=
None
,
serialized_start
=
100
,
serialized_end
=
1
7
6
,
serialized_start
=
88
,
serialized_end
=
1
4
6
,
methods
=
[
_descriptor
.
MethodDescriptor
(
name
=
'
Single
Classify'
,
full_name
=
'classify.
Single
Classify'
,
name
=
'Classify'
,
full_name
=
'classify.Classify'
,
index
=
0
,
containing_service
=
None
,
input_type
=
_
SINGLE
CLASSIFYREQUEST
,
output_type
=
_
SINGLE
CLASSIFYREPLY
,
input_type
=
_CLASSIFYREQUEST
,
output_type
=
_CLASSIFYREPLY
,
serialized_options
=
None
,
),
])
...
...
protobuf/classify_pb2_grpc.py
View file @
d283c820
...
...
@@ -13,17 +13,17 @@ class classifyStub(object):
Args:
channel: A grpc.Channel.
"""
self
.
Single
Classify
=
channel
.
unary_unary
(
'/classify/
Single
Classify'
,
request_serializer
=
classify__pb2
.
Single
ClassifyRequest
.
SerializeToString
,
response_deserializer
=
classify__pb2
.
Single
ClassifyReply
.
FromString
,
self
.
Classify
=
channel
.
unary_unary
(
'/classify/Classify'
,
request_serializer
=
classify__pb2
.
ClassifyRequest
.
SerializeToString
,
response_deserializer
=
classify__pb2
.
ClassifyReply
.
FromString
,
)
class
classifyServicer
(
object
):
"""Missing associated documentation comment in .proto file"""
def
Single
Classify
(
self
,
request
,
context
):
def
Classify
(
self
,
request
,
context
):
"""Missing associated documentation comment in .proto file"""
context
.
set_code
(
grpc
.
StatusCode
.
UNIMPLEMENTED
)
context
.
set_details
(
'Method not implemented!'
)
...
...
@@ -32,10 +32,10 @@ class classifyServicer(object):
def
add_classifyServicer_to_server
(
servicer
,
server
):
rpc_method_handlers
=
{
'
Single
Classify'
:
grpc
.
unary_unary_rpc_method_handler
(
servicer
.
Single
Classify
,
request_deserializer
=
classify__pb2
.
Single
ClassifyRequest
.
FromString
,
response_serializer
=
classify__pb2
.
Single
ClassifyReply
.
SerializeToString
,
'Classify'
:
grpc
.
unary_unary_rpc_method_handler
(
servicer
.
Classify
,
request_deserializer
=
classify__pb2
.
ClassifyRequest
.
FromString
,
response_serializer
=
classify__pb2
.
ClassifyReply
.
SerializeToString
,
),
}
generic_handler
=
grpc
.
method_handlers_generic_handler
(
...
...
@@ -48,7 +48,7 @@ class classify(object):
"""Missing associated documentation comment in .proto file"""
@staticmethod
def
Single
Classify
(
request
,
def
Classify
(
request
,
target
,
options
=
(),
channel_credentials
=
None
,
...
...
@@ -57,8 +57,8 @@ class classify(object):
wait_for_ready
=
None
,
timeout
=
None
,
metadata
=
None
):
return
grpc
.
experimental
.
unary_unary
(
request
,
target
,
'/classify/
Single
Classify'
,
classify__pb2
.
Single
ClassifyRequest
.
SerializeToString
,
classify__pb2
.
Single
ClassifyReply
.
FromString
,
return
grpc
.
experimental
.
unary_unary
(
request
,
target
,
'/classify/Classify'
,
classify__pb2
.
ClassifyRequest
.
SerializeToString
,
classify__pb2
.
ClassifyReply
.
FromString
,
options
,
channel_credentials
,
call_credentials
,
compression
,
wait_for_ready
,
timeout
,
metadata
)
utils/predic_fac.py
View file @
d283c820
...
...
@@ -22,3 +22,5 @@ class PredictorFac():
predictor
=
self
.
_get_predictor
(
data
)
res
=
predictor
.
predict
(
data
)
return
res
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment