From 7325f96b67c115c8ea7cee00e7f01303ec7ef9a3 Mon Sep 17 00:00:00 2001 From: Alex Zenla Date: Mon, 1 May 2023 18:05:47 -0700 Subject: [PATCH] Working C++ Sample --- Clients/Cpp/CMakeLists.txt | 4 ++-- Clients/Cpp/StableDiffusion.proto | 1 + Clients/Cpp/sample.cpp | 23 +++++++++++++++++++++++ Clients/Cpp/src/StableDiffusion.proto | 1 - Clients/Cpp/src/sample.cpp | 11 ----------- 5 files changed, 26 insertions(+), 14 deletions(-) create mode 120000 Clients/Cpp/StableDiffusion.proto create mode 100644 Clients/Cpp/sample.cpp delete mode 120000 Clients/Cpp/src/StableDiffusion.proto delete mode 100644 Clients/Cpp/src/sample.cpp diff --git a/Clients/Cpp/CMakeLists.txt b/Clients/Cpp/CMakeLists.txt index a1ec46d..0b5323c 100644 --- a/Clients/Cpp/CMakeLists.txt +++ b/Clients/Cpp/CMakeLists.txt @@ -6,7 +6,7 @@ find_package(gRPC CONFIG REQUIRED) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") -add_library(sdrpc src/StableDiffusion.proto) +add_library(sdrpc StableDiffusion.proto) get_target_property(grpc_cpp_plugin_location gRPC::grpc_cpp_plugin LOCATION) @@ -17,6 +17,6 @@ protobuf_generate(TARGET sdrpc LANGUAGE grpc target_include_directories(sdrpc PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) target_link_libraries(sdrpc PUBLIC protobuf::libprotobuf gRPC::grpc gRPC::grpc++) -add_executable(sdrpc_sample src/sample.cpp) +add_executable(sdrpc_sample sample.cpp) target_include_directories(sdrpc_sample PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) target_link_libraries(sdrpc_sample PRIVATE sdrpc) diff --git a/Clients/Cpp/StableDiffusion.proto b/Clients/Cpp/StableDiffusion.proto new file mode 120000 index 0000000..4cddda6 --- /dev/null +++ b/Clients/Cpp/StableDiffusion.proto @@ -0,0 +1 @@ +../../Common/StableDiffusion.proto \ No newline at end of file diff --git a/Clients/Cpp/sample.cpp b/Clients/Cpp/sample.cpp new file mode 100644 index 0000000..f8bba1a --- /dev/null +++ b/Clients/Cpp/sample.cpp @@ -0,0 +1,23 @@ +#include "StableDiffusion.pb.h" +#include "StableDiffusion.grpc.pb.h" + +#include + +using namespace gay::pizza::stable::diffusion; + +int main() { + auto channel = grpc::CreateChannel("localhost:4546", grpc::InsecureChannelCredentials()); + auto modelService = ModelService::NewStub(channel); + auto imageGenerationService = ImageGenerationService::NewStub(channel); + + grpc::ClientContext context; + + ListModelsRequest listModelsRequest; + ListModelsResponse response; + modelService->ListModels(&context, listModelsRequest, &response); + auto models = response.available_models(); + for (const auto &item: models) { + std::cout << "Model Name: " << item.name() << std::endl; + } + return 0; +} diff --git a/Clients/Cpp/src/StableDiffusion.proto b/Clients/Cpp/src/StableDiffusion.proto deleted file mode 120000 index 2839d83..0000000 --- a/Clients/Cpp/src/StableDiffusion.proto +++ /dev/null @@ -1 +0,0 @@ -../../../Common/StableDiffusion.proto \ No newline at end of file diff --git a/Clients/Cpp/src/sample.cpp b/Clients/Cpp/src/sample.cpp deleted file mode 100644 index b34abd8..0000000 --- a/Clients/Cpp/src/sample.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -using namespace gay::pizza::stable::diffusion; - -int main() { - ModelInfo info; - info.set_name("anything-4.5"); - std::cout << info.DebugString() << std::endl; - return 0; -}