Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
12 changes: 11 additions & 1 deletion examples/server/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions examples/server/frontend
Submodule frontend added at aa8225
14 changes: 12 additions & 2 deletions examples/server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 -----------------------
Expand Down Expand Up @@ -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<const char*>(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);
Expand All @@ -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");
}
});

Expand Down