Spaces:
Sleeping
Sleeping
Merge branch 'main' of https://huggingface.co/spaces/aadnk/whisper-webui into main
Browse files- app.py +10 -4
- src/config.py +3 -1
- src/prompts/jsonPromptStrategy.py +2 -1
app.py
CHANGED
|
@@ -273,15 +273,21 @@ class WhisperTranscriber:
|
|
| 273 |
if ('task' in decodeOptions):
|
| 274 |
task = decodeOptions.pop('task')
|
| 275 |
|
| 276 |
-
|
| 277 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
# Prepend initial prompt
|
| 279 |
-
prompt_strategy = PrependPromptStrategy(initial_prompt,
|
| 280 |
elif (vadOptions.vadInitialPromptMode == VadInitialPromptMode.JSON_PROMPT_MODE):
|
| 281 |
# Use a JSON format to specify the prompt for each segment
|
| 282 |
prompt_strategy = JsonPromptStrategy(initial_prompt)
|
| 283 |
else:
|
| 284 |
-
raise ValueError("Invalid vadInitialPromptMode: " +
|
| 285 |
|
| 286 |
# Callable for processing an audio file
|
| 287 |
whisperCallable = model.create_callback(language, task, prompt_strategy=prompt_strategy, **decodeOptions)
|
|
|
|
| 273 |
if ('task' in decodeOptions):
|
| 274 |
task = decodeOptions.pop('task')
|
| 275 |
|
| 276 |
+
initial_prompt_mode = vadOptions.vadInitialPromptMode
|
| 277 |
+
|
| 278 |
+
# Set default initial prompt mode
|
| 279 |
+
if (initial_prompt_mode is None):
|
| 280 |
+
initial_prompt_mode = VadInitialPromptMode.PREPREND_FIRST_SEGMENT
|
| 281 |
+
|
| 282 |
+
if (initial_prompt_mode == VadInitialPromptMode.PREPEND_ALL_SEGMENTS or
|
| 283 |
+
initial_prompt_mode == VadInitialPromptMode.PREPREND_FIRST_SEGMENT):
|
| 284 |
# Prepend initial prompt
|
| 285 |
+
prompt_strategy = PrependPromptStrategy(initial_prompt, initial_prompt_mode)
|
| 286 |
elif (vadOptions.vadInitialPromptMode == VadInitialPromptMode.JSON_PROMPT_MODE):
|
| 287 |
# Use a JSON format to specify the prompt for each segment
|
| 288 |
prompt_strategy = JsonPromptStrategy(initial_prompt)
|
| 289 |
else:
|
| 290 |
+
raise ValueError("Invalid vadInitialPromptMode: " + initial_prompt_mode)
|
| 291 |
|
| 292 |
# Callable for processing an audio file
|
| 293 |
whisperCallable = model.create_callback(language, task, prompt_strategy=prompt_strategy, **decodeOptions)
|
src/config.py
CHANGED
|
@@ -41,8 +41,10 @@ class VadInitialPromptMode(Enum):
|
|
| 41 |
return VadInitialPromptMode.PREPREND_FIRST_SEGMENT
|
| 42 |
elif normalized == "json_prompt_mode":
|
| 43 |
return VadInitialPromptMode.JSON_PROMPT_MODE
|
| 44 |
-
|
| 45 |
raise ValueError(f"Invalid value for VadInitialPromptMode: {s}")
|
|
|
|
|
|
|
| 46 |
|
| 47 |
class ApplicationConfig:
|
| 48 |
def __init__(self, models: List[ModelConfig] = [], input_audio_max_duration: int = 600,
|
|
|
|
| 41 |
return VadInitialPromptMode.PREPREND_FIRST_SEGMENT
|
| 42 |
elif normalized == "json_prompt_mode":
|
| 43 |
return VadInitialPromptMode.JSON_PROMPT_MODE
|
| 44 |
+
elif normalized is not None and normalized != "":
|
| 45 |
raise ValueError(f"Invalid value for VadInitialPromptMode: {s}")
|
| 46 |
+
else:
|
| 47 |
+
return None
|
| 48 |
|
| 49 |
class ApplicationConfig:
|
| 50 |
def __init__(self, models: List[ModelConfig] = [], input_audio_max_duration: int = 600,
|
src/prompts/jsonPromptStrategy.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import json
|
|
|
|
| 2 |
from src.prompts.abstractPromptStrategy import AbstractPromptStrategy
|
| 3 |
|
| 4 |
|
|
@@ -25,7 +26,7 @@ class JsonPromptStrategy(AbstractPromptStrategy):
|
|
| 25 |
|
| 26 |
"""
|
| 27 |
parsed_json = json.loads(initial_json_prompt)
|
| 28 |
-
self.segment_lookup
|
| 29 |
|
| 30 |
for prompt_entry in parsed_json:
|
| 31 |
segment_index = prompt_entry["segment_index"]
|
|
|
|
| 1 |
import json
|
| 2 |
+
from typing import Dict
|
| 3 |
from src.prompts.abstractPromptStrategy import AbstractPromptStrategy
|
| 4 |
|
| 5 |
|
|
|
|
| 26 |
|
| 27 |
"""
|
| 28 |
parsed_json = json.loads(initial_json_prompt)
|
| 29 |
+
self.segment_lookup: Dict[str, JsonPromptSegment] = dict()
|
| 30 |
|
| 31 |
for prompt_entry in parsed_json:
|
| 32 |
segment_index = prompt_entry["segment_index"]
|