├── .github ├── template.yml ├── rename_project.sh └── workflows │ └── rename_project.yaml ├── aana_app_project ├── __init__.py ├── core │ ├── __init__.py │ ├── models │ │ └── __init__.py │ └── prompts │ │ ├── __init__.py │ │ ├── test.j2 │ │ └── loader.py ├── utils │ ├── core.py │ └── __init__.py ├── configs │ ├── __init__.py │ ├── settings.py │ ├── endpoints.py │ └── deployments.py ├── endpoints │ └── __init__.py ├── tests │ └── __init__.py ├── deployments │ └── __init__.py ├── exceptions │ └── core.py └── app.py ├── .devcontainer ├── Dockerfile └── devcontainer.json ├── .vscode └── settings.json ├── pyproject.toml ├── Dockerfile ├── docker-compose.yaml ├── .gitignore ├── README.md └── LICENSE /.github/template.yml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /aana_app_project/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /aana_app_project/core/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /aana_app_project/utils/core.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /aana_app_project/configs/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /aana_app_project/endpoints/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /aana_app_project/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /aana_app_project/utils/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /aana_app_project/core/models/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /aana_app_project/core/prompts/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /aana_app_project/deployments/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /aana_app_project/exceptions/core.py: -------------------------------------------------------------------------------- 1 | from aana.exceptions.core import BaseException 2 | -------------------------------------------------------------------------------- /aana_app_project/core/prompts/test.j2: -------------------------------------------------------------------------------- 1 | Define your prompts for LLMs here. Use jinja2 templating to include variables like {{ your_variable }}. -------------------------------------------------------------------------------- /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nvidia/cuda:12.1.0-cudnn8-devel-ubuntu22.04 2 | RUN apt-get update && apt-get install -y libgl1 libglib2.0-0 ffmpeg 3 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "python.analysis.packageIndexDepths": [ 3 | { 4 | "name": "aana", 5 | "depth": 10, 6 | } 7 | ], 8 | } -------------------------------------------------------------------------------- /aana_app_project/configs/settings.py: -------------------------------------------------------------------------------- 1 | from aana.configs.settings import Settings as AanaSettings 2 | 3 | 4 | class Settings(AanaSettings): 5 | """A pydantic model for App settings.""" 6 | # Add your custom settings here 7 | # Then, you can access them in your app like this: 8 | # from aana_app_project.configs.settings import settings 9 | # settings.custom_property 10 | pass 11 | 12 | 13 | settings = Settings() 14 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "aana_app_project" 3 | version = "0.1.0" 4 | description = "project_description" 5 | authors = ["author_name"] 6 | readme = "README.md" 7 | 8 | [tool.poetry.dependencies] 9 | python = "^3.10" 10 | aana = ">=0.2.2.1" 11 | 12 | [tool.poetry.group.dev.dependencies] 13 | ipykernel = "^6.29.4" 14 | ruff = "^0.1.5" 15 | 16 | [build-system] 17 | requires = ["poetry-core"] 18 | build-backend = "poetry.core.masonry.api" 19 | -------------------------------------------------------------------------------- /aana_app_project/app.py: -------------------------------------------------------------------------------- 1 | from aana.sdk import AanaSDK 2 | 3 | from aana_app_project.configs.deployments import deployments 4 | from aana_app_project.configs.endpoints import endpoints 5 | 6 | aana_app = AanaSDK(name="aana_app_project") 7 | 8 | for deployment in deployments: 9 | aana_app.register_deployment(**deployment) 10 | 11 | for endpoint in endpoints: 12 | aana_app.register_endpoint(**endpoint) 13 | 14 | if __name__ == "__main__": 15 | aana_app.connect() 16 | aana_app.migrate() 17 | aana_app.deploy() 18 | -------------------------------------------------------------------------------- /aana_app_project/configs/endpoints.py: -------------------------------------------------------------------------------- 1 | endpoints: list[dict] = [] 2 | 3 | # Add your endpoints here. 4 | # 5 | # For example: 6 | # endpoints.append( 7 | # { 8 | # "name": "predict", 9 | # "path": "/predict", 10 | # "summary": "Predict the class of an image.", 11 | # "endpoint_cls": PredictEndpoint, 12 | # } 13 | # ) 14 | # 15 | # Endpoints can be created by inheriting from the `Endpoint` class. 16 | # Put your endpoint classes in a separate files in the `endpoints` directory and import them here. 17 | # See https://github.com/mobiusml/aana_sdk/tree/main?tab=readme-ov-file#endpoints in how to create endpoints. 18 | -------------------------------------------------------------------------------- /aana_app_project/core/prompts/loader.py: -------------------------------------------------------------------------------- 1 | from jinja2 import Environment, PackageLoader, Template 2 | 3 | 4 | def get_prompt_template(name: str) -> Template: 5 | """Load a prompt template by name. 6 | 7 | Use this function to load a prompt templates for LLMs: 8 | 9 | ```python 10 | from aana_app_project.core.prompts.loader import get_prompt_template 11 | 12 | template = get_prompt_template("test") 13 | prompt = template.render(your_variable="your_value") 14 | ``` 15 | 16 | Args: 17 | name (str): The name of the prompt template. 18 | 19 | Returns: 20 | Template: The prompt template. 21 | """ 22 | env = Environment(loader=PackageLoader( 23 | "aana_app_project.core", "prompts")) 24 | template = env.get_template(f"{name}.j2") 25 | return template 26 | -------------------------------------------------------------------------------- /.github/rename_project.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | while getopts a:n:d: flag 3 | do 4 | case "${flag}" in 5 | a) author=${OPTARG};; 6 | n) name=${OPTARG};; 7 | d) description=${OPTARG};; 8 | esac 9 | done 10 | 11 | echo "Author: $author"; 12 | echo "Project Name: $name"; 13 | echo "Description: $description"; 14 | 15 | echo "Renaming project..." 16 | 17 | original_author="author_name" 18 | original_name="aana_app_project" 19 | original_description="project_description" 20 | for filename in $(git ls-files) 21 | do 22 | sed -i "s/$original_author/$author/g" $filename 23 | sed -i "s/$original_name/$name/g" $filename 24 | sed -i "s/$original_description/$description/g" $filename 25 | echo "Renamed $filename" 26 | done 27 | 28 | mv $original_name $name 29 | 30 | # This command runs only once on GHA! 31 | rm -rf .github/template.yml 32 | rm -rf .github/workflows/rename_project.yaml 33 | rm -rf .github/rename_project.sh -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Ubuntu", 3 | "build": { 4 | "dockerfile": "Dockerfile" 5 | }, 6 | "capAdd": [ 7 | "SYS_PTRACE" 8 | ], 9 | "features": { 10 | "ghcr.io/devcontainers/features/python:1": { 11 | "installTools": true, 12 | "version": "3.10" 13 | }, 14 | "ghcr.io/devcontainers-contrib/features/poetry:2": { 15 | "version": "latest" 16 | } 17 | }, 18 | "hostRequirements": { 19 | "gpu": "optional" 20 | }, 21 | "securityOpt": [ 22 | "seccomp=unconfined" 23 | ], 24 | "postStartCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}", 25 | "customizations": { 26 | "vscode": { 27 | "extensions": [ 28 | "charliermarsh.ruff", 29 | "ms-python.python", 30 | "ms-python.mypy-type-checker", 31 | "ms-toolsai.jupyter" 32 | ] 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /aana_app_project/configs/deployments.py: -------------------------------------------------------------------------------- 1 | deployments: list[dict] = [] 2 | 3 | # Add deployments for models that you want to deploy here. 4 | # 5 | # For example: 6 | # from aana.deployments.whisper_deployment import ( 7 | # WhisperComputeType, 8 | # WhisperConfig, 9 | # WhisperDeployment, 10 | # WhisperModelSize, 11 | # ) 12 | # asr_deployment = WhisperDeployment.options( 13 | # num_replicas=1, 14 | # ray_actor_options={"num_gpus": 0.1}, 15 | # user_config=WhisperConfig( 16 | # model_size=WhisperModelSize.MEDIUM, 17 | # compute_type=WhisperComputeType.FLOAT16, 18 | # ).model_dump(mode="json"), 19 | # ) 20 | # deployments.append({"name": "asr_deployment", "instance": asr_deployment}) 21 | # 22 | # You can use predefined deployments from the Aana SDK or create your own. 23 | # See https://github.com/mobiusml/aana_sdk/blob/main/docs/integrations.md for the list of predefined deployments. 24 | # 25 | # If you want to create your own deployment, put your deployment classes in a separate files in the `deployments` directory and import them here. 26 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Use NVIDIA CUDA as base image 2 | FROM nvidia/cuda:12.1.1-cudnn8-devel-ubuntu22.04 3 | 4 | # Build args 5 | ARG INSTALL_FLASH_ATTENTION=false 6 | 7 | # Set working directory 8 | WORKDIR /app 9 | 10 | # Set environment variables to non-interactive (this prevents some prompts) 11 | ENV DEBIAN_FRONTEND=non-interactive 12 | 13 | # Install required libraries, tools, and Python3 14 | RUN apt-get update && apt-get install -y ffmpeg curl git python3.10 python3-pip 15 | 16 | # Install poetry 17 | RUN curl -sSL https://install.python-poetry.org | python3 - 18 | 19 | # Update PATH 20 | RUN echo 'export PATH="/root/.local/bin:$PATH"' >> /root/.bashrc 21 | ENV PATH="/root/.local/bin:$PATH" 22 | 23 | # Copy project files into the container 24 | COPY . /app 25 | 26 | # Install the package with poetry 27 | RUN poetry install 28 | 29 | # Install flash attention 30 | RUN poetry run pip install torch --index-url https://download.pytorch.org/whl/cu121 31 | RUN if [[ "$INSTALL_FLASH_ATTENTION" = "true" ]] ; then \ 32 | poetry run pip install flash-attn --no-build-isolation; \ 33 | else \ 34 | echo Skip flash_atten installation ; \ 35 | fi 36 | 37 | # Disable buffering for stdout and stderr to get the logs in real time 38 | ENV PYTHONUNBUFFERED=1 39 | 40 | # Expose the desired port 41 | EXPOSE 8000 42 | 43 | # Run the app 44 | CMD ["poetry", "run", "aana", "deploy", "aana_app_project.app:aana_app", "--host", "0.0.0.0"] 45 | -------------------------------------------------------------------------------- /.github/workflows/rename_project.yaml: -------------------------------------------------------------------------------- 1 | name: Rename the project from template 2 | 3 | on: [push] 4 | 5 | permissions: write-all 6 | 7 | jobs: 8 | rename-project: 9 | if: ${{ !contains (github.repository, '/aana_app_template') }} 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v3 13 | with: 14 | # by default, it uses a depth of 1 15 | # this fetches all history so that we can read each commit 16 | fetch-depth: 0 17 | ref: ${{ github.head_ref }} 18 | 19 | - run: echo "REPOSITORY_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}' | tr '-' '_' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV 20 | shell: bash 21 | 22 | - run: echo "REPOSITORY_OWNER=$(echo '${{ github.repository }}' | awk -F '/' '{print $1}')" >> $GITHUB_ENV 23 | shell: bash 24 | 25 | - name: Is this still a template 26 | id: is_template 27 | run: echo "::set-output name=is_template::$(ls .github/template.yml &> /dev/null && echo true || echo false)" 28 | 29 | - name: Rename the project 30 | if: steps.is_template.outputs.is_template == 'true' 31 | run: | 32 | echo "Renaming the project with -a(author) ${{ env.REPOSITORY_OWNER }} -n(name) ${{ env.REPOSITORY_NAME }}" 33 | .github/rename_project.sh -a ${{ env.REPOSITORY_OWNER }} -n ${{ env.REPOSITORY_NAME }} -d "" 34 | 35 | - uses: stefanzweifel/git-auto-commit-action@v4 36 | with: 37 | commit_message: "✅ Ready to clone and code." 38 | # commit_options: '--amend --no-edit' 39 | push_options: --force -------------------------------------------------------------------------------- /docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3.8' 2 | 3 | services: 4 | postgres: 5 | restart: always 6 | container_name: aana_app_project_db 7 | image: postgres 8 | command: postgres -c 'max_connections=1000' 9 | healthcheck: 10 | test: /usr/bin/pg_isready 11 | timeout: 45s 12 | interval: 10s 13 | retries: 10 14 | ports: 15 | - '15430:15430' 16 | expose: 17 | - 15430 18 | environment: 19 | PGPASSWORD: '${POSTGRES_PASSWORD:-Yf?5nX39}' 20 | PGUSER: '${POSTGRES_USER:-aana_db_user}' 21 | PGDATABASE: '${POSTGRES_DB:-aana_db}' 22 | POSTGRES_PASSWORD: '${POSTGRES_PASSWORD:-Yf?5nX39}' 23 | POSTGRES_USER: '${POSTGRES_USER:-aana_db_user}' 24 | POSTGRES_DB: '${POSTGRES_DB:-aana_db}' 25 | PGPORT: '15430' 26 | PGDATA: '/pgdata' 27 | volumes: 28 | - pg_data:/pgdata 29 | 30 | aana_app_project_app: 31 | restart: always 32 | container_name: aana_app_project_app 33 | depends_on: 34 | postgres: 35 | condition: service_healthy 36 | ports: 37 | - 8000:8000 # request server 38 | expose: 39 | - '8000' 40 | build: 41 | context: . 42 | dockerfile: Dockerfile 43 | args: 44 | INSTALL_FLASH_ATTENTION: '${INSTALL_FLASH_ATTENTION:-false}' 45 | deploy: 46 | resources: 47 | reservations: 48 | devices: 49 | - capabilities: ["gpu"] 50 | environment: 51 | CUDA_VISIBLE_DEVICES: 52 | HF_HUB_ENABLE_HF_TRANSFER: '${HF_HUB_ENABLE_HF_TRANSFER:-1}' 53 | HF_TOKEN: '${HF_TOKEN}' 54 | HF_DATASETS_CACHE: /root/.cache/huggingface 55 | NUM_WORKERS: '${NUM_WORKERS:-2}' 56 | TMP_DATA_DIR: /tmp/aana_data 57 | DB_CONFIG: '{"datastore_type":"postgresql","datastore_config":{"host":"postgres","port":"15430","user":"${POSTGRES_USER:-aana_db_user}","password":"${POSTGRES_PASSWORD:-Yf?5nX39}","database":"${POSTGRES_DB:-aana_db}"}}' 58 | volumes: 59 | - app_data:/tmp/aana_data 60 | - hf_datasets_cache:/root/.cache/huggingface 61 | 62 | volumes: 63 | pg_data: 64 | name: aana_app_project_postgres_data 65 | app_data: 66 | name: aana_app_project_app_data 67 | hf_datasets_cache: 68 | name: hf_datasets_cache 69 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/latest/usage/project/#working-with-version-control 110 | .pdm.toml 111 | .pdm-python 112 | .pdm-build/ 113 | 114 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 115 | __pypackages__/ 116 | 117 | # Celery stuff 118 | celerybeat-schedule 119 | celerybeat.pid 120 | 121 | # SageMath parsed files 122 | *.sage.py 123 | 124 | # Environments 125 | .env 126 | .venv 127 | env/ 128 | venv/ 129 | ENV/ 130 | env.bak/ 131 | venv.bak/ 132 | 133 | # Spyder project settings 134 | .spyderproject 135 | .spyproject 136 | 137 | # Rope project settings 138 | .ropeproject 139 | 140 | # mkdocs documentation 141 | /site 142 | 143 | # mypy 144 | .mypy_cache/ 145 | .dmypy.json 146 | dmypy.json 147 | 148 | # Pyre type checker 149 | .pyre/ 150 | 151 | # pytype static type analyzer 152 | .pytype/ 153 | 154 | # Cython debug symbols 155 | cython_debug/ 156 | 157 | # PyCharm 158 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 159 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 160 | # and can be added to the global gitignore or merged into this file. For a more nuclear 161 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 162 | #.idea/ 163 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Aana Application Template 2 | 3 | [Aana SDK](https://github.com/mobiusml/aana_sdk) is a powerful framework for building multimodal applications. It facilitates the large-scale deployment of machine learning models, including those for vision, audio, and language, and supports Retrieval-Augmented Generation (RAG) systems. This enables the development of advanced applications such as search engines, recommendation systems, and data insights platforms. 4 | 5 | This repository contains a template that you can use to start building your own Aana application. It will help you get started with the Aana SDK and provide you with a basic structure for your application and its dependencies. 6 | 7 | ## How to use this template 8 | 9 | 1. Click on [Use this template](https://github.com/mobiusml/aana_app_template/generate). 10 | 2. Give your repository a name and click on "Create repository". The name of the repository will also be the name of your application and the Python package. 11 | 3. Wait for the first workflow to finish. This will rename the package to match the repository name. 12 | 4. Clone the repository to your local machine and start building your application. 13 | 5. Change the [LICENSE](/LICENSE) file to match your project's license. The default license is the Apache License 2.0. 14 | 15 | ## Getting started 16 | 17 | The project template uses [Poetry](https://python-poetry.org/) for dependency management. To install the project, run the following commands: 18 | 19 | ```bash 20 | poetry install 21 | ``` 22 | 23 | See [Tutorial](https://mobiusml.github.io/aana_sdk/pages/tutorial/) for more information on how to build your application. 24 | 25 | ## Project structure 26 | 27 | ``` 28 | aana_app_project/ 29 | ├── config/ | various configs, including settings, deployments and endpoints 30 | │ ├── endpoints.py | list of endpoints to deploy 31 | │ ├── deployments.py | list of deployments (models) to deploy 32 | │ └── settings.py | app settings 33 | ├── core/ | core models and functionality 34 | │ ├── models/ | data models 35 | │ └── prompts/ | prompt templates for LLMs 36 | ├── deployments/ | custom deployments 37 | ├── endpoints/ | endpoint classes for the app 38 | ├── exceptions/ | custom exception classes 39 | ├── utils/ | various utility functionality 40 | └── app.py | main application file 41 | ``` 42 | 43 | 44 | ## Installation 45 | 46 | To install the project, follow these steps: 47 | 48 | 1. Clone the repository. 49 | 50 | 2. Install the package with Poetry. 51 | 52 | The project is managed with [Poetry](https://python-poetry.org/docs/). See the [Poetry installation instructions](https://python-poetry.org/docs/#installation) on how to install it on your system. 53 | 54 | It will install the package and all dependencies in a virtual environment. 55 | 56 | ```bash 57 | poetry install 58 | ``` 59 | 60 | 3. Install additional libraries. 61 | 62 | For optimal performance, you should also install [PyTorch](https://pytorch.org/get-started/locally/) version >=2.1 appropriate for your system. You can continue directly to the next step, but it will install a default version that may not make optimal use of your system's resources, for example, a GPU or even some SIMD operations. Therefore we recommend choosing your PyTorch package carefully and installing it manually. 63 | 64 | Some models use Flash Attention. Install Flash Attention library for better performance. See [flash attention installation instructions](https://github.com/Dao-AILab/flash-attention?tab=readme-ov-file#installation-and-features) for more details and supported GPUs. 65 | 66 | 67 | 4. Activate the Poetry environment. 68 | 69 | To activate the Poetry environment, run the following command: 70 | 71 | ```bash 72 | poetry shell 73 | ``` 74 | 75 | Alternatively, you can run commands in the Poetry environment by prefixing them with `poetry run`. For example: 76 | 77 | ```bash 78 | poetry run aana deploy aana_app_project.app:aana_app 79 | ``` 80 | 81 | 5. Run the app. 82 | 83 | ```bash 84 | aana deploy aana_app_project.app:aana_app 85 | ``` 86 | 87 | ## Usage 88 | 89 | To use the project, follow these steps: 90 | 91 | 1. Run the app as described in the installation section. 92 | 93 | ```bash 94 | aana deploy aana_app_project.app:aana_app 95 | ``` 96 | 97 | Once the application is running, you will see the message `Deployed successfully.` in the logs. It will also show the URL for the API documentation. 98 | 99 | > **⚠️ Warning** 100 | > 101 | > If the application is using GPU, make sure that the GPU is available and the application can access it. 102 | > 103 | > The applications will detect the available GPU automatically but you need to make sure that `CUDA_VISIBLE_DEVICES` is set correctly. 104 | > 105 | > Sometimes `CUDA_VISIBLE_DEVICES` is set to an empty string and the application will not be able to detect the GPU. Use `unset CUDA_VISIBLE_DEVICES` to unset the variable. 106 | > 107 | > You can also set the `CUDA_VISIBLE_DEVICES` environment variable to the GPU index you want to use: `export CUDA_VISIBLE_DEVICES=0`. 108 | 109 | 2. Send a POST request to the app. 110 | 111 | For example, if your application has `/summary` endpoint that accepts videos, you can send a POST request like this: 112 | 113 | ```bash 114 | curl -X POST http://127.0.0.1:8000/summary -Fbody='{"video":{"url":"https://www.youtube.com/watch?v=VhJFyyukAzA"}}' 115 | ``` 116 | 117 | ## Running with Docker 118 | 119 | We provide a docker-compose configuration to run the application in a Docker container. 120 | 121 | Requirements: 122 | 123 | - Docker Engine >= 26.1.0 124 | - Docker Compose >= 1.29.2 125 | - NVIDIA Driver >= 525.60.13 126 | 127 | To run the application, simply run the following command: 128 | 129 | ```bash 130 | docker-compose up 131 | ``` 132 | 133 | The application will be accessible at `http://localhost:8000` on the host server. 134 | 135 | 136 | > **⚠️ Warning** 137 | > 138 | > If your applications requires GPU to run, you need to specify which GPU to use. 139 | > 140 | > The applications will detect the available GPU automatically but you need to make sure that `CUDA_VISIBLE_DEVICES` is set correctly. 141 | > 142 | > Sometimes `CUDA_VISIBLE_DEVICES` is set to an empty string and the application will not be able to detect the GPU. Use `unset CUDA_VISIBLE_DEVICES` to unset the variable. 143 | > 144 | > You can also set the `CUDA_VISIBLE_DEVICES` environment variable to the GPU index you want to use: `CUDA_VISIBLE_DEVICES=0 docker-compose up`. 145 | 146 | 147 | > **💡Tip** 148 | > 149 | > Some models use Flash Attention for better performance. You can set the build argument `INSTALL_FLASH_ATTENTION` to `true` to install Flash Attention. 150 | > 151 | > ```bash 152 | > INSTALL_FLASH_ATTENTION=true docker-compose build 153 | > ``` 154 | > 155 | > After building the image, you can use `docker-compose up` command to run the application. 156 | > 157 | > You can also set the `INSTALL_FLASH_ATTENTION` environment variable to `true` in the `docker-compose.yaml` file. 158 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------