CK-Explorer commited on
Commit
2629a0b
·
1 Parent(s): 640a11c

feat: remove unnecessary options for model selection

Browse files
Files changed (3) hide show
  1. ui/constants.py +3 -5
  2. ui/events.py +0 -4
  3. ui/layout.py +31 -59
ui/constants.py CHANGED
@@ -1,21 +1,19 @@
1
  """
2
  Constants used in the DuoSubs Hugging Face Web UI.
3
 
4
- This module defines file paths, supported subtitle formats, model precision options,
5
- and default values for use in the UI and other components.
6
  """
7
 
8
  from pathlib import Path
9
 
10
- from duosubs import ModelPrecision, SubtitleFormat
11
 
12
  TITLE_HTML = Path(__file__).parent.parent / "assets" / "title.html"
13
 
14
  SUB_EXT_LIST: list[str] = [f.value for f in SubtitleFormat]
15
  SUB_EXT_LIST_WITH_DOT: list[str] = [f".{ext}" for ext in SUB_EXT_LIST]
16
- PRECISION_LIST: list[str] = [f.value for f in ModelPrecision]
17
 
18
- DEFAULT_PRECISION = ModelPrecision.FLOAT32.value
19
  DEFAULT_SUB_EXT = SubtitleFormat.ASS.value
20
 
21
  MODEL_NAME_LIST = [
 
1
  """
2
  Constants used in the DuoSubs Hugging Face Web UI.
3
 
4
+ This module defines file paths, supported subtitle formats, and default values for use
5
+ in the UI and other components.
6
  """
7
 
8
  from pathlib import Path
9
 
10
+ from duosubs import SubtitleFormat
11
 
12
  TITLE_HTML = Path(__file__).parent.parent / "assets" / "title.html"
13
 
14
  SUB_EXT_LIST: list[str] = [f.value for f in SubtitleFormat]
15
  SUB_EXT_LIST_WITH_DOT: list[str] = [f".{ext}" for ext in SUB_EXT_LIST]
 
16
 
 
17
  DEFAULT_SUB_EXT = SubtitleFormat.ASS.value
18
 
19
  MODEL_NAME_LIST = [
ui/events.py CHANGED
@@ -13,7 +13,6 @@ from duosubs import (
13
  LoadSubsError,
14
  MergeArgs,
15
  MergeSubsError,
16
- ModelPrecision,
17
  OmitFile,
18
  SaveSubsError,
19
  SubtitleFormat,
@@ -30,7 +29,6 @@ def start_merging(
30
  secondary_subtitles: str,
31
  model_name: str,
32
  batch_size: int,
33
- model_precision: str,
34
  ignore_non_overlap: bool,
35
  retain_newline: bool,
36
  secondary_above_primary: bool,
@@ -52,7 +50,6 @@ def start_merging(
52
  secondary_subtitles (str): Path to secondary subtitle file.
53
  model_name (str): Name of the model to use.
54
  batch_size (int): Batch size for inference.
55
- model_precision (str): Precision mode for inference.
56
  ignore_non_overlap (bool): Whether to ignore non-overlapping subtitles.
57
  retain_newline (bool): Whether to retain newlines in output.
58
  secondary_above_primary (bool): Whether to place secondary subtitle above
@@ -77,7 +74,6 @@ def start_merging(
77
  args = MergeArgs(
78
  primary=primary_subtitles,
79
  secondary=secondary_subtitles,
80
- model_precision=ModelPrecision(model_precision),
81
  batch_size=int(batch_size),
82
  ignore_non_overlap_filter=ignore_non_overlap,
83
  retain_newline=retain_newline,
 
13
  LoadSubsError,
14
  MergeArgs,
15
  MergeSubsError,
 
16
  OmitFile,
17
  SaveSubsError,
18
  SubtitleFormat,
 
29
  secondary_subtitles: str,
30
  model_name: str,
31
  batch_size: int,
 
32
  ignore_non_overlap: bool,
33
  retain_newline: bool,
34
  secondary_above_primary: bool,
 
50
  secondary_subtitles (str): Path to secondary subtitle file.
51
  model_name (str): Name of the model to use.
52
  batch_size (int): Batch size for inference.
 
53
  ignore_non_overlap (bool): Whether to ignore non-overlapping subtitles.
54
  retain_newline (bool): Whether to retain newlines in output.
55
  secondary_above_primary (bool): Whether to place secondary subtitle above
 
74
  args = MergeArgs(
75
  primary=primary_subtitles,
76
  secondary=secondary_subtitles,
 
77
  batch_size=int(batch_size),
78
  ignore_non_overlap_filter=ignore_non_overlap,
79
  retain_newline=retain_newline,
ui/layout.py CHANGED
@@ -10,10 +10,8 @@ file handling.
10
  import gradio as gr
11
 
12
  from .constants import (
13
- DEFAULT_PRECISION,
14
  DEFAULT_SUB_EXT,
15
  MODEL_NAME_LIST,
16
- PRECISION_LIST,
17
  SUB_EXT_LIST,
18
  SUB_EXT_LIST_WITH_DOT,
19
  TITLE_HTML,
@@ -56,7 +54,7 @@ def create_main_gr_blocks_ui(
56
  title_content = open_html(TITLE_HTML)
57
  gr.HTML(title_content)
58
  with gr.Row():
59
- with gr.Column(scale=9):
60
  (
61
  primary_file,
62
  secondary_file,
@@ -64,28 +62,26 @@ def create_main_gr_blocks_ui(
64
  merge_button,
65
  cancel_button
66
  ) = _create_subtitles_io_block()
67
- with gr.Column(scale=11):
68
  gr.Markdown("### 🔧 Configurations")
69
- with gr.Tab("Model & Device"):
70
- (
71
- model_name,
72
- batch_size,
73
- model_precision
74
- ) = _create_model_configurations_block()
75
- with gr.Tab("Alignment Behavior"):
76
- ignore_non_overlap = _create_alignment_behaviour_block()
77
- with gr.Tab("Output Styling"):
78
- (
79
- retain_newline,
80
- secondary_above_primary
81
- ) = _create_output_styling_block()
82
- with gr.Tab("File Exports"):
83
- (
84
- omit_subtitles,
85
- combined_format,
86
- primary_format,
87
- secondary_format
88
- ) = _create_file_exports_block()
89
 
90
  omit_subtitles.change(
91
  fn=validate_excluded_subtitle_file,
@@ -102,8 +98,6 @@ def create_main_gr_blocks_ui(
102
  primary_file,
103
  secondary_file,
104
  model_name,
105
- batch_size,
106
- model_precision,
107
  ignore_non_overlap,
108
  retain_newline,
109
  secondary_above_primary,
@@ -166,43 +160,26 @@ def _create_subtitles_io_block(
166
 
167
  return primary_file, secondary_file, merged_file, merge_button, cancel_button
168
 
169
- def _create_model_configurations_block() -> tuple[gr.Dropdown, gr.Slider, gr.Dropdown]:
170
  """
171
- Creates model and device configuration UI components.
172
 
173
- This function sets up the UI for selecting the model name, batch size, and model
174
- precision.
175
 
176
  Returns:
177
- tuple[gradio.Dropdown, gradio.Slider, gradio.Dropdown]:
178
- - model_name
179
- - batch_size
180
- - model_precision
181
  """
182
  with gr.Column():
183
  model_name = gr.Dropdown(
184
  choices=MODEL_NAME_LIST,
185
  label="Sentence Transformer Model",
186
  value=MODEL_NAME_LIST[0],
187
- info="Model for computing subtitle sentence similarity."
188
- )
189
-
190
- with gr.Row():
191
- batch_size = gr.Slider(
192
- label="Batch Size",
193
- minimum=8,
194
- maximum=256,
195
- value=256,
196
- step=1,
197
- info="Number of sentences to process in parallel"
198
- )
199
- model_precision = gr.Dropdown(
200
- choices=PRECISION_LIST,
201
- label="Model Precision",
202
- value=DEFAULT_PRECISION,
203
- info="Precision mode for inference"
204
  )
205
- return model_name, batch_size, model_precision
206
 
207
  def _create_alignment_behaviour_block() -> gr.Checkbox:
208
  """
@@ -296,8 +273,6 @@ def wrapped_start_merging(
296
  primary_subtitles: str,
297
  secondary_subtitles: str,
298
  model_name: str,
299
- batch_size: int,
300
- model_precision: str,
301
  ignore_non_overlap: bool,
302
  retain_newline: bool,
303
  secondary_above_primary: bool,
@@ -307,7 +282,7 @@ def wrapped_start_merging(
307
  secondary_format: str,
308
  cancel_state: list[bool],
309
  progress: gr.Progress | None = None
310
- ) -> str | None:
311
  """
312
  Wrapper for starting the merging process with all required arguments.
313
 
@@ -315,8 +290,6 @@ def wrapped_start_merging(
315
  primary_subtitles (str): Path to primary subtitle file.
316
  secondary_subtitles (str): Path to secondary subtitle file.
317
  model_name (str): Name of the model to use.
318
- batch_size (int): Batch size for inference.
319
- model_precision (str): Precision mode for inference.
320
  ignore_non_overlap (bool): Whether to ignore non-overlapping subtitles.
321
  retain_newline (bool): Whether to retain newlines in output.
322
  secondary_above_primary (bool): Whether to place secondary subtitle above
@@ -341,8 +314,7 @@ def wrapped_start_merging(
341
  primary_subtitles,
342
  secondary_subtitles,
343
  model_name,
344
- batch_size,
345
- model_precision,
346
  ignore_non_overlap,
347
  retain_newline,
348
  secondary_above_primary,
 
10
  import gradio as gr
11
 
12
  from .constants import (
 
13
  DEFAULT_SUB_EXT,
14
  MODEL_NAME_LIST,
 
15
  SUB_EXT_LIST,
16
  SUB_EXT_LIST_WITH_DOT,
17
  TITLE_HTML,
 
54
  title_content = open_html(TITLE_HTML)
55
  gr.HTML(title_content)
56
  with gr.Row():
57
+ with gr.Column():
58
  (
59
  primary_file,
60
  secondary_file,
 
62
  merge_button,
63
  cancel_button
64
  ) = _create_subtitles_io_block()
65
+ with gr.Column():
66
  gr.Markdown("### 🔧 Configurations")
67
+ with gr.Accordion("Basic"):
68
+ with gr.Tab("Model Selection"):
69
+ model_name = _create_model_configurations_block()
70
+ with gr.Tab("Output Styling"):
71
+ (
72
+ retain_newline,
73
+ secondary_above_primary
74
+ ) = _create_output_styling_block()
75
+ with gr.Tab("File Exports"):
76
+ (
77
+ omit_subtitles,
78
+ combined_format,
79
+ primary_format,
80
+ secondary_format
81
+ ) = _create_file_exports_block()
82
+ with gr.Accordion("Advanced", open=False):
83
+ with gr.Tab("Alignment Behavior"):
84
+ ignore_non_overlap = _create_alignment_behaviour_block()
 
 
85
 
86
  omit_subtitles.change(
87
  fn=validate_excluded_subtitle_file,
 
98
  primary_file,
99
  secondary_file,
100
  model_name,
 
 
101
  ignore_non_overlap,
102
  retain_newline,
103
  secondary_above_primary,
 
160
 
161
  return primary_file, secondary_file, merged_file, merge_button, cancel_button
162
 
163
+ def _create_model_configurations_block() -> gr.Dropdown:
164
  """
165
+ Creates model selection configuration UI components.
166
 
167
+ This function sets up the UI for selecting the model name.
 
168
 
169
  Returns:
170
+ gradio.Dropdown: model name
 
 
 
171
  """
172
  with gr.Column():
173
  model_name = gr.Dropdown(
174
  choices=MODEL_NAME_LIST,
175
  label="Sentence Transformer Model",
176
  value=MODEL_NAME_LIST[0],
177
+ info=(
178
+ "Model for computing subtitle sentence similarity, "
179
+ "with float32 precision"
180
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
181
  )
182
+ return model_name
183
 
184
  def _create_alignment_behaviour_block() -> gr.Checkbox:
185
  """
 
273
  primary_subtitles: str,
274
  secondary_subtitles: str,
275
  model_name: str,
 
 
276
  ignore_non_overlap: bool,
277
  retain_newline: bool,
278
  secondary_above_primary: bool,
 
282
  secondary_format: str,
283
  cancel_state: list[bool],
284
  progress: gr.Progress | None = None
285
+ ) -> str | None:
286
  """
287
  Wrapper for starting the merging process with all required arguments.
288
 
 
290
  primary_subtitles (str): Path to primary subtitle file.
291
  secondary_subtitles (str): Path to secondary subtitle file.
292
  model_name (str): Name of the model to use.
 
 
293
  ignore_non_overlap (bool): Whether to ignore non-overlapping subtitles.
294
  retain_newline (bool): Whether to retain newlines in output.
295
  secondary_above_primary (bool): Whether to place secondary subtitle above
 
314
  primary_subtitles,
315
  secondary_subtitles,
316
  model_name,
317
+ 256,
 
318
  ignore_non_overlap,
319
  retain_newline,
320
  secondary_above_primary,