mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-02-04 10:53:34 +00:00
Add embedded WebUI
This commit is contained in:
parent
2efd19978d
commit
366b3de936
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -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
|
||||
|
||||
@ -1,6 +1,16 @@
|
||||
set(TARGET sd-server)
|
||||
|
||||
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
examples/server/frontend
Submodule
1
examples/server/frontend
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit aa8225dee04af93cac03ddeac9d3128bb158daac
|
||||
@ -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<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);
|
||||
@ -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");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user