Skip to content

Commit

Permalink
add execution time
Browse files Browse the repository at this point in the history
  • Loading branch information
jonafeucht committed Jun 11, 2024
1 parent cbff51a commit dd89dbf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@ jobs:
matrix:
include:
- docker_file: Dockerfile
tag-suffix: cpu
latest-tag: latest
label: "latest"
- docker_file: Dockerfile.cuda
tag-suffix: cuda
latest-tag: latest-cuda
label: "cuda"
label: "latest-cuda"
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -62,6 +58,7 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: |
${{ steps.meta.outputs.tags }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.latest-tag }}
${{ matrix.docker_file == 'Dockerfile' && matrix.label == 'latest' && env.REGISTRY }}/{{ env.IMAGE_NAME }}:latest
${{ matrix.docker_file == 'Dockerfile.cuda' && matrix.label == 'latest-cuda' && env.REGISTRY }}/{{ env.IMAGE_NAME }}:latest-cuda
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
7 changes: 6 additions & 1 deletion src/routes/api/summarization.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from fastapi import APIRouter, Query, Depends
from src.middleware.auth.auth import get_api_key
from src.shared.shared import summarization_model
import time

router = APIRouter()

Expand All @@ -10,10 +11,14 @@ async def summarization(
text: str,
model_name: str = Query(None),
):
start_time = time.time()
summarizer = summarization_model(model_name)
try:
summary = summarizer(text)
return {"res": summary}
return {
"execution_time": time.time() - start_time,
"res": summary,
}

except Exception as e:
print("Something went wrong: ", e)
Expand Down
7 changes: 6 additions & 1 deletion src/routes/api/translation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from fastapi import APIRouter, Query, Depends
from src.middleware.auth.auth import get_api_key
from src.shared.shared import translation_model
import time

router = APIRouter()

Expand All @@ -12,11 +13,15 @@ async def translation(
input_language: str = Query("en", description="Input language"),
output_language: str = Query("de", description="Output language"),
):
start_time = time.time()
translator = translation_model(model_name, input_language, output_language)

try:
translation = translator(text)
return {"res": translation}
return {
"execution_time": time.time() - start_time,
"res": translation,
}

except Exception as e:
print("Something went wrong: ", e)
Expand Down

0 comments on commit dd89dbf

Please sign in to comment.