|
""" |
|
Modal deployer for deploying transcription services |
|
""" |
|
|
|
import subprocess |
|
from typing import Optional |
|
|
|
from ..utils.config import AudioProcessingConfig |
|
from ..utils.errors import DeploymentError |
|
from .endpoint_manager import EndpointManager |
|
|
|
|
|
class ModalDeployer: |
|
"""Deployer for Modal transcription services""" |
|
|
|
def __init__(self, config: Optional[AudioProcessingConfig] = None): |
|
self.config = config or AudioProcessingConfig() |
|
self.endpoint_manager = EndpointManager() |
|
|
|
def deploy_transcription_service(self) -> Optional[str]: |
|
"""Deploy transcription service to Modal""" |
|
|
|
print("π Deploying transcription service to Modal...") |
|
|
|
try: |
|
|
|
print("π Running modal deploy command...") |
|
result = subprocess.run( |
|
["modal", "deploy", "modal_config.py"], |
|
capture_output=True, |
|
text=True |
|
) |
|
|
|
if result.returncode == 0: |
|
|
|
endpoint_url = self._extract_endpoint_url(result.stdout) |
|
|
|
if endpoint_url: |
|
|
|
self.endpoint_manager.set_endpoint("transcribe_audio", endpoint_url) |
|
print(f"β
Transcription service deployed: {endpoint_url}") |
|
return endpoint_url |
|
else: |
|
print("β οΈ Could not extract endpoint URL from deployment output") |
|
return None |
|
else: |
|
raise DeploymentError( |
|
f"Modal deployment failed: {result.stderr}", |
|
service="transcription" |
|
) |
|
|
|
except FileNotFoundError: |
|
raise DeploymentError( |
|
"Modal CLI not found. Please install Modal: pip install modal", |
|
service="transcription" |
|
) |
|
except Exception as e: |
|
raise DeploymentError( |
|
f"Failed to deploy transcription service: {str(e)}", |
|
service="transcription" |
|
) |
|
|
|
def _extract_endpoint_url(self, output: str) -> Optional[str]: |
|
"""Extract endpoint URL from deployment output""" |
|
|
|
|
|
for line in output.split('\n'): |
|
if 'https://' in line and 'modal.run' in line: |
|
|
|
parts = line.split() |
|
for part in parts: |
|
if part.startswith('https://') and 'modal.run' in part: |
|
return part |
|
|
|
|
|
return f"https://{self.config.modal_app_name}--transcribe-audio-endpoint.modal.run" |
|
|
|
def check_deployment_status(self) -> bool: |
|
"""Check if transcription service is deployed and healthy""" |
|
|
|
endpoint_url = self.endpoint_manager.get_endpoint("transcribe_audio") |
|
if not endpoint_url: |
|
print("β No transcription endpoint configured") |
|
return False |
|
|
|
if self.endpoint_manager.check_endpoint_health("transcribe_audio"): |
|
print(f"β
Transcription service is healthy: {endpoint_url}") |
|
return True |
|
else: |
|
print(f"β Transcription service is not responding: {endpoint_url}") |
|
return False |
|
|
|
def undeploy_transcription_service(self): |
|
"""Remove transcription service endpoint""" |
|
self.endpoint_manager.remove_endpoint("transcribe_audio") |
|
print("ποΈ Transcription service endpoint removed from configuration") |
|
print("π‘ Note: The actual Modal deployment may still be active. Use 'modal app stop' to stop it.") |