55#include < string>
66#include < unordered_map>
77#include < vector>
8+ #include < filesystem>
89
910#include " model.h"
1011#include " stable-diffusion.h"
@@ -907,7 +908,12 @@ bool is_zip_file(const std::string& file_path) {
907908}
908909
909910bool is_gguf_file (const std::string& file_path) {
910- std::ifstream file (file_path, std::ios::binary);
911+ #ifdef _WIN32
912+ std::filesystem::path fpath = std::filesystem::u8path (file_path);
913+ #else
914+ std::filesystem::path fpath = std::filesystem::path (file_path);
915+ #endif
916+ std::ifstream file (fpath, std::ios::binary);
911917 if (!file.is_open ()) {
912918 return false ;
913919 }
@@ -928,7 +934,12 @@ bool is_gguf_file(const std::string& file_path) {
928934}
929935
930936bool is_safetensors_file (const std::string& file_path) {
931- std::ifstream file (file_path, std::ios::binary);
937+ #ifdef _WIN32
938+ std::filesystem::path fpath = std::filesystem::u8path (file_path);
939+ #else
940+ std::filesystem::path fpath = std::filesystem::path (file_path);
941+ #endif
942+ std::ifstream file (fpath, std::ios::binary);
932943 if (!file.is_open ()) {
933944 return false ;
934945 }
@@ -1052,7 +1063,12 @@ bool ModelLoader::init_from_safetensors_file(const std::string& file_path, const
10521063 LOG_DEBUG (" init from '%s'" , file_path.c_str ());
10531064 file_paths_.push_back (file_path);
10541065 size_t file_index = file_paths_.size () - 1 ;
1055- std::ifstream file (file_path, std::ios::binary);
1066+ #ifdef _WIN32
1067+ std::filesystem::path fpath = std::filesystem::u8path (file_path);
1068+ #else
1069+ std::filesystem::path fpath = std::filesystem::path (file_path);
1070+ #endif
1071+ std::ifstream file (fpath, std::ios::binary);
10561072 if (!file.is_open ()) {
10571073 LOG_ERROR (" failed to open '%s'" , file_path.c_str ());
10581074 return false ;
@@ -1809,7 +1825,12 @@ bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb, ggml_backend
18091825 std::string file_path = file_paths_[file_index];
18101826 LOG_DEBUG (" loading tensors from %s\n " , file_path.c_str ());
18111827
1812- std::ifstream file (file_path, std::ios::binary);
1828+ #ifdef _WIN32
1829+ std::filesystem::path fpath = std::filesystem::u8path (file_path);
1830+ #else
1831+ std::filesystem::path fpath = std::filesystem::path (file_path);
1832+ #endif
1833+ std::ifstream file (fpath, std::ios::binary);
18131834 if (!file.is_open ()) {
18141835 LOG_ERROR (" failed to open '%s'" , file_path.c_str ());
18151836 return false ;
0 commit comments