Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added maya1_test.wav
Binary file not shown.
71 changes: 71 additions & 0 deletions maya_modal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# modal_app.py
import modal

app = modal.App("sub1")

image = (
modal.Image.debian_slim(python_version="3.11")
# 1. Install runtime deps. You can trim this, but this mirrors their stack.
.pip_install(
"torch>=2.5.0",
"torchvision>=0.20.0",
"torchaudio>=2.5.0",
"transformers>=4.57.0",
"accelerate>=1.10.0",
"vllm>=0.11.0",
"xformers>=0.0.32",
"snac>=1.2.1",
"soundfile>=0.13.0",
"numpy>=2.1.0",
"librosa>=0.11.0",
"scipy>=1.15.0",
"fastapi>=0.119.0",
"uvicorn[standard]>=0.38.0",
"pydantic>=2.12.0",
"pydantic-settings>=2.11.0",
"python-multipart>=0.0.20",
"httpx>=0.28.0",
"python-dotenv>=1.1.0",
"huggingface-hub>=0.35.0",
"tqdm>=4.67.0",
"openai>=2.5.0",
"python-Levenshtein>=0.21.0",
)
# 2. This is the crucial part: include the local `maya1` Python package.
# Because modal_app.py lives in the same directory as `maya1/`,
# Python can import `maya1` locally, and Modal will copy that package
# into /root/maya1 inside the container.
.add_local_python_source("maya1")
)


@app.function(
image=image,
gpu="A10G", # or "L4", "T4", etc.
timeout=600,
min_containers=1,
max_containers=1,
)
@modal.asgi_app()
def maya1_tts_app():
"""
Runs inside the Modal container.

- Loads env (.env) if present
- Sets default model path
- Imports FastAPI `app` from maya1.api_v2
- Returns it as the ASGI app
"""
import os
from dotenv import load_dotenv

load_dotenv()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical: .env file won't be available in Modal containers.

The load_dotenv() call will fail silently because .env files are not automatically copied to Modal containers. Environment variables configured via load_dotenv() will not be set, potentially causing the application to fail or use incorrect defaults.

Use Modal Secrets to manage environment variables instead.

Apply this approach:

  1. Create Modal secrets for your environment variables:
# Set secrets via Modal CLI
modal secret create maya1-secrets \
  MAYA1_MODEL_PATH="maya-research/maya1" \
  HUGGINGFACE_HUB_TOKEN="your_token_here"
  1. Update the function decorator to use the secrets:
 @app.function(
     image=image,
     gpu="A10G",
     timeout=600,
     min_containers=1,
     max_containers=1,
+    secrets=[modal.Secret.from_name("maya1-secrets")],
 )
 @modal.asgi_app()
 def maya1_tts_app():
  1. Remove or simplify the dotenv logic:
-    import os
-    from dotenv import load_dotenv
-
-    load_dotenv()
-
-    # If not overridden, use HF repo as model path
-    os.environ.setdefault("MAYA1_MODEL_PATH", "maya-research/maya1")
-
-    # If the model is gated and you need auth, you can also set:
-    # os.environ.setdefault("HUGGINGFACE_HUB_TOKEN", "<your_hf_token>")
+    import os
+    
+    # Secrets are automatically injected as environment variables
+    # Set defaults only if not provided
+    os.environ.setdefault("MAYA1_MODEL_PATH", "maya-research/maya1")
🤖 Prompt for AI Agents
In maya_modal.py around line 62, the call to load_dotenv() is inappropriate
because Modal containers won’t have a .env file; replace this with Modal
Secrets: remove or disable load_dotenv() and any reliance on dotenv, create
Modal secrets for the required variables (e.g., MAYA1_MODEL_PATH,
HUGGINGFACE_HUB_TOKEN), update the Modal function decorator to include
secrets=<your_secret_name> so the secrets are injected into the container, and
read values from os.environ at runtime; also remove the dotenv import if no
longer used.


# If not overridden, use HF repo as model path
os.environ.setdefault("MAYA1_MODEL_PATH", "maya-research/maya1")

# If the model is gated and you need auth, you can also set:
# os.environ.setdefault("HUGGINGFACE_HUB_TOKEN", "<your_hf_token>")

from maya1.api_v2 import app as fastapi_app
return fastapi_app