Skip to content

Commit

Permalink
fix ci error
Browse files Browse the repository at this point in the history
  • Loading branch information
leejet committed Mar 3, 2024
1 parent 41f20e6 commit 27887b6
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 71 deletions.
4 changes: 2 additions & 2 deletions clip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ class CLIPTokenizer {

auto it = encoder.find(utf8_to_utf32("img</w>"));
if (it != encoder.end()) {
printf(" trigger word img already in vocab \n");
LOG_DEBUG(" trigger word img already in vocab \n");
}else{
printf(" trigger word img not in vocab yet\n");
LOG_DEBUG(" trigger word img not in vocab yet\n");
}

int rank = 0;
Expand Down
75 changes: 72 additions & 3 deletions examples/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,75 @@
#define STB_IMAGE_WRITE_STATIC
#include "stb_image_write.h"

#ifdef _WIN32 // code for windows
#include <windows.h>
std::vector<std::string> get_files_from_dir(const std::string& dir) {

std::vector<std::string> files;

WIN32_FIND_DATA findFileData;
HANDLE hFind;

char currentDirectory[MAX_PATH];
GetCurrentDirectory(MAX_PATH, currentDirectory);

char directoryPath[MAX_PATH]; // this is absolute path
sprintf(directoryPath, "%s\\%s\\*", currentDirectory, dir.c_str());

// Find the first file in the directory
hFind = FindFirstFile(directoryPath, &findFileData);

// Check if the directory was found
if (hFind == INVALID_HANDLE_VALUE) {
printf("Unable to find directory %s.\n", dir.c_str());
return files;
}

// Loop through all files in the directory
do {
// Check if the found file is a regular file (not a directory)
if (!(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
files.push_back(std::string(currentDirectory) + "\\" + dir + "\\" + std::string(findFileData.cFileName));
}
} while (FindNextFile(hFind, &findFileData) != 0);

// Close the handle
FindClose(hFind);


sort(files.begin(), files.end());

return files;
}
#else // UNIX
#include <dirent.h>
#include <sys/stat.h>

std::vector<std::string> get_files_from_dir(const std::string &dir){

std::vector<std::string> files;

DIR* dp = opendir(dir.c_str());

if (dp != nullptr) {
struct dirent* entry;

while ((entry = readdir(dp)) != nullptr) {
std::string fname = dir + "/" + entry->d_name;
if (!is_directory(fname))
files.push_back(fname);
}
closedir(dp);
}

sort(files.begin(), files.end());

return files;

}

#endif

const char* rng_type_to_str[] = {
"std_default",
"cuda",
Expand Down Expand Up @@ -699,10 +768,10 @@ int main(int argc, const char* argv[]) {
int width, height;
input_image_buffer = stbi_load(img_file.c_str(), &width, &height, &c, 3);
if (input_image_buffer == NULL) {
LOG_ERROR("PhotoMaker load image from '%s' failed", img_file.c_str());
printf("PhotoMaker load image from '%s' failed\n", img_file.c_str());
return 1;
}else{
LOG_INFO("PhotoMaker loaded image from '%s'", img_file.c_str());
printf("PhotoMaker loaded image from '%s'\n", img_file.c_str());
}
sd_image_t* input_image = NULL;
input_image = new sd_image_t{(uint32_t)width,
Expand All @@ -711,7 +780,7 @@ int main(int argc, const char* argv[]) {
input_image_buffer};
input_image = preprocess_id_image(input_image);
if(input_image == NULL){
LOG_ERROR("preprocess input id image from '%s' failed", img_file.c_str());
printf("preprocess input id image from '%s' failed\n", img_file.c_str());
return 1;
}
input_id_images.push_back(input_image);
Expand Down
66 changes: 2 additions & 64 deletions util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include "ggml/ggml.h"
#include "stable-diffusion.h"

#define STB_IMAGE_RESIZE_IMPLEMENTATION
#include "stb_image_resize.h"
#define STB_IMAGE_RESIZE_IMPLEMENTATION
#include "stb_image_resize.h"


bool ends_with(const std::string& str, const std::string& ending) {
Expand Down Expand Up @@ -91,45 +91,6 @@ std::string get_full_path(const std::string& dir, const std::string& filename) {
}
}

std::vector<std::string> get_files_from_dir(const std::string& dir) {

std::vector<std::string> files;

WIN32_FIND_DATA findFileData;
HANDLE hFind;

char currentDirectory[MAX_PATH];
GetCurrentDirectory(MAX_PATH, currentDirectory);

char directoryPath[MAX_PATH]; // this is absolute path
sprintf(directoryPath, "%s\\%s\\*", currentDirectory, dir.c_str());

// Find the first file in the directory
hFind = FindFirstFile(directoryPath, &findFileData);

// Check if the directory was found
if (hFind == INVALID_HANDLE_VALUE) {
printf("Unable to find directory.\n");
return files;
}

// Loop through all files in the directory
do {
// Check if the found file is a regular file (not a directory)
if (!(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
files.push_back(std::string(currentDirectory) + "\\" + dir + "\\" + std::string(findFileData.cFileName));
}
} while (FindNextFile(hFind, &findFileData) != 0);

// Close the handle
FindClose(hFind);


sort(files.begin(), files.end());

return files;
}

#else // Unix
#include <dirent.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -164,29 +125,6 @@ std::string get_full_path(const std::string& dir, const std::string& filename) {
return "";
}

std::vector<std::string> get_files_from_dir(const std::string &dir){

std::vector<std::string> files;

DIR* dp = opendir(dir.c_str());

if (dp != nullptr) {
struct dirent* entry;

while ((entry = readdir(dp)) != nullptr) {
std::string fname = dir + "/" + entry->d_name;
if (!is_directory(fname))
files.push_back(fname);
}
closedir(dp);
}

sort(files.begin(), files.end());

return files;

}

#endif

// get_num_physical_cores is copy from
Expand Down
2 changes: 0 additions & 2 deletions util.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ bool file_exists(const std::string& filename);
bool is_directory(const std::string& path);
std::string get_full_path(const std::string& dir, const std::string& filename);

std::vector<std::string> get_files_from_dir(const std::string &dir);

std::u32string utf8_to_utf32(const std::string& utf8_str);
std::string utf32_to_utf8(const std::u32string& utf32_str);
std::u32string unicode_value_to_utf32(int unicode_value);
Expand Down

0 comments on commit 27887b6

Please sign in to comment.