summaryrefslogtreecommitdiffstats
path: root/GUI
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2023-01-01 21:09:32 -0800
committeryum <yum.food.vr@gmail.com>2023-01-01 21:45:56 -0800
commit6bed3a15edf134fa176ca4866b4346017bc97ada (patch)
tree243fc4e278fc14d71eec3391c70b10eb4347b4c4 /GUI
parente25bdba3a3a53b09be5269d8b065c13b73ab55c3 (diff)
Portability bugfixes
* Expose option to run transcription engine on CPU instead of GPU * Use embedded git when setting up the Python virtual environment
Diffstat (limited to 'GUI')
-rw-r--r--GUI/GUI/GUI/Frame.cpp17
-rw-r--r--GUI/GUI/GUI/Frame.h1
-rw-r--r--GUI/GUI/GUI/PythonWrapper.cpp31
-rw-r--r--GUI/GUI/GUI/PythonWrapper.h10
4 files changed, 52 insertions, 7 deletions
diff --git a/GUI/GUI/GUI/Frame.cpp b/GUI/GUI/GUI/Frame.cpp
index bd4bbec..cfb2060 100644
--- a/GUI/GUI/GUI/Frame.cpp
+++ b/GUI/GUI/GUI/Frame.cpp
@@ -32,6 +32,7 @@ namespace {
ID_PY_APP_BYTES_PER_CHAR,
ID_PY_APP_MODEL_PANEL,
ID_PY_APP_ENABLE_LOCAL_BEEP,
+ ID_PY_APP_USE_CPU,
ID_PY_APP_ROWS,
ID_PY_APP_COLS,
ID_PY_APP_WINDOW_DURATION,
@@ -394,6 +395,17 @@ Frame::Frame()
);
py_app_enable_local_beep_ = py_app_enable_local_beep;
+ auto* py_app_use_cpu = new wxCheckBox(py_config_panel,
+ ID_PY_APP_USE_CPU, "Use CPU");
+ py_app_use_cpu->SetValue(false);
+ py_app_use_cpu->SetToolTip(
+ "If checked, the transcription engine will run on your "
+ "CPU instead of your GPU. This is typically much slower "
+ "and should only be used if you aren't able to use your "
+ "GPU."
+ );
+ py_app_use_cpu_ = py_app_use_cpu;
+
auto* py_app_start_button = new wxButton(py_config_panel, ID_PY_APP_START_BUTTON, "Begin transcribing");
auto* py_app_stop_button = new wxButton(py_config_panel, ID_PY_APP_STOP_BUTTON, "Stop transcribing");
@@ -403,6 +415,7 @@ Frame::Frame()
sizer->Add(py_dump_mics_button, /*proportion=*/0, /*flags=*/wxEXPAND);
sizer->Add(py_app_config_panel_pairs, /*proportion=*/0, /*flags=*/wxEXPAND);
sizer->Add(py_app_enable_local_beep, /*proportion=*/0, /*flags=*/wxEXPAND);
+ sizer->Add(py_app_use_cpu, /*proportion=*/0, /*flags=*/wxEXPAND);
sizer->Add(py_app_start_button, /*proportion=*/0, /*flags=*/wxEXPAND);
sizer->Add(py_app_stop_button, /*proportion=*/0, /*flags=*/wxEXPAND);
}
@@ -888,6 +901,7 @@ void Frame::OnAppStart(wxCommandEvent& event) {
bytes_per_char_idx = kBytesDefault;
}
const bool enable_local_beep = py_app_enable_local_beep_->GetValue();
+ const bool use_cpu = py_app_use_cpu_->GetValue();
std::string rows_str = py_app_rows_->GetValue().ToStdString();
std::string cols_str = py_app_cols_->GetValue().ToStdString();
std::string window_duration_str = py_app_window_duration_->GetValue().ToStdString();
@@ -929,7 +943,8 @@ void Frame::OnAppStart(wxCommandEvent& event) {
rows,
cols,
window_duration,
- enable_local_beep);
+ enable_local_beep,
+ use_cpu);
if (!p) {
Log(transcribe_out_, "Failed to launch transcription engine\n");
return;
diff --git a/GUI/GUI/GUI/Frame.h b/GUI/GUI/GUI/Frame.h
index 2a2760a..cd62127 100644
--- a/GUI/GUI/GUI/Frame.h
+++ b/GUI/GUI/GUI/Frame.h
@@ -50,6 +50,7 @@ private:
wxChoice* unity_bytes_per_char_;
wxCheckBox* py_app_enable_local_beep_;
+ wxCheckBox* py_app_use_cpu_;
wxProcess* py_app_;
wxTimer py_app_drain_;
diff --git a/GUI/GUI/GUI/PythonWrapper.cpp b/GUI/GUI/GUI/PythonWrapper.cpp
index da63a4a..81366e5 100644
--- a/GUI/GUI/GUI/PythonWrapper.cpp
+++ b/GUI/GUI/GUI/PythonWrapper.cpp
@@ -42,17 +42,29 @@ wxProcess* PythonWrapper::InvokeAsyncWithArgs(std::vector<std::string>&& args,
return p;
}
-bool PythonWrapper::InvokeWithArgs(std::vector<std::string>&& args,
+bool PythonWrapper::InvokeCommandWithArgs(
+ const std::string& cmd,
+ std::vector<std::string>&& args,
std::string* py_stdout, std::string* py_stderr) {
std::ostringstream cmd_oss;
- cmd_oss << "Resources/Python/python.exe";
+ cmd_oss << cmd;
for (const auto& arg : args) {
cmd_oss << " " << arg;
}
+ wxString path;
+ if (!wxGetEnv("PATH", &path)) {
+ *py_stderr = "Failed to get PATH";
+ return false;
+ }
+ if (!wxSetEnv("PATH", path + ";Resources/PortableGit/bin")) {
+ *py_stderr = "Failed to append to PATH";
+ return false;
+ }
+
wxArrayString cmd_stdout;
wxArrayString cmd_stderr;
- long result = wxExecute(cmd_oss.str(), cmd_stdout, cmd_stderr);
+ long result = wxExecute(cmd_oss.str(), cmd_stdout, cmd_stderr, /*flags=*/0);
std::ostringstream cmd_stdout_oss;
for (const auto& line : cmd_stdout) {
if (!cmd_stdout_oss.str().empty()) {
@@ -69,7 +81,9 @@ bool PythonWrapper::InvokeWithArgs(std::vector<std::string>&& args,
}
if (result == -1) {
std::ostringstream err_oss;
- err_oss << "Error while executing python command \"" << cmd_oss.str() << "\": Failed to launch process";
+ err_oss << "Error while executing python command \"" << cmd_oss.str() << "\": Failed to launch process" << std::endl;
+ err_oss << cmd_stdout_oss.str() << std::endl;
+ err_oss << cmd_stderr_oss.str() << std::endl;
if (py_stderr) {
*py_stderr = err_oss.str();
}
@@ -94,6 +108,11 @@ bool PythonWrapper::InvokeWithArgs(std::vector<std::string>&& args,
return true;
}
+bool PythonWrapper::InvokeWithArgs(std::vector<std::string>&& args,
+ std::string* py_stdout, std::string* py_stderr) {
+ return InvokeCommandWithArgs("Resources/Python/python.exe",
+ std::move(args), py_stdout, py_stderr);
+}
std::string PythonWrapper::GetVersion() {
std::string py_stdout, py_stderr;
@@ -125,7 +144,8 @@ wxProcess* PythonWrapper::StartApp(
std::function<void(wxProcess* proc, int ret)>&& exit_callback,
const std::string& mic, const std::string& lang, const std::string& model,
const std::string& chars_per_sync, const std::string& bytes_per_char,
- int rows, int cols, int window_duration_s, bool enable_local_beep) {
+ int rows, int cols, int window_duration_s, bool enable_local_beep,
+ bool use_cpu) {
return InvokeAsyncWithArgs({
"-u",
"Resources/Scripts/transcribe.py",
@@ -138,6 +158,7 @@ wxProcess* PythonWrapper::StartApp(
"--rows", std::to_string(rows),
"--cols", std::to_string(cols),
"--window_duration_s", std::to_string(window_duration_s),
+ "--cpu", use_cpu ? "1" : "0",
},
std::move(exit_callback));
}
diff --git a/GUI/GUI/GUI/PythonWrapper.h b/GUI/GUI/GUI/PythonWrapper.h
index 25855a4..a60bdae 100644
--- a/GUI/GUI/GUI/PythonWrapper.h
+++ b/GUI/GUI/GUI/PythonWrapper.h
@@ -22,6 +22,13 @@ namespace PythonWrapper
wxProcess* InvokeAsyncWithArgs(std::vector<std::string>&& args,
std::function<void(wxProcess* proc, int ret)>&& exit_callback);
+ // Invoke a command on the shell with arguments.
+ // On error, sets `out` to an error message and returns false.
+ bool InvokeCommandWithArgs(const std::string& cmd,
+ std::vector<std::string>&& args,
+ std::string* py_stdout,
+ std::string* py_stderr = NULL);
+
// Invoke the interpreter with arguments.
// On error, sets `out` to an error message and returns false.
bool InvokeWithArgs(std::vector<std::string>&& args, std::string* py_stdout,
@@ -44,7 +51,8 @@ namespace PythonWrapper
std::function<void(wxProcess* proc, int ret)>&& exit_callback,
const std::string& mic, const std::string& lang, const std::string& model,
const std::string& chars_per_sync, const std::string& bytes_per_char,
- int rows, int cols, int window_duration_s, bool enable_local_beep
+ int rows, int cols, int window_duration_s, bool enable_local_beep,
+ bool use_cpu
);
bool GenerateAnimator(