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
...
@@ -9,16 +9,17 @@ from utils.predic_fac import PredictorFac
from
utils.log_manager
import
get_logger
from
utils.log_manager
import
get_logger
log_server
=
get_logger
(
'server'
)
log_server
=
get_logger
(
'server'
)
class
Classify
(
classify_pb2_grpc
.
classifyServicer
):
class
Classify
(
classify_pb2_grpc
.
classifyServicer
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
()
.
__init__
(
*
args
,
**
kwargs
)
super
()
.
__init__
(
*
args
,
**
kwargs
)
log_server
.
info
(
'classify server start!'
)
log_server
.
info
(
'classify server start!'
)
self
.
predictorfac
=
PredictorFac
(
model_config
)
self
.
predictorfac
=
PredictorFac
(
model_config
)
def
Single
Classify
(
self
,
request
,
context
):
def
Classify
(
self
,
request
,
context
):
log_server
.
debug
(
'接收数据: '
+
request
.
keyword
)
log_server
.
debug
(
'接收数据: '
+
request
.
keyword
)
res
=
self
.
predictorfac
.
predic
(
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
):
def
fac_test_predic
(
self
,
data
):
res
=
self
.
predictorfac
.
predic
(
data
)
res
=
self
.
predictorfac
.
predic
(
data
)
...
...
client/client.py
View file @
d283c820
...
@@ -8,7 +8,7 @@ def run():
...
@@ -8,7 +8,7 @@ def run():
channel
=
grpc
.
insecure_channel
(
'localhost:50051'
)
channel
=
grpc
.
insecure_channel
(
'localhost:50051'
)
# 调用 rpc 服务
# 调用 rpc 服务
stub
=
classify_pb2_grpc
.
classifyStub
(
channel
)
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
)
print
(
"Classify client received: "
+
response
.
message
)
if
__name__
==
'__main__'
:
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 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"
;
syntax
=
"proto3"
;
service
classify
{
service
classify
{
rpc
SingleClassify
(
SingleClassifyRequest
)
returns
(
Single
ClassifyReply
)
{}
rpc
Classify
(
ClassifyRequest
)
returns
(
ClassifyReply
)
{}
}
}
message
Single
ClassifyRequest
{
message
ClassifyRequest
{
string
keyword
=
1
;
string
keyword
=
1
;
}
}
message
Single
ClassifyReply
{
message
ClassifyReply
{
string
message
=
1
;
string
message
=
1
;
}
}
...
...
protobuf/classify_pb2.py
View file @
d283c820
...
@@ -18,21 +18,21 @@ DESCRIPTOR = _descriptor.FileDescriptor(
...
@@ -18,21 +18,21 @@ DESCRIPTOR = _descriptor.FileDescriptor(
package
=
''
,
package
=
''
,
syntax
=
'proto3'
,
syntax
=
'proto3'
,
serialized_options
=
None
,
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
(
_CLASSIFYREQUEST
=
_descriptor
.
Descriptor
(
name
=
'
Single
ClassifyRequest'
,
name
=
'ClassifyRequest'
,
full_name
=
'
Single
ClassifyRequest'
,
full_name
=
'ClassifyRequest'
,
filename
=
None
,
filename
=
None
,
file
=
DESCRIPTOR
,
file
=
DESCRIPTOR
,
containing_type
=
None
,
containing_type
=
None
,
fields
=
[
fields
=
[
_descriptor
.
FieldDescriptor
(
_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
,
number
=
1
,
type
=
9
,
cpp_type
=
9
,
label
=
1
,
has_default_value
=
False
,
default_value
=
b
""
.
decode
(
'utf-8'
),
has_default_value
=
False
,
default_value
=
b
""
.
decode
(
'utf-8'
),
message_type
=
None
,
enum_type
=
None
,
containing_type
=
None
,
message_type
=
None
,
enum_type
=
None
,
containing_type
=
None
,
...
@@ -51,19 +51,19 @@ _SINGLECLASSIFYREQUEST = _descriptor.Descriptor(
...
@@ -51,19 +51,19 @@ _SINGLECLASSIFYREQUEST = _descriptor.Descriptor(
oneofs
=
[
oneofs
=
[
],
],
serialized_start
=
18
,
serialized_start
=
18
,
serialized_end
=
5
8
,
serialized_end
=
5
2
,
)
)
_
SINGLE
CLASSIFYREPLY
=
_descriptor
.
Descriptor
(
_CLASSIFYREPLY
=
_descriptor
.
Descriptor
(
name
=
'
Single
ClassifyReply'
,
name
=
'ClassifyReply'
,
full_name
=
'
Single
ClassifyReply'
,
full_name
=
'ClassifyReply'
,
filename
=
None
,
filename
=
None
,
file
=
DESCRIPTOR
,
file
=
DESCRIPTOR
,
containing_type
=
None
,
containing_type
=
None
,
fields
=
[
fields
=
[
_descriptor
.
FieldDescriptor
(
_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
,
number
=
1
,
type
=
9
,
cpp_type
=
9
,
label
=
1
,
has_default_value
=
False
,
default_value
=
b
""
.
decode
(
'utf-8'
),
has_default_value
=
False
,
default_value
=
b
""
.
decode
(
'utf-8'
),
message_type
=
None
,
enum_type
=
None
,
containing_type
=
None
,
message_type
=
None
,
enum_type
=
None
,
containing_type
=
None
,
...
@@ -81,27 +81,27 @@ _SINGLECLASSIFYREPLY = _descriptor.Descriptor(
...
@@ -81,27 +81,27 @@ _SINGLECLASSIFYREPLY = _descriptor.Descriptor(
extension_ranges
=
[],
extension_ranges
=
[],
oneofs
=
[
oneofs
=
[
],
],
serialized_start
=
60
,
serialized_start
=
54
,
serialized_end
=
98
,
serialized_end
=
86
,
)
)
DESCRIPTOR
.
message_types_by_name
[
'
SingleClassifyRequest'
]
=
_SINGLE
CLASSIFYREQUEST
DESCRIPTOR
.
message_types_by_name
[
'
ClassifyRequest'
]
=
_
CLASSIFYREQUEST
DESCRIPTOR
.
message_types_by_name
[
'
SingleClassifyReply'
]
=
_SINGLE
CLASSIFYREPLY
DESCRIPTOR
.
message_types_by_name
[
'
ClassifyReply'
]
=
_
CLASSIFYREPLY
_sym_db
.
RegisterFileDescriptor
(
DESCRIPTOR
)
_sym_db
.
RegisterFileDescriptor
(
DESCRIPTOR
)
SingleClassifyRequest
=
_reflection
.
GeneratedProtocolMessageType
(
'Single
ClassifyRequest'
,
(
_message
.
Message
,),
{
ClassifyRequest
=
_reflection
.
GeneratedProtocolMessageType
(
'
ClassifyRequest'
,
(
_message
.
Message
,),
{
'DESCRIPTOR'
:
_
SINGLE
CLASSIFYREQUEST
,
'DESCRIPTOR'
:
_CLASSIFYREQUEST
,
'__module__'
:
'classify_pb2'
'__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
,),
{
ClassifyReply
=
_reflection
.
GeneratedProtocolMessageType
(
'
ClassifyReply'
,
(
_message
.
Message
,),
{
'DESCRIPTOR'
:
_
SINGLE
CLASSIFYREPLY
,
'DESCRIPTOR'
:
_CLASSIFYREPLY
,
'__module__'
:
'classify_pb2'
'__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(
...
@@ -111,16 +111,16 @@ _CLASSIFY = _descriptor.ServiceDescriptor(
file
=
DESCRIPTOR
,
file
=
DESCRIPTOR
,
index
=
0
,
index
=
0
,
serialized_options
=
None
,
serialized_options
=
None
,
serialized_start
=
100
,
serialized_start
=
88
,
serialized_end
=
1
7
6
,
serialized_end
=
1
4
6
,
methods
=
[
methods
=
[
_descriptor
.
MethodDescriptor
(
_descriptor
.
MethodDescriptor
(
name
=
'
Single
Classify'
,
name
=
'Classify'
,
full_name
=
'classify.
Single
Classify'
,
full_name
=
'classify.Classify'
,
index
=
0
,
index
=
0
,
containing_service
=
None
,
containing_service
=
None
,
input_type
=
_
SINGLE
CLASSIFYREQUEST
,
input_type
=
_CLASSIFYREQUEST
,
output_type
=
_
SINGLE
CLASSIFYREPLY
,
output_type
=
_CLASSIFYREPLY
,
serialized_options
=
None
,
serialized_options
=
None
,
),
),
])
])
...
...
protobuf/classify_pb2_grpc.py
View file @
d283c820
...
@@ -13,17 +13,17 @@ class classifyStub(object):
...
@@ -13,17 +13,17 @@ class classifyStub(object):
Args:
Args:
channel: A grpc.Channel.
channel: A grpc.Channel.
"""
"""
self
.
Single
Classify
=
channel
.
unary_unary
(
self
.
Classify
=
channel
.
unary_unary
(
'/classify/
Single
Classify'
,
'/classify/Classify'
,
request_serializer
=
classify__pb2
.
Single
ClassifyRequest
.
SerializeToString
,
request_serializer
=
classify__pb2
.
ClassifyRequest
.
SerializeToString
,
response_deserializer
=
classify__pb2
.
Single
ClassifyReply
.
FromString
,
response_deserializer
=
classify__pb2
.
ClassifyReply
.
FromString
,
)
)
class
classifyServicer
(
object
):
class
classifyServicer
(
object
):
"""Missing associated documentation comment in .proto file"""
"""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"""
"""Missing associated documentation comment in .proto file"""
context
.
set_code
(
grpc
.
StatusCode
.
UNIMPLEMENTED
)
context
.
set_code
(
grpc
.
StatusCode
.
UNIMPLEMENTED
)
context
.
set_details
(
'Method not implemented!'
)
context
.
set_details
(
'Method not implemented!'
)
...
@@ -32,10 +32,10 @@ class classifyServicer(object):
...
@@ -32,10 +32,10 @@ class classifyServicer(object):
def
add_classifyServicer_to_server
(
servicer
,
server
):
def
add_classifyServicer_to_server
(
servicer
,
server
):
rpc_method_handlers
=
{
rpc_method_handlers
=
{
'
Single
Classify'
:
grpc
.
unary_unary_rpc_method_handler
(
'Classify'
:
grpc
.
unary_unary_rpc_method_handler
(
servicer
.
Single
Classify
,
servicer
.
Classify
,
request_deserializer
=
classify__pb2
.
Single
ClassifyRequest
.
FromString
,
request_deserializer
=
classify__pb2
.
ClassifyRequest
.
FromString
,
response_serializer
=
classify__pb2
.
Single
ClassifyReply
.
SerializeToString
,
response_serializer
=
classify__pb2
.
ClassifyReply
.
SerializeToString
,
),
),
}
}
generic_handler
=
grpc
.
method_handlers_generic_handler
(
generic_handler
=
grpc
.
method_handlers_generic_handler
(
...
@@ -48,7 +48,7 @@ class classify(object):
...
@@ -48,7 +48,7 @@ class classify(object):
"""Missing associated documentation comment in .proto file"""
"""Missing associated documentation comment in .proto file"""
@staticmethod
@staticmethod
def
Single
Classify
(
request
,
def
Classify
(
request
,
target
,
target
,
options
=
(),
options
=
(),
channel_credentials
=
None
,
channel_credentials
=
None
,
...
@@ -57,8 +57,8 @@ class classify(object):
...
@@ -57,8 +57,8 @@ class classify(object):
wait_for_ready
=
None
,
wait_for_ready
=
None
,
timeout
=
None
,
timeout
=
None
,
metadata
=
None
):
metadata
=
None
):
return
grpc
.
experimental
.
unary_unary
(
request
,
target
,
'/classify/
Single
Classify'
,
return
grpc
.
experimental
.
unary_unary
(
request
,
target
,
'/classify/Classify'
,
classify__pb2
.
Single
ClassifyRequest
.
SerializeToString
,
classify__pb2
.
ClassifyRequest
.
SerializeToString
,
classify__pb2
.
Single
ClassifyReply
.
FromString
,
classify__pb2
.
ClassifyReply
.
FromString
,
options
,
channel_credentials
,
options
,
channel_credentials
,
call_credentials
,
compression
,
wait_for_ready
,
timeout
,
metadata
)
call_credentials
,
compression
,
wait_for_ready
,
timeout
,
metadata
)
utils/predic_fac.py
View file @
d283c820
...
@@ -22,3 +22,5 @@ class PredictorFac():
...
@@ -22,3 +22,5 @@ class PredictorFac():
predictor
=
self
.
_get_predictor
(
data
)
predictor
=
self
.
_get_predictor
(
data
)
res
=
predictor
.
predict
(
data
)
res
=
predictor
.
predict
(
data
)
return
res
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