added interactive translation
This commit is contained in:
parent
bb03886da6
commit
310ec8597a
1 changed files with 50 additions and 3 deletions
|
@ -3,6 +3,7 @@ from .menu import MainMenu, PromptMenu, SettingsMenu
|
||||||
from srtify.core.prompts import PromptsManager
|
from srtify.core.prompts import PromptsManager
|
||||||
from srtify.core.settings import SettingsManager
|
from srtify.core.settings import SettingsManager
|
||||||
from srtify.utils.utils import clear_screen, fancy_headline
|
from srtify.utils.utils import clear_screen, fancy_headline
|
||||||
|
from ..core.translator import TranslatorApp
|
||||||
|
|
||||||
|
|
||||||
class CliHandler:
|
class CliHandler:
|
||||||
|
@ -35,9 +36,7 @@ class CliHandler:
|
||||||
try:
|
try:
|
||||||
match choice:
|
match choice:
|
||||||
case "translate":
|
case "translate":
|
||||||
# TODO: Implement translation
|
self.interactive_translation()
|
||||||
print("Not implemented yet!")
|
|
||||||
input("Press Enter to continue...")
|
|
||||||
case "prompts":
|
case "prompts":
|
||||||
self.handle_prompts_menu()
|
self.handle_prompts_menu()
|
||||||
case "settings":
|
case "settings":
|
||||||
|
@ -51,6 +50,54 @@ class CliHandler:
|
||||||
print(f"❌ Error in Main Menu: {e}")
|
print(f"❌ Error in Main Menu: {e}")
|
||||||
input("Press Enter to continue...")
|
input("Press Enter to continue...")
|
||||||
|
|
||||||
|
def interactive_translation(self):
|
||||||
|
clear_screen()
|
||||||
|
print(fancy_headline("Start Translation", "rounded"))
|
||||||
|
|
||||||
|
input_dir, output_dir = self.settings_manager.get_directories()
|
||||||
|
lang, batch_size = self.settings_manager.get_translation_config()
|
||||||
|
api_key = self.settings_manager.get_api_key()
|
||||||
|
|
||||||
|
if not api_key:
|
||||||
|
print("❌ No API key found. Use 'subtitle-translator settings' to configure.")
|
||||||
|
input("Press Enter to continue...")
|
||||||
|
return
|
||||||
|
|
||||||
|
print("\nSelect a prompt to use for translation:")
|
||||||
|
prompt = self.select_prompt_for_translation()
|
||||||
|
print(f"Selected prompt: {prompt}")
|
||||||
|
|
||||||
|
app = TranslatorApp(self.settings_manager, self.prompts_manager)
|
||||||
|
|
||||||
|
options = {
|
||||||
|
'input': input_dir,
|
||||||
|
'output': output_dir,
|
||||||
|
'language': lang,
|
||||||
|
'batch_size': batch_size,
|
||||||
|
'prompt': prompt
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
app.run_translation(options)
|
||||||
|
print("✅ Translation completed successfully!")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ Error during translation: {e}")
|
||||||
|
finally:
|
||||||
|
input("Press Enter to continue...")
|
||||||
|
|
||||||
|
def select_prompt_for_translation(self) -> str:
|
||||||
|
""" Let the user select a prompt for translation
|
||||||
|
:return: str: prompt
|
||||||
|
"""
|
||||||
|
all_prompts = self.prompts_manager.get_all_prompts()
|
||||||
|
for i, (name, prompt) in enumerate(all_prompts.items()):
|
||||||
|
print(f"{i+1} - {name}: {prompt[:100]}")
|
||||||
|
choice = input("Enter the number of the prompt you want to use: ")
|
||||||
|
try:
|
||||||
|
return list(all_prompts.keys())[int(choice) - 1]
|
||||||
|
except (IndexError, ValueError):
|
||||||
|
print("Invalid choice. Please enter a number between 1 and", len(all_prompts))
|
||||||
|
|
||||||
def handle_prompts_menu(self):
|
def handle_prompts_menu(self):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue