diff --git a/.gitmodules b/.gitmodules index 5a7851973..5d66c8795 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "ggml"] path = ggml url = https://github.com/ggml-org/ggml.git +[submodule "examples/server/frontend"] + path = examples/server/frontend + url = https://github.com/leejet/stable-ui.git diff --git a/examples/server/CMakeLists.txt b/examples/server/CMakeLists.txt index d19126080..e3f334009 100644 --- a/examples/server/CMakeLists.txt +++ b/examples/server/CMakeLists.txt @@ -1,6 +1,16 @@ set(TARGET sd-server) -add_executable(${TARGET} main.cpp) +set(GENERATED_HTML_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/frontend/dist/gen_index_html.h") + +if(EXISTS ${GENERATED_HTML_HEADER}) + message(STATUS "Found generated header: ${GENERATED_HTML_HEADER}") + add_executable(${TARGET} main.cpp ${GENERATED_HTML_HEADER}) + target_compile_definitions(${TARGET} PRIVATE HAVE_INDEX_HTML) +else() + message(WARNING "Header ${GENERATED_HTML_HEADER} not found. Skipping index_html inclusion.") + add_executable(${TARGET} main.cpp) +endif() + install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE stable-diffusion ${CMAKE_THREAD_LIBS_INIT}) target_compile_features(${TARGET} PUBLIC c_std_11 cxx_std_17) \ No newline at end of file diff --git a/examples/server/frontend b/examples/server/frontend new file mode 160000 index 000000000..aa8225dee --- /dev/null +++ b/examples/server/frontend @@ -0,0 +1 @@ +Subproject commit aa8225dee04af93cac03ddeac9d3128bb158daac diff --git a/examples/server/main.cpp b/examples/server/main.cpp index 76199ac69..2b4965532 100644 --- a/examples/server/main.cpp +++ b/examples/server/main.cpp @@ -13,6 +13,10 @@ #include "common/common.hpp" +#ifdef HAVE_INDEX_HTML +#include "frontend/dist/gen_index_html.h" +#endif + namespace fs = std::filesystem; // ----------------------- helpers ----------------------- @@ -312,7 +316,13 @@ int main(int argc, const char** argv) { return httplib::Server::HandlerResponse::Unhandled; }); - // health + // index html + std::string index_html; +#ifdef HAVE_INDEX_HTML + index_html.assign(reinterpret_cast(index_html_bytes), index_html_size); +#else + index_html = "Stable Diffusion Server is running"; +#endif svr.Get("/", [&](const httplib::Request&, httplib::Response& res) { if (!svr_params.serve_html_path.empty()) { std::ifstream file(svr_params.serve_html_path); @@ -324,7 +334,7 @@ int main(int argc, const char** argv) { res.set_content("Error: Unable to read HTML file", "text/plain"); } } else { - res.set_content("Stable Diffusion Server is running", "text/plain"); + res.set_content(index_html, "text/html"); } });