File size: 2,820 Bytes
4f2513f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de50fb2
4f2513f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3fad690
 
 
4f2513f
 
 
 
3fad690
 
4f2513f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d0fbd88
4f2513f
f5a891f
 
 
 
 
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# ─── Stage 1: builder ──-
FROM python:3.13-slim

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
ENV LIBTORCH_URL=https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-2.0.0%2Bcpu.zip
ENV PROTOBUF_VERSION=3.13.0

# Install system dependencies
RUN apt-get update && \
    apt-get install -y \
    git \
    curl \
    unzip \
    build-essential \
    cmake \
    dos2unix \
    bash \
    cmake \
    make \
    libtorch-dev \
    && rm -rf /var/lib/apt/lists/*

# install protobuf
WORKDIR /tmp
RUN curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-cpp-3.13.0.tar.gz && \
    tar --no-same-owner -xzf protobuf-cpp-${PROTOBUF_VERSION}.tar.gz && \
    cd protobuf-${PROTOBUF_VERSION} && \
    ./configure && make -j$(nproc) && make install && ldconfig

# Copy the needed folders for inference only
RUN mkdir -p /build

# Set working directory to MIDI-GPT
WORKDIR /build

COPY pip_requirements pip_requirements
COPY libraries libraries

COPY src src
COPY include include
COPY CMakeLists.txt /build/CMakeLists.txt
COPY models models
RUN unzip models/model.zip -d models


# Install Python dependencies
RUN pip install --no-cache-dir -r pip_requirements/common_requirements.txt

# Download and unpack libtorch
RUN mkdir -p libraries/libtorch && \
    curl -L ${LIBTORCH_URL} -o libtorch.zip && \
    unzip -q libtorch.zip -d libraries/ && \
    rm libtorch.zip

# Clone pybind11 (overwrite if exists)
RUN rm -rf libraries/pybind11 && \
    git clone https://github.com/pybind/pybind11.git libraries/pybind11 && \
    cd libraries/pybind11 && \
    git reset --hard 5ccb9e4

# Clone midifile
RUN rm -rf libraries/midifile && \
    git clone https://github.com/craigsapp/midifile libraries/midifile && \
    cd libraries/midifile && \
    git reset --hard 838c62c

# Compile protobuf definitions
RUN mkdir -p libraries/protobuf/build && \
    protoc --proto_path=libraries/protobuf/src --cpp_out=libraries/protobuf/build libraries/protobuf/src/*.proto

RUN cp -r /build/libraries/libtorch /opt/
ENV TORCH_DIR=/opt/libtorch
ENV LD_LIBRARY_PATH=$TORCH_DIR/lib:$LD_LIBRARY_PATH

# Build the C++ Python extension
RUN mkdir -p python_lib && \
    cd python_lib && \
    cmake .. -DCMAKE_PREFIX_PATH=$TORCH_DIR && \
    make


WORKDIR /app
# Copy the compiled C++ extension and models from the builder stage

RUN cp -r /build/python_lib python_lib
RUN cp -r /build/models models

ENV PYTHONPATH=/app/python_lib
RUN rm -rf /build
RUN python3 -c "import midigpt; print('βœ… midigpt built and importable')"

RUN python3 -m pip install --no-cache-dir gradio

#CMD ["/bin/bash"]
COPY python_scripts_for_testing/ /app/python_scripts_for_testing
EXPOSE 7860
WORKDIR /app/python_scripts_for_testing
ENTRYPOINT [ "python", "gradio_app.py" ]