Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Upgrading asteroid image. #175

Merged
merged 1 commit into from
Jul 9, 2021
Merged
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
25 changes: 17 additions & 8 deletions api-inference-community/docker_images/asteroid/app/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import functools
import logging
import os
from typing import Dict, Type
Expand Down Expand Up @@ -37,7 +38,10 @@
}


def get_pipeline(task: str, model_id: str) -> Pipeline:
@functools.lru_cache()
def get_pipeline() -> Pipeline:
task = os.environ["TASK"]
model_id = os.environ["MODEL_ID"]
if task not in ALLOWED_TASKS:
raise EnvironmentError(f"{task} is not a valid pipeline for model : {model_id}")
return ALLOWED_TASKS[task](model_id)
Expand Down Expand Up @@ -71,13 +75,18 @@ async def startup_event():
handler.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(message)s"))
logger.handlers = [handler]

task = os.environ["TASK"]
model_id = os.environ["MODEL_ID"]
app.pipeline = get_pipeline(task, model_id)
# Link between `api-inference-community` and framework code.
app.get_pipeline = get_pipeline
try:
get_pipeline()
except Exception:
# We can fail so we can show exception later.
pass


if __name__ == "__main__":
task = os.environ["TASK"]
model_id = os.environ["MODEL_ID"]

get_pipeline(task, model_id)
try:
get_pipeline()
except Exception:
# We can fail so we can show exception later.
pass
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
starlette==0.14.2
api-inference-community==0.0.7
api-inference-community==0.0.9
asteroid==0.4.4