Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preset model downloader and bump versions #8

Merged
merged 7 commits into from
Mar 19, 2024
Merged
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
4 changes: 2 additions & 2 deletions .github/scripts/.build.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ ${_usage_host:-}"
-DCODESIGN_IDENTITY=${CODESIGN_IDENT:--}
)

# TODO: enable -arch arm64
cmake_build_args+=(--preset ${_preset} --parallel --config ${config} -- ONLY_ACTIVE_ARCH=NO -arch x86_64 -arch arm64)
cmake_build_args+=(--preset ${_preset} --parallel --config ${config} -- ONLY_ACTIVE_ARCH=NO -arch arm64 -arch x86_64)
cmake_install_args+=(build_macos --config ${config} --prefix "${project_root}/release/${config}")

local -a xcbeautify_opts=()
Expand All @@ -243,6 +242,7 @@ ${_usage_host:-}"
-G "${generator}"
-DQT_VERSION=${QT_VERSION:-6}
-DCMAKE_BUILD_TYPE=${config}
-DCMAKE_INSTALL_PREFIX=/usr
)

local cmake_version
Expand Down
19 changes: 10 additions & 9 deletions .github/scripts/Package-Windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,18 @@ function Package {
Invoke-External iscc ${IsccFile} /O"${ProjectRoot}/release" /F"${OutputName}-Installer"
Remove-Item -Path Package -Recurse
Pop-Location -Stack BuildTemp
} else {
Log-Group "Archiving ${ProductName}..."
$CompressArgs = @{
Path = (Get-ChildItem -Path "${ProjectRoot}/release/${Configuration}" -Exclude "${OutputName}*.*")
CompressionLevel = 'Optimal'
DestinationPath = "${ProjectRoot}/release/${OutputName}.zip"
Verbose = ($Env:CI -ne $null)
}
}

Compress-Archive -Force @CompressArgs
Log-Group "Archiving ${ProductName}..."
$CompressArgs = @{
Path = (Get-ChildItem -Path "${ProjectRoot}/release/${Configuration}" -Exclude "${OutputName}*.*")
CompressionLevel = 'Optimal'
DestinationPath = "${ProjectRoot}/release/${OutputName}.zip"
Verbose = ($Env:CI -ne $null)
}

Compress-Archive -Force @CompressArgs

Log-Group
}

Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/utils.zsh/check_macos
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ if (( ! ${+commands[brew]} )) {
return 2
}

brew bundle --file ${SCRIPT_HOME}/.Brewfile
brew bundle --no-upgrade --file ${SCRIPT_HOME}/.Brewfile
rehash
log_group
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE OBS::libobs)
include(cmake/BuildCTranslate2.cmake)
include(cmake/BuildSentencepiece.cmake)
include(cmake/BuildCppHTTPLib.cmake)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ct2 sentencepiece cpphttplib)
include(cmake/BuildMyCurl.cmake)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ct2 sentencepiece cpphttplib libcurl)

if(ENABLE_FRONTEND_API)
find_package(obs-frontend-api REQUIRED)
Expand All @@ -40,7 +41,10 @@ if(ENABLE_QT)
endif()

add_subdirectory(src/ui)
target_sources(${CMAKE_PROJECT_NAME} PRIVATE src/translation-service/translation.cpp src/plugin-main.c
src/utils/config-data.cpp src/translation-service/httpserver.cpp)
target_sources(
${CMAKE_PROJECT_NAME}
PRIVATE src/translation-service/translation.cpp src/plugin-main.c src/utils/config-data.cpp
src/translation-service/httpserver.cpp src/model-utils/model-downloader.cpp
src/model-utils/model-downloader-ui.cpp)

set_target_properties_plugin(${CMAKE_PROJECT_NAME} PROPERTIES OUTPUT_NAME ${_name})
81 changes: 22 additions & 59 deletions cmake/BuildCTranslate2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ if(APPLE)

FetchContent_Declare(
ctranslate2_fetch
URL https://github.com/obs-ai/obs-ai-ctranslate2-dep/releases/download/1.0.0/libctranslate2-macos-Release-1.0.0.tar.gz
URL_HASH SHA256=8e55a6ed4fb17ac556ad0e020ddab619584e3ceb4c9497a816f819bd8fd36443)
URL https://github.com/occ-ai/obs-ai-ctranslate2-dep/releases/download/1.1.1/libctranslate2-macos-Release-1.1.1.tar.gz
URL_HASH SHA256=da04d88ecc1ea105f8ee672e4eab33af96e50c999c5cc8170e105e110392182b)
FetchContent_MakeAvailable(ctranslate2_fetch)

add_library(ct2 INTERFACE)
Expand All @@ -17,45 +17,29 @@ if(APPLE)
set_target_properties(ct2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${ctranslate2_fetch_SOURCE_DIR}/include)
target_compile_options(ct2 INTERFACE -Wno-shorten-64-to-32)

else()
set(CT2_VERSION "3.20.0")
set(CT2_URL "https://github.com/OpenNMT/CTranslate2.git")
elseif(WIN32)

if(WIN32)
# Build with OpenBLAS
FetchContent_Declare(
ctranslate2_fetch
URL https://github.com/occ-ai/obs-ai-ctranslate2-dep/releases/download/1.1.1/libctranslate2-windows-4.1.1-Release.zip
URL_HASH SHA256=aa87073e663e4dfbbc9b9360d83bed847212309bea433c3b1888a33a51cb0db0)
FetchContent_MakeAvailable(ctranslate2_fetch)

set(OpenBLAS_URL "https://github.com/xianyi/OpenBLAS/releases/download/v0.3.24/OpenBLAS-0.3.24-x64.zip")
set(OpenBLAS_SHA256 "6335128ee7117ea2dd2f5f96f76dafc17256c85992637189a2d5f6da0c608163")
FetchContent_Declare(
openblas_fetch
URL ${OpenBLAS_URL}
URL_HASH SHA256=${OpenBLAS_SHA256})
FetchContent_MakeAvailable(openblas_fetch)
set(OpenBLAS_DIR ${openblas_fetch_SOURCE_DIR})
set(OPENBLAS_INCLUDE_DIR ${OpenBLAS_DIR}/include)
add_library(ct2 INTERFACE)
target_link_libraries(ct2 INTERFACE ${ctranslate2_fetch_SOURCE_DIR}/lib/ctranslate2.lib)
set_target_properties(ct2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${ctranslate2_fetch_SOURCE_DIR}/include)
target_compile_options(ct2 INTERFACE /wd4267 /wd4244 /wd4305 /wd4996 /wd4099)

add_library(openblas STATIC IMPORTED)
set_target_properties(openblas PROPERTIES IMPORTED_LOCATION ${OpenBLAS_DIR}/lib/libopenblas.dll.a)
install(FILES ${OpenBLAS_DIR}/bin/libopenblas.dll DESTINATION "obs-plugins/64bit")
install(FILES ${ctranslate2_fetch_SOURCE_DIR}/bin/ctranslate2.dll ${ctranslate2_fetch_SOURCE_DIR}/bin/libopenblas.dll
DESTINATION "obs-plugins/64bit")

set(CT2_OPENBLAS_CMAKE_ARGS -DOPENBLAS_INCLUDE_DIR=${OPENBLAS_INCLUDE_DIR}
-DOPENBLAS_LIBRARY=${OpenBLAS_DIR}/lib/libopenblas.dll.a -DWITH_OPENBLAS=ON)
else()
set(CT2_OPENBLAS_CMAKE_ARGS -DWITH_OPENBLAS=OFF)
endif()
else()
set(CT2_VERSION "4.1.1")
set(CT2_URL "https://github.com/OpenNMT/CTranslate2.git")
set(CT2_OPENBLAS_CMAKE_ARGS -DWITH_OPENBLAS=OFF)

if(UNIX)
if(APPLE)
set(CT2_CMAKE_PLATFORM_OPTIONS -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 -DBUILD_SHARED_LIBS=OFF -DWITH_ACCELERATE=ON
-DOPENMP_RUNTIME=NONE -DCMAKE_OSX_ARCHITECTURES=arm64)
else()
set(CT2_CMAKE_PLATFORM_OPTIONS -DBUILD_SHARED_LIBS=OFF -DOPENMP_RUNTIME=NONE -DCMAKE_POSITION_INDEPENDENT_CODE=ON)
endif()
set(CT2_LIB_INSTALL_LOCATION lib/${CMAKE_SHARED_LIBRARY_PREFIX}ctranslate2${CMAKE_STATIC_LIBRARY_SUFFIX})
else()
set(CT2_CMAKE_PLATFORM_OPTIONS -DBUILD_SHARED_LIBS=ON -DOPENMP_RUNTIME=COMP)
set(CT2_LIB_INSTALL_LOCATION bin/${CMAKE_SHARED_LIBRARY_PREFIX}ctranslate2${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()
set(CT2_CMAKE_PLATFORM_OPTIONS -DBUILD_SHARED_LIBS=OFF -DOPENMP_RUNTIME=NONE -DCMAKE_POSITION_INDEPENDENT_CODE=ON)
set(CT2_LIB_INSTALL_LOCATION lib/${CMAKE_SHARED_LIBRARY_PREFIX}ctranslate2${CMAKE_STATIC_LIBRARY_SUFFIX})

ExternalProject_Add(
ct2_build
Expand Down Expand Up @@ -84,33 +68,12 @@ else()
${CT2_CMAKE_PLATFORM_OPTIONS})
ExternalProject_Get_Property(ct2_build INSTALL_DIR)

if(UNIX)
# Get cpu_features from the CTranslate2 build - only for x86_64 builds if(APPLE)
# ExternalProject_Get_Property(ct2_build BINARY_DIR) add_library(ct2::cpu_features STATIC IMPORTED GLOBAL)
# set_target_properties( ct2::cpu_features PROPERTIES IMPORTED_LOCATION
# ${BINARY_DIR}/third_party/cpu_features/RelWithDebInfo/libcpu_features.a) endif()

add_library(ct2::ct2 STATIC IMPORTED GLOBAL)
else()
add_library(ct2::ct2 SHARED IMPORTED GLOBAL)
set_target_properties(
ct2::ct2 PROPERTIES IMPORTED_IMPLIB
${INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}ctranslate2${CMAKE_STATIC_LIBRARY_SUFFIX})
install(FILES ${INSTALL_DIR}/${CT2_LIB_INSTALL_LOCATION} DESTINATION "obs-plugins/64bit")
endif()
add_library(ct2::ct2 STATIC IMPORTED GLOBAL)
add_dependencies(ct2::ct2 ct2_build)
set_target_properties(ct2::ct2 PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/${CT2_LIB_INSTALL_LOCATION})

add_library(ct2 INTERFACE)
if(APPLE)
target_link_libraries(
ct2
INTERFACE
"-framework Accelerate /Users/roy_shilkrot/Downloads/obs-ai-ctranslate2-dep/CTranslate2-3.20.0/release/universal/RelWithDebInfo/lib/libctranslate2.a"
)
else()
target_link_libraries(ct2 INTERFACE ct2::ct2)
endif()
target_link_libraries(ct2 INTERFACE ct2::ct2)
set_target_properties(ct2::ct2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include)

endif()
73 changes: 73 additions & 0 deletions cmake/BuildMyCurl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
include(FetchContent)

set(LibCurl_VERSION "8.4.0-3")
set(LibCurl_BASEURL "https://github.com/occ-ai/obs-ai-libcurl-dep/releases/download/${LibCurl_VERSION}")

if(${CMAKE_BUILD_TYPE} STREQUAL Release OR ${CMAKE_BUILD_TYPE} STREQUAL RelWithDebInfo)
set(LibCurl_BUILD_TYPE Release)
else()
set(LibCurl_BUILD_TYPE Debug)
endif()

if(APPLE)
if(LibCurl_BUILD_TYPE STREQUAL Release)
set(LibCurl_URL "${LibCurl_BASEURL}/libcurl-macos-${LibCurl_VERSION}-Release.tar.gz")
set(LibCurl_HASH SHA256=5ef7bfed2c2bca17ba562aede6a3c3eb465b8d7516cff86ca0f0d0337de951e1)
else()
set(LibCurl_URL "${LibCurl_BASEURL}/libcurl-macos-${LibCurl_VERSION}-Debug.tar.gz")
set(LibCurl_HASH SHA256=da0801168eac5103e6b27bfd0f56f82e0617f85e4e6c69f476071dbba273403b)
endif()
elseif(MSVC)
if(LibCurl_BUILD_TYPE STREQUAL Release)
set(LibCurl_URL "${LibCurl_BASEURL}/libcurl-windows-${LibCurl_VERSION}-Release.zip")
set(LibCurl_HASH SHA256=bf4d4cd7d741712a2913df0994258d11aabe22c9a305c9f336ed59e76f351adf)
else()
set(LibCurl_URL "${LibCurl_BASEURL}/libcurl-windows-${LibCurl_VERSION}-Debug.zip")
set(LibCurl_HASH SHA256=9fe20e677ffb0d7dd927b978d532e23574cdb1923e2d2ca7c5e42f1fff2ec529)
endif()
else()
if(LibCurl_BUILD_TYPE STREQUAL Release)
set(LibCurl_URL "${LibCurl_BASEURL}/libcurl-linux-${LibCurl_VERSION}-Release.tar.gz")
set(LibCurl_HASH SHA256=f2cd80b7d3288fe5b4c90833bcbf0bde7c9574bc60eddb13015df19c5a09f56b)
else()
set(LibCurl_URL "${LibCurl_BASEURL}/libcurl-linux-${LibCurl_VERSION}-Debug.tar.gz")
set(LibCurl_HASH SHA256=6a41d3daef98acc3172b3702118dcf1cccbde923f3836ed2f4f3ed7301e47b8b)
endif()
endif()

FetchContent_Declare(
libcurl_fetch
URL ${LibCurl_URL}
URL_HASH ${LibCurl_HASH})
FetchContent_MakeAvailable(libcurl_fetch)

if(MSVC)
set(libcurl_fetch_lib_location "${libcurl_fetch_SOURCE_DIR}/lib/libcurl.lib")
set(libcurl_fetch_link_libs "\$<LINK_ONLY:ws2_32>;\$<LINK_ONLY:advapi32>;\$<LINK_ONLY:crypt32>;\$<LINK_ONLY:bcrypt>")
else()
find_package(ZLIB REQUIRED)
set(libcurl_fetch_lib_location "${libcurl_fetch_SOURCE_DIR}/lib/libcurl.a")
if(UNIX AND NOT APPLE)
find_package(OpenSSL REQUIRED)
set(libcurl_fetch_link_libs "\$<LINK_ONLY:OpenSSL::SSL>;\$<LINK_ONLY:OpenSSL::Crypto>;\$<LINK_ONLY:ZLIB::ZLIB>")
else()
set(libcurl_fetch_link_libs
"-framework SystemConfiguration;-framework Security;-framework CoreFoundation;-framework CoreServices;ZLIB::ZLIB"
)
endif()
endif()

# Create imported target
add_library(libcurl STATIC IMPORTED)

set_target_properties(
libcurl
PROPERTIES INTERFACE_COMPILE_DEFINITIONS "CURL_STATICLIB"
INTERFACE_INCLUDE_DIRECTORIES "${libcurl_fetch_SOURCE_DIR}/include"
INTERFACE_LINK_LIBRARIES "${libcurl_fetch_link_libs}")
set_property(
TARGET libcurl
APPEND
PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(libcurl PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C" IMPORTED_LOCATION_RELEASE
${libcurl_fetch_lib_location})
15 changes: 13 additions & 2 deletions cmake/BuildSentencepiece.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,24 @@ if(APPLE)

FetchContent_Declare(
sentencepiece_fetch
URL https://github.com/obs-ai/obs-ai-ctranslate2-dep/releases/download/1.0.0/libsentencepiece-macos-Release-1.0.0.tar.gz
URL_HASH SHA256=67f58a8e97c14db1bc69becd507ffe69326948f371bf874fe919157d7d65aff4)
URL https://github.com/occ-ai/obs-ai-ctranslate2-dep/releases/download/1.1.1/libsentencepiece-macos-Release-1.1.1.tar.gz
URL_HASH SHA256=c911f1e84ea94925a8bc3fd3257185b2e18395075509c8659cc7003a979e0b32)
FetchContent_MakeAvailable(sentencepiece_fetch)
add_library(sentencepiece INTERFACE)
target_link_libraries(sentencepiece INTERFACE ${sentencepiece_fetch_SOURCE_DIR}/lib/libsentencepiece.a)
set_target_properties(sentencepiece PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
${sentencepiece_fetch_SOURCE_DIR}/include)
elseif(WIN32)

FetchContent_Declare(
sentencepiece_fetch
URL https://github.com/occ-ai/obs-ai-ctranslate2-dep/releases/download/1.1.1/sentencepiece-windows-0.2.0-Release.zip
URL_HASH SHA256=846699c7fa1e8918b71ed7f2bd5cd60e47e51105e1d84e3192919b4f0f10fdeb)
FetchContent_MakeAvailable(sentencepiece_fetch)
add_library(sentencepiece INTERFACE)
target_link_libraries(sentencepiece INTERFACE ${sentencepiece_fetch_SOURCE_DIR}/lib/sentencepiece.lib)
set_target_properties(sentencepiece PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
${sentencepiece_fetch_SOURCE_DIR}/include)

else()

Expand Down
2 changes: 1 addition & 1 deletion cmake/common/compiler_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ set(_obs_clang_c_options
-Wfour-char-constants
-Winfinite-recursion
-Wint-conversion
-Wnewline-eof
-Wno-conversion
-Wno-error=newline-eof
-Wno-float-conversion
-Wno-implicit-fallthrough
-Wno-missing-braces
Expand Down
3 changes: 2 additions & 1 deletion cmake/linux/compilerconfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ set(_obs_gcc_c_options
# cmake-format: sortable
-fno-strict-aliasing
-fopenmp-simd
-Wdeprecated-declarations
-Wempty-body
-Wenum-conversion
-Werror=return-type
-Wextra
-Wformat
-Wformat-security
-Wno-conversion
-Wno-deprecated-declarations
-Wno-error=deprecated-declarations
-Wno-float-conversion
-Wno-implicit-fallthrough
-Wno-missing-braces
Expand Down
2 changes: 1 addition & 1 deletion cmake/macos/xcode.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN__DUPLICATE_METHOD_MATCH YES)
set(CMAKE_XCODE_ATTRIBUTE_GCC_NO_COMMON_BLOCKS YES)
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_64_TO_32_BIT_CONVERSION YES)
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS NO)
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_NEWLINE YES)
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_NEWLINE NO)
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_RETURN_TYPE YES_ERROR)
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_CHECK_SWITCH_STATEMENTS YES)
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_FOUR_CHARACTER_CONSTANTS YES)
Expand Down
23 changes: 23 additions & 0 deletions src/model-utils/model-downloader-types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef MODEL_DOWNLOADER_TYPES_H
#define MODEL_DOWNLOADER_TYPES_H

#include <functional>
#include <map>
#include <string>

// Information about a model
struct ModelInfo {
std::string name;
std::vector<std::string> urls;
std::string localPath;
std::string spmUrl;
std::string localSpmPath;
};

// Callback for when the download is finished
typedef std::function<void(int download_status, const ModelInfo &modelInfo)>
download_finished_callback_t;

extern std::map<std::string, ModelInfo> models_info;

#endif // MODEL_DOWNLOADER_TYPES_H
Loading
Loading