Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
vietanhdev committed Aug 2, 2023
1 parent b9f14c9 commit 3d08a2c
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 42 deletions.
15 changes: 9 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ find_package(OpenCV REQUIRED)
add_subdirectory(libs/whisper-cpp)
add_subdirectory(libs/subprocess)

# Build embeding search module
add_subdirectory(customchar/embeddb)
include_directories(libs .)

# Build embeding search library
add_library(
embeddb
customchar/embeddb/document.cpp
customchar/embeddb/embed_search.cpp
)

# Build CustomChar-core
set(TARGET customchar-core)
Expand All @@ -47,10 +53,8 @@ add_library(
target_include_directories(
${TARGET} PUBLIC
${SDL2_INCLUDE_DIRS}
libs
.
)
target_link_libraries(${TARGET} PUBLIC ${SDL2_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${OpenCV_LIBS} whisper subprocess)
target_link_libraries(${TARGET} PUBLIC ${SDL2_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${OpenCV_LIBS} whisper subprocess embeddb)

# Set binary output directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
Expand Down Expand Up @@ -113,7 +117,6 @@ if(BUILD_GUI)
${CMAKE_SOURCE_DIR}/fonts $<TARGET_FILE_DIR:customchar>/fonts)
endif()


add_executable(
test_ffmpeg_as_input tests/test_ffmpeg_as_input.cpp
)
Expand Down
8 changes: 0 additions & 8 deletions customchar/embeddb/CMakeLists.txt

This file was deleted.

8 changes: 4 additions & 4 deletions customchar/embeddb/embed_search.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#ifndef CUSTOMCHAR_EMBED_SEARCH_EMBED_SEARCH_H_
#define CUSTOMCHAR_EMBED_SEARCH_EMBED_SEARCH_H_
#ifndef CUSTOMCHAR_EMBEDDB_EMBED_SEARCH_H_
#define CUSTOMCHAR_EMBEDDB_EMBED_SEARCH_H_

#include <fstream>
#include <iostream>
#include <memory>
#include <string>
#include <vector>

#include "customchar/embed_search/search_embed_result.h"
#include "customchar/embeddb/types.h"
#include "hnswlib/hnswlib.h"

namespace CC {
Expand Down Expand Up @@ -47,4 +47,4 @@ class EmbedSearch {
} // namespace embeddb
} // namespace CC

#endif // CUSTOMCHAR_EMBED_SEARCH_EMBED_SEARCH_H_
#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef CUSTOMCHAR_EMBEDDB_EMBED_DB_H_
#define CUSTOMCHAR_EMBEDDB_EMBED_DB_H_
#ifndef CUSTOMCHAR_EMBEDDB_EMBEDDB_H_
#define CUSTOMCHAR_EMBEDDB_EMBEDDB_H_

#include <string>
#include <vector>
Expand Down
8 changes: 5 additions & 3 deletions customchar/embeddb/types.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#ifndef CUSTOMCHAR_CHARACTER_CHARACTER_H_
#define CUSTOMCHAR_CHARACTER_CHARACTER_H_
#ifndef CUSTOMCHAR_EMBEDDB_TYPES_H_
#define CUSTOMCHAR_EMBEDDB_TYPES_H_

namespace CC {
namespace embeddb {
struct SearchEmbedResult {
int id;
float score;
};

} // namespace embeddb
} // namespace CC

#endif // CUSTOMCHAR_CHARACTER_CHARACTER_H_
#endif // CUSTOMCHAR_EMBEDDB_TYPES_H_
18 changes: 9 additions & 9 deletions customchar/executors/plugin_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ class PluginExecutor {
{"(.*)stop video recording(.*)", "VIDEO_RECORD"},
{"(.*)record (a|some) video(.*)", "VIDEO_RECORD"}};

std::function<bool()> IsRecording_;
std::function<void(const std::string& filename)> StartVideoRecoding_;
std::function<void()> StopVideoCapture_;
std::function<bool()> is_recording_;
std::function<void(const std::string& filename)> start_video_recording_;
std::function<void()> stop_video_capture_;

std::vector<std::shared_ptr<Plugin>> plugins_ = {
std::make_shared<OpenAppPlugin>("OPEN_APP"),
std::make_shared<VideoRecordPlugin>("VIDEO_RECORD", IsRecording_,
StartVideoRecoding_,
StopVideoCapture_)};
std::make_shared<VideoRecordPlugin>("VIDEO_RECORD", is_recording_,
start_video_recording_,
stop_video_capture_)};
std::shared_ptr<Plugin> current_plugin_;

std::string reflect(const std::string& word);
Expand All @@ -55,9 +55,9 @@ class PluginExecutor {
std::function<bool()> is_recording,
std::function<void(const std::string& filename)> start_video_recording,
std::function<void()> stop_video_capture)
: IsRecording_(is_recording),
StartVideoRecoding_(start_video_recording),
StopVideoCapture_(stop_video_capture) {}
: is_recording_(is_recording),
start_video_recording_(start_video_recording),
stop_video_capture_(stop_video_capture) {}

/// @brief Parse and execute input
/// @param input user input string
Expand Down
20 changes: 10 additions & 10 deletions customchar/executors/plugins/video_record_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ namespace executors {
/// @brief Plugin for record videos
class VideoRecordPlugin : public Plugin {
private:
std::function<bool()> IsRecording_;
std::function<void(const std::string& filename)> StartVideoRecoding_;
std::function<void()> StopVideoCapture_;
std::function<bool()> is_recording_;
std::function<void(const std::string& filename)> start_video_recording_;
std::function<void()> stop_video_capture_;

public:
VideoRecordPlugin(
const std::string& name, std::function<bool()> is_recording,
std::function<void(const std::string& filename)> start_video_recording,
std::function<void()> stop_video_capture)
: Plugin(name),
IsRecording_(is_recording),
StartVideoRecoding_(start_video_recording),
StopVideoCapture_(stop_video_capture) {}
is_recording_(is_recording),
start_video_recording_(start_video_recording),
stop_video_capture_(stop_video_capture) {}
bool handle(const std::string& input, std::string& response,
bool& finished) override {
// Normalize app name
Expand All @@ -40,17 +40,17 @@ class VideoRecordPlugin : public Plugin {
normalized_input.find("end") != std::string::npos ||
normalized_input.find("finish") != std::string::npos;
if (contains_stop) {
if (!IsRecording_()) {
if (!is_recording_()) {
finished = true;
return false;
}
StopVideoCapture_();
stop_video_capture_();
response = "Stopping video recording";
finished = true;
return true;
}

if (IsRecording_()) {
if (is_recording_()) {
finished = true;
return false;
}
Expand All @@ -59,7 +59,7 @@ class VideoRecordPlugin : public Plugin {
std::stringstream ss;
ss << "video_" << std::time(nullptr) << ".mkv";

StartVideoRecoding_(ss.str());
start_video_recording_(ss.str());
response = "Starting video recording...";
finished = true;
return true;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 3d08a2c

Please sign in to comment.