added api for ai; got backend working
This commit is contained in:
54
backend/ai_provider.py
Normal file
54
backend/ai_provider.py
Normal file
@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
AI provider interface for Ollama, OpenAI, and Claude.
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Add backend to path
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
|
||||
from services.ai_provider import AIProvider
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python ai_provider.py <command> [args...]", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
command = sys.argv[1]
|
||||
|
||||
try:
|
||||
if command == "complete":
|
||||
if len(sys.argv) < 4:
|
||||
print("Usage: python ai_provider.py complete <prompt> <provider> [model] [api_key] [base_url] [system_prompt] [temperature]", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
prompt = sys.argv[2]
|
||||
provider = sys.argv[3]
|
||||
model = sys.argv[4] if len(sys.argv) > 4 else None
|
||||
api_key = sys.argv[5] if len(sys.argv) > 5 else None
|
||||
base_url = sys.argv[6] if len(sys.argv) > 6 else None
|
||||
system_prompt = sys.argv[7] if len(sys.argv) > 7 else None
|
||||
temperature = float(sys.argv[8]) if len(sys.argv) > 8 else 0.3
|
||||
|
||||
result = AIProvider.complete(prompt, provider, model, api_key, base_url, system_prompt, temperature)
|
||||
print(json.dumps({"response": result}))
|
||||
|
||||
elif command == "list_ollama_models":
|
||||
base_url = sys.argv[2] if len(sys.argv) > 2 else "http://localhost:11434"
|
||||
result = AIProvider.list_ollama_models(base_url)
|
||||
print(json.dumps({"models": result}))
|
||||
|
||||
else:
|
||||
print(f"Unknown command: {command}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
47
backend/audio_cleaner.py
Normal file
47
backend/audio_cleaner.py
Normal file
@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Audio cleaning operations using DeepFilterNet or FFmpeg fallback.
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Add backend to path
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
|
||||
from services.audio_cleaner import clean_audio, is_deepfilter_available
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python audio_cleaner.py <command> [args...]", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
command = sys.argv[1]
|
||||
|
||||
try:
|
||||
if command == "clean_audio":
|
||||
if len(sys.argv) != 4:
|
||||
print("Usage: python audio_cleaner.py clean_audio <input_path> <output_path>", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
input_path = sys.argv[2]
|
||||
output_path = sys.argv[3]
|
||||
result = clean_audio(input_path, output_path)
|
||||
print(json.dumps({"output_path": result}))
|
||||
|
||||
elif command == "is_deepfilter_available":
|
||||
result = is_deepfilter_available()
|
||||
print(json.dumps({"available": result}))
|
||||
|
||||
else:
|
||||
print(f"Unknown command: {command}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
50
backend/background_removal.py
Normal file
50
backend/background_removal.py
Normal file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Background removal operations (placeholder for Phase 5).
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Add backend to path
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
|
||||
from services.background_removal import is_available, remove_background_on_export
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python background_removal.py <command> [args...]", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
command = sys.argv[1]
|
||||
|
||||
try:
|
||||
if command == "is_available":
|
||||
result = is_available()
|
||||
print(json.dumps({"available": result}))
|
||||
|
||||
elif command == "remove_background_on_export":
|
||||
if len(sys.argv) != 6:
|
||||
print("Usage: python background_removal.py remove_background_on_export <input_path> <output_path> <replacement> <replacement_value>", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
input_path = sys.argv[2]
|
||||
output_path = sys.argv[3]
|
||||
replacement = sys.argv[4]
|
||||
replacement_value = sys.argv[5]
|
||||
|
||||
result = remove_background_on_export(input_path, output_path, replacement, replacement_value)
|
||||
print(json.dumps({"output_path": result}))
|
||||
|
||||
else:
|
||||
print(f"Unknown command: {command}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
78
backend/caption_generator.py
Normal file
78
backend/caption_generator.py
Normal file
@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Generate caption files from word-level timestamps.
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Add backend to path
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
|
||||
from services.caption_generator import generate_srt, generate_vtt, generate_ass, save_captions
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python caption_generator.py <command> [args...]", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
command = sys.argv[1]
|
||||
|
||||
try:
|
||||
if command == "generate_srt":
|
||||
if len(sys.argv) < 4:
|
||||
print("Usage: python caption_generator.py generate_srt <words_json> [deleted_indices_json] [words_per_line]", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
words = json.loads(sys.argv[2])
|
||||
deleted_indices = set(json.loads(sys.argv[3])) if len(sys.argv) > 3 and sys.argv[3] != "null" else None
|
||||
words_per_line = int(sys.argv[4]) if len(sys.argv) > 4 else 8
|
||||
|
||||
result = generate_srt(words, deleted_indices, words_per_line)
|
||||
print(json.dumps({"content": result}))
|
||||
|
||||
elif command == "generate_vtt":
|
||||
if len(sys.argv) < 4:
|
||||
print("Usage: python caption_generator.py generate_vtt <words_json> [deleted_indices_json] [words_per_line]", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
words = json.loads(sys.argv[2])
|
||||
deleted_indices = set(json.loads(sys.argv[3])) if len(sys.argv) > 3 and sys.argv[3] != "null" else None
|
||||
words_per_line = int(sys.argv[4]) if len(sys.argv) > 4 else 8
|
||||
|
||||
result = generate_vtt(words, deleted_indices, words_per_line)
|
||||
print(json.dumps({"content": result}))
|
||||
|
||||
elif command == "generate_ass":
|
||||
if len(sys.argv) < 4:
|
||||
print("Usage: python caption_generator.py generate_ass <words_json> [deleted_indices_json] [words_per_line] [style_json]", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
words = json.loads(sys.argv[2])
|
||||
deleted_indices = set(json.loads(sys.argv[3])) if len(sys.argv) > 3 and sys.argv[3] != "null" else None
|
||||
words_per_line = int(sys.argv[4]) if len(sys.argv) > 4 else 8
|
||||
style = json.loads(sys.argv[5]) if len(sys.argv) > 5 and sys.argv[5] != "null" else None
|
||||
|
||||
result = generate_ass(words, deleted_indices, words_per_line, style)
|
||||
print(json.dumps({"content": result}))
|
||||
|
||||
elif command == "save_captions":
|
||||
if len(sys.argv) != 4:
|
||||
print("Usage: python caption_generator.py save_captions <content> <output_path>", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
content = sys.argv[2]
|
||||
output_path = sys.argv[3]
|
||||
|
||||
result = save_captions(content, output_path)
|
||||
print(json.dumps({"output_path": result}))
|
||||
|
||||
else:
|
||||
print(f"Unknown command: {command}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
47
backend/diarization.py
Normal file
47
backend/diarization.py
Normal file
@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Speaker diarization using pyannote.audio.
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Add backend to path
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
|
||||
from services.diarization import diarize_and_label
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python diarization.py <command> [args...]", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
command = sys.argv[1]
|
||||
|
||||
try:
|
||||
if command == "diarize_and_label":
|
||||
if len(sys.argv) < 4:
|
||||
print("Usage: python diarization.py diarize_and_label <transcription_result_json> <audio_path> [hf_token] [num_speakers] [use_gpu]", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
transcription_result = json.loads(sys.argv[2])
|
||||
audio_path = sys.argv[3]
|
||||
hf_token = sys.argv[4] if len(sys.argv) > 4 else None
|
||||
num_speakers = int(sys.argv[5]) if len(sys.argv) > 5 and sys.argv[5] != "null" else None
|
||||
use_gpu = sys.argv[6].lower() == "true" if len(sys.argv) > 6 else True
|
||||
|
||||
result = diarize_and_label(transcription_result, audio_path, hf_token, num_speakers, use_gpu)
|
||||
print(json.dumps(result))
|
||||
|
||||
else:
|
||||
print(f"Unknown command: {command}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
77
backend/video_editor.py
Normal file
77
backend/video_editor.py
Normal file
@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Video editing operations using FFmpeg.
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Add backend to path
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
|
||||
from services.video_editor import export_stream_copy, export_reencode, export_reencode_with_subs, get_video_info
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python video_editor.py <command> [args...]", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
command = sys.argv[1]
|
||||
|
||||
try:
|
||||
if command == "export_stream_copy":
|
||||
if len(sys.argv) != 5:
|
||||
print("Usage: python video_editor.py export_stream_copy <input_path> <output_path> <keep_segments_json>", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
input_path = sys.argv[2]
|
||||
output_path = sys.argv[3]
|
||||
keep_segments = json.loads(sys.argv[4])
|
||||
result = export_stream_copy(input_path, output_path, keep_segments)
|
||||
print(json.dumps({"output_path": result}))
|
||||
|
||||
elif command == "export_reencode":
|
||||
if len(sys.argv) != 7:
|
||||
print("Usage: python video_editor.py export_reencode <input_path> <output_path> <keep_segments_json> <resolution> <format_hint>", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
input_path = sys.argv[2]
|
||||
output_path = sys.argv[3]
|
||||
keep_segments = json.loads(sys.argv[4])
|
||||
resolution = sys.argv[5]
|
||||
format_hint = sys.argv[6]
|
||||
result = export_reencode(input_path, output_path, keep_segments, resolution, format_hint)
|
||||
print(json.dumps({"output_path": result}))
|
||||
|
||||
elif command == "export_reencode_with_subs":
|
||||
if len(sys.argv) != 8:
|
||||
print("Usage: python video_editor.py export_reencode_with_subs <input_path> <output_path> <keep_segments_json> <subtitle_path> <resolution> <format_hint>", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
input_path = sys.argv[2]
|
||||
output_path = sys.argv[3]
|
||||
keep_segments = json.loads(sys.argv[4])
|
||||
subtitle_path = sys.argv[5]
|
||||
resolution = sys.argv[6]
|
||||
format_hint = sys.argv[7]
|
||||
result = export_reencode_with_subs(input_path, output_path, keep_segments, subtitle_path, resolution, format_hint)
|
||||
print(json.dumps({"output_path": result}))
|
||||
|
||||
elif command == "get_video_info":
|
||||
if len(sys.argv) != 3:
|
||||
print("Usage: python video_editor.py get_video_info <input_path>", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
input_path = sys.argv[2]
|
||||
result = get_video_info(input_path)
|
||||
print(json.dumps(result))
|
||||
|
||||
else:
|
||||
print(f"Unknown command: {command}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user