kostis-init commited on
Commit
34e8992
Β·
1 Parent(s): 308cfba

change to docker

Browse files
Files changed (8) hide show
  1. .gitattributes +0 -35
  2. .pre-commit-config.yaml +0 -53
  3. Dockerfile +31 -0
  4. Makefile +0 -13
  5. README.md +3 -3
  6. app.py +12 -38
  7. pyproject.toml +0 -13
  8. setup.sh +15 -11
.gitattributes DELETED
@@ -1,35 +0,0 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tflite filter=lfs diff=lfs merge=lfs -text
29
- *.tgz filter=lfs diff=lfs merge=lfs -text
30
- *.wasm filter=lfs diff=lfs merge=lfs -text
31
- *.xz filter=lfs diff=lfs merge=lfs -text
32
- *.zip filter=lfs diff=lfs merge=lfs -text
33
- *.zst filter=lfs diff=lfs merge=lfs -text
34
- *tfevents* filter=lfs diff=lfs merge=lfs -text
35
- scale-hf-logo.png filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.pre-commit-config.yaml DELETED
@@ -1,53 +0,0 @@
1
- # Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- default_language_version:
16
- python: python3
17
-
18
- ci:
19
- autofix_prs: true
20
- autoupdate_commit_msg: '[pre-commit.ci] pre-commit suggestions'
21
- autoupdate_schedule: quarterly
22
-
23
- repos:
24
- - repo: https://github.com/pre-commit/pre-commit-hooks
25
- rev: v4.3.0
26
- hooks:
27
- - id: check-yaml
28
- - id: check-case-conflict
29
- - id: detect-private-key
30
- - id: check-added-large-files
31
- args: ['--maxkb=1000']
32
- - id: requirements-txt-fixer
33
- - id: end-of-file-fixer
34
- - id: trailing-whitespace
35
-
36
- - repo: https://github.com/PyCQA/isort
37
- rev: 5.12.0
38
- hooks:
39
- - id: isort
40
- name: Format imports
41
-
42
- - repo: https://github.com/psf/black
43
- rev: 22.12.0
44
- hooks:
45
- - id: black
46
- name: Format code
47
- additional_dependencies: ['click==8.0.2']
48
-
49
- - repo: https://github.com/charliermarsh/ruff-pre-commit
50
- # Ruff version.
51
- rev: 'v0.0.267'
52
- hooks:
53
- - id: ruff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Dockerfile ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Start from a base Python image
2
+ FROM python:3.12-slim
3
+
4
+ # Set the working directory in the container
5
+ WORKDIR /app
6
+
7
+ # Copy your setup script and application files
8
+ COPY setup.sh .
9
+ COPY requirements.txt .
10
+ COPY app.py .
11
+ COPY src/ ./src/
12
+
13
+ # Make setup.sh executable and run it
14
+ # This is where MiniZinc will be installed
15
+ RUN chmod +x setup.sh && ./setup.sh
16
+
17
+ # Install Python dependencies
18
+ RUN pip install --no-cache-dir -r requirements.txt
19
+
20
+ # The MiniZinc installation in setup.sh exports PATH,
21
+ # but that only applies to the RUN layer.
22
+ # We need to ensure the PATH is set for the runtime environment of the app.
23
+ ENV MZN_DIR=/opt/minizinc
24
+ ENV PATH="${MZN_DIR}/bin:${PATH}"
25
+ # If MiniZinc has shared libraries in MZN_DIR/lib that are needed at runtime:
26
+ ENV LD_LIBRARY_PATH="${MZN_DIR}/lib:${LD_LIBRARY_PATH}"
27
+
28
+ # Expose the port Gradio runs on (default is 7860)
29
+ EXPOSE 7860
30
+
31
+ CMD ["python", "app.py"]
Makefile DELETED
@@ -1,13 +0,0 @@
1
- .PHONY: style format
2
-
3
-
4
- style:
5
- python -m black --line-length 119 .
6
- python -m isort .
7
- ruff check --fix .
8
-
9
-
10
- quality:
11
- python -m black --check --line-length 119 .
12
- python -m isort --check-only .
13
- ruff check .
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md CHANGED
@@ -3,9 +3,9 @@ title: CP Bench Competition
3
  emoji: πŸ₯‡
4
  colorFrom: green
5
  colorTo: indigo
6
- sdk: gradio
7
- sdk_version: 5.30.0
8
- python_version: 3.12
9
  app_file: app.py
10
  pinned: true
11
  license: apache-2.0
 
3
  emoji: πŸ₯‡
4
  colorFrom: green
5
  colorTo: indigo
6
+ sdk: docker
7
+ #sdk_version: 5.30.0
8
+ #python_version: 3.12
9
  app_file: app.py
10
  pinned: true
11
  license: apache-2.0
app.py CHANGED
@@ -1,48 +1,22 @@
1
  from src.ui import create_ui
2
-
3
  import os
4
  import subprocess
5
- import urllib.request
6
- import tarfile
7
-
8
- def install_minizinc():
9
- install_path = "/home/user/minizinc"
10
- if os.path.exists(os.path.join(install_path, "bin", "minizinc")):
11
- print("βœ… MiniZinc already installed.")
12
- return
13
-
14
- print("⬇️ Downloading MiniZinc...")
15
- url = "https://github.com/MiniZinc/MiniZincIDE/releases/download/2.9.0/MiniZincIDE-2.9.0-bundle-linux-x86_64.tgz"
16
- bundle_path = "/tmp/minizinc.tgz"
17
-
18
- urllib.request.urlretrieve(url, bundle_path)
19
-
20
- print("πŸ“¦ Extracting MiniZinc...")
21
- os.makedirs(install_path, exist_ok=True)
22
- with tarfile.open(bundle_path, "r:gz") as tar:
23
- tar.extractall(path=install_path, members=_strip_top_level(tar))
24
 
25
- print("βœ… MiniZinc installed.")
26
-
27
- def _strip_top_level(tar):
28
- # Removes top-level folder when extracting
29
- top_level = tar.getmembers()[0].name.split('/')[0]
30
- for member in tar.getmembers():
31
- member.path = '/'.join(member.path.split('/')[1:])
32
- yield member
33
 
34
- # Install and patch env
35
- install_minizinc()
36
- os.environ["PATH"] = f"/home/user/minizinc/bin:{os.environ['PATH']}"
37
 
38
- # Check it works
39
- try:
40
- version = subprocess.check_output(["minizinc", "--version"], text=True)
41
- print("🧠 MiniZinc version:", version.strip())
42
  except Exception as e:
43
- print("❌ MiniZinc install failed:", e)
44
-
45
 
46
  if __name__ == "__main__":
47
  demo = create_ui()
48
- demo.queue().launch()
 
1
  from src.ui import create_ui
 
2
  import os
3
  import subprocess
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
+ try:
6
+ version = subprocess.check_output(["minizinc", "--version"], text=True, stderr=subprocess.STDOUT)
7
+ print(f"🧠 MiniZinc version (from Docker env): {version.strip()}")
 
 
 
 
 
8
 
9
+ # Optional: Check for solvers to confirm full setup
10
+ solvers = subprocess.check_output(["minizinc", "--solvers"], text=True, stderr=subprocess.STDOUT)
11
+ print(f"πŸ’‘ MiniZinc solvers (from Docker env):\n{solvers.strip()}")
12
 
13
+ except FileNotFoundError:
14
+ print("❌ MiniZinc command not found. Check PATH in Dockerfile and setup.sh.")
15
+ except subprocess.CalledProcessError as e:
16
+ print(f"❌ MiniZinc command failed. Output: {e.output}")
17
  except Exception as e:
18
+ print(f"❌ Error checking MiniZinc: {e}")
 
19
 
20
  if __name__ == "__main__":
21
  demo = create_ui()
22
+ demo.queue().launch() # HF Spaces usually uses port 7860 by default
pyproject.toml DELETED
@@ -1,13 +0,0 @@
1
- [tool.ruff]
2
- # Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default.
3
- select = ["E", "F"]
4
- ignore = ["E501"] # line too long (black is taking care of this)
5
- line-length = 119
6
- fixable = ["A", "B", "C", "D", "E", "F", "G", "I", "N", "Q", "S", "T", "W", "ANN", "ARG", "BLE", "COM", "DJ", "DTZ", "EM", "ERA", "EXE", "FBT", "ICN", "INP", "ISC", "NPY", "PD", "PGH", "PIE", "PL", "PT", "PTH", "PYI", "RET", "RSE", "RUF", "SIM", "SLF", "TCH", "TID", "TRY", "UP", "YTT"]
7
-
8
- [tool.isort]
9
- profile = "black"
10
- line_length = 119
11
-
12
- [tool.black]
13
- line-length = 119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
setup.sh CHANGED
@@ -4,18 +4,22 @@
4
  set -e
5
 
6
  # Define version and paths
7
- VERSION=2.9.3
8
- MZN_DIR=/home/user/minizinc
9
 
10
- # Download and extract MiniZinc
11
- wget https://github.com/MiniZinc/MiniZincIDE/releases/download/${VERSION}/MiniZincIDE-${VERSION}-bundle-linux-x86_64.tgz
12
  mkdir -p $MZN_DIR
13
- tar -xzf MiniZincIDE-${VERSION}-bundle-linux-x86_64.tgz -C $MZN_DIR --strip-components=1
14
- rm MiniZincIDE-${VERSION}-bundle-linux-x86_64.tgz
15
 
16
- # Export path for the runtime
17
- echo "export PATH=$MZN_DIR/bin:\$PATH" >> ~/.bashrc
18
- echo "export PATH=$MZN_DIR/bin:\$PATH" >> ~/.profile
19
- export PATH=$MZN_DIR/bin:$PATH
20
 
21
- echo "βœ… setup.sh finished running" > setup_log.txt
 
 
 
 
 
 
 
 
 
 
 
4
  set -e
5
 
6
  # Define version and paths
7
+ VERSION=2.9.3 # Or make this an ARG in Dockerfile if you want to change it easily
8
+ MZN_DIR=/opt/minizinc # This path is used in the Dockerfile ENV
9
 
 
 
10
  mkdir -p $MZN_DIR
 
 
11
 
12
+ echo "Downloading MiniZinc ${VERSION}..."
13
+ wget -q https://github.com/MiniZinc/MiniZincIDE/releases/download/${VERSION}/MiniZincIDE-${VERSION}-bundle-linux-x86_64.tgz -O MiniZincIDE.tgz
 
 
14
 
15
+ echo "Extracting MiniZinc to ${MZN_DIR}..."
16
+ tar -xzf MiniZincIDE.tgz -C $MZN_DIR --strip-components=1
17
+
18
+ echo "Cleaning up downloaded archive..."
19
+ rm MiniZincIDE.tgz
20
+
21
+ # Ensure binaries are executable (good practice)
22
+ chmod -R +x ${MZN_DIR}/bin || true # Allow to fail if no bin dir yet, though it should exist.
23
+ chmod -R +x ${MZN_DIR}/share/minizinc/solvers || true # Some solvers might be scripts
24
+
25
+ echo "βœ… setup.sh finished installing MiniZinc to ${MZN_DIR}" > setup_log.txt