Spaces:
Sleeping
Sleeping
File size: 4,958 Bytes
402daee e378a99 402daee 170e15c 402daee e378a99 170e15c e378a99 170e15c e378a99 170e15c e378a99 170e15c e378a99 170e15c e378a99 402daee e378a99 170e15c 402daee e378a99 402daee 170e15c 402daee 170e15c e378a99 170e15c 402daee 170e15c e378a99 170e15c 402daee 170e15c 402daee 170e15c e378a99 170e15c 402daee 170e15c 402daee 170e15c e378a99 170e15c e378a99 170e15c e378a99 170e15c e378a99 170e15c e378a99 170e15c e378a99 170e15c e378a99 170e15c e378a99 170e15c e378a99 402daee |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
--[[
ReaSpeechControlsUI.lua - UI elements for configuring ASR services
]]--
ReaSpeechControlsUI = Polo {
DEFAULT_TAB = 'simple',
DEFAULT_LANGUAGE = '',
DEFAULT_MODEL_NAME = 'small',
SIMPLE_MODEL_SIZES = {
{'Small', 'small'},
{'Medium', 'medium'},
{'Large', 'distil-large-v3'},
},
COLUMN_PADDING = 15,
MARGIN_BOTTOM = 5,
MARGIN_LEFT = 115,
MARGIN_RIGHT = 0,
NARROW_COLUMN_WIDTH = 150,
}
function ReaSpeechControlsUI:init()
self.tabs = ReaSpeechTabBar.new {
default = self.DEFAULT_TAB,
tabs = {
ReaSpeechTabBar.tab('simple', 'Simple'),
ReaSpeechTabBar.tab('advanced', 'Advanced'),
}
}
self.log_enable = ReaSpeechCheckbox.simple(false, 'Enable')
self.log_debug = ReaSpeechCheckbox.simple(false, 'Debug')
self.language = ReaSpeechCombo.new {
default = self.DEFAULT_LANGUAGE,
label = 'Language',
items = WhisperLanguages.LANGUAGE_CODES,
item_labels = WhisperLanguages.LANGUAGES
}
self.translate = ReaSpeechCheckbox.new {
default = false,
label_long = 'Translate to English',
label_short = 'Translate',
width_threshold = self.NARROW_COLUMN_WIDTH
}
self.hotwords = ReaSpeechTextInput.simple('', 'Hot Words')
self.initial_prompt = ReaSpeechTextInput.simple('', 'Initial Prompt')
self.model_name = ReaSpeechTextInput.simple(self.DEFAULT_MODEL_NAME, 'Model Name')
self.vad_filter = ReaSpeechCheckbox.new {
default = true,
label_long = 'Voice Activity Detection',
label_short = 'VAD',
width_threshold = self.NARROW_COLUMN_WIDTH
}
self.model_name_buttons = ReaSpeechButtonBar.new {
default = self.DEFAULT_MODEL_NAME,
label = 'Model Name',
buttons = self.SIMPLE_MODEL_SIZES,
column_padding = self.COLUMN_PADDING,
margin_bottom = self.MARGIN_BOTTOM,
margin_left = self.MARGIN_LEFT,
margin_right = self.MARGIN_RIGHT,
}
self.model_name_buttons.on_set = function()
self.model_name:set(self.model_name_buttons:value())
end
self:init_layouts()
end
function ReaSpeechControlsUI:get_request_data()
return {
language = self.language:value(),
translate = self.translate:value(),
hotwords = self.hotwords:value(),
initial_prompt = self.initial_prompt:value(),
model_name = self.model_name:value(),
vad_filter = self.vad_filter:value(),
}
end
function ReaSpeechControlsUI:init_layouts()
self:init_advanced_layouts()
end
function ReaSpeechControlsUI:init_advanced_layouts()
local renderers = {
{self.render_model_name, self.render_hotwords, self.render_language},
{self.render_options, self.render_initial_prompt, self.render_logging},
}
self.advanced_layouts = {}
for row = 1, #renderers do
self.advanced_layouts[row] = ColumnLayout.new {
column_padding = self.COLUMN_PADDING,
margin_bottom = self.MARGIN_BOTTOM,
margin_left = self.MARGIN_LEFT,
margin_right = self.MARGIN_RIGHT,
num_columns = #renderers[row],
render_column = function (column)
ImGui.PushItemWidth(ctx, column.width)
app:trap(function () renderers[row][column.num](self, column) end)
ImGui.PopItemWidth(ctx)
end
}
end
end
function ReaSpeechControlsUI:render()
self:render_heading()
if self.tabs:value() == 'advanced' then
self:render_advanced()
else
self:render_simple()
end
ImGui.Separator(ctx)
ImGui.Dummy(ctx, 0, 5)
end
function ReaSpeechControlsUI:render_heading()
local init_x, init_y = ImGui.GetCursorPos(ctx)
ImGui.SetCursorPosX(ctx, init_x - 20)
app.png_from_bytes('reaspeech-logo-small')
ImGui.SetCursorPos(ctx, init_x + self.MARGIN_LEFT + 2, init_y)
self.tabs:render()
ImGui.SetCursorPos(ctx, ImGui.GetWindowWidth(ctx) - 55, init_y)
app.png_from_bytes('heading-logo-tech-audio')
ImGui.SetCursorPos(ctx, init_x, init_y + 40)
end
function ReaSpeechControlsUI:render_simple()
self.model_name_buttons:render()
end
function ReaSpeechControlsUI:render_advanced()
for row = 1, #self.advanced_layouts do
self.advanced_layouts[row]:render()
end
end
function ReaSpeechControlsUI:render_input_label(text)
ImGui.Text(ctx, text)
ImGui.Dummy(ctx, 0, 0)
end
function ReaSpeechControlsUI:render_language(column)
self.language:render()
self.translate:render(column)
end
function ReaSpeechControlsUI:render_model_name()
self.model_name:render()
end
function ReaSpeechControlsUI:render_model_sizes()
self.model_sizes_layout:render()
end
function ReaSpeechControlsUI:render_hotwords()
self.hotwords:render()
end
function ReaSpeechControlsUI:render_options(column)
self:render_input_label('Options')
self.vad_filter:render(column)
end
function ReaSpeechControlsUI:render_logging()
self:render_input_label('Logging')
self.log_enable:render()
if self.log_enable:value() then
ImGui.SameLine(ctx)
self.log_debug:render()
end
end
function ReaSpeechControlsUI:render_initial_prompt()
self.initial_prompt:render()
end
|