-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathDockerfile.gpu
More file actions
62 lines (43 loc) · 1.62 KB
/
Copy pathDockerfile.gpu
File metadata and controls
62 lines (43 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Run e.g. with docker build -t homr . && docker run --gpus all --rm -p 8080:8000 homr
# And then send images: curl -X POST -F "file=@tabi.jpg" http://localhost:8080/process --output tabi.musicxml
FROM python:3.11
WORKDIR /app
RUN apt update && apt install -y libgl1
RUN curl -sSL https://install.python-poetry.org | python3 -
RUN git clone https://github.com/liebharc/homr .
RUN /root/.local/bin/poetry install --only main,gpu
RUN /root/.local/bin/poetry run pip install --no-cache-dir fastapi uvicorn python-multipart "onnxruntime-gpu[cuda,cudnn]==1.24.1"
# Pre-download models
RUN /root/.local/bin/poetry run python homr/main.py --init
# Generate FastAPI app inline
RUN cat <<'EOF' > api.py
from fastapi import FastAPI, UploadFile, File, BackgroundTasks
from fastapi.responses import FileResponse
import subprocess
import tempfile
import os
import shutil
app = FastAPI()
@app.post("/process")
def process_image(
file: UploadFile = File(...),
background_tasks: BackgroundTasks = BackgroundTasks(),
):
tmpdir = tempfile.mkdtemp()
input_path = os.path.join(tmpdir, file.filename)
with open(input_path, "wb") as f:
shutil.copyfileobj(file.file, f)
subprocess.check_call([
"python", "homr/main.py", input_path
])
base, _ = os.path.splitext(input_path)
output_path = base + ".musicxml"
background_tasks.add_task(shutil.rmtree, tmpdir)
return FileResponse(
output_path,
media_type="application/xml",
filename=os.path.basename(output_path),
)
EOF
EXPOSE 8000
CMD ["/root/.local/bin/poetry", "run", "uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8000"]