added api for ai; got backend working
This commit is contained in:
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()
|
||||
Reference in New Issue
Block a user