Skip to content
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
46 changes: 46 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Git
.git
.gitignore

# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# Virtual Environment
venv/
ENV/

# IDE
.idea/
.vscode/
*.swp
*.swo

# Docker
Dockerfile
.dockerignore

# Logs
*.log

# Local development
.env
.env.local
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:

- name: Run tests
run: |
pytest tests/
pytest tests/ --ignore=tests/manual
15 changes: 12 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@ FROM python:3.11-slim
# Set working directory
WORKDIR /app

# Copy project files
COPY . .
# Install system dependencies required for OpenCV
RUN apt-get update && apt-get install -y \
libgl1-mesa-glx \
libglib2.0-0 \
&& rm -rf /var/lib/apt/lists/*

# Copy only requirements first to leverage Docker cache
COPY requirements.txt .

# Install dependencies
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application
COPY . .

# Expose the port the app runs on
EXPOSE 5000

Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ train:
python app/model/train_color_model.py

test:
pytest tests/
pytest tests/ --ignore=tests/manual

coverage:
coverage run -m pytest tests/
coverage run -m pytest tests/ --ignore=tests/manual
coverage report
coverage html

docker-test:
docker build -t rubik-api .
docker run --rm rubik-api pytest tests/
docker run --rm rubik-api pytest tests/ --ignore=tests/manual
4 changes: 0 additions & 4 deletions app/cube_recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
import numpy as np
from .color_detection import detect_colors

# Rubik's cube face labels in standard order
FACE_ORDER = ['U', 'R', 'F', 'D', 'L', 'B']


def generate_cube_string(images):
cube_string = ''

Expand Down
4 changes: 4 additions & 0 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

main = Blueprint('main', __name__)

@main.route('/', methods=['GET'])
def health_check():
return jsonify({'status': 'API is running'}), 200

@main.route('/cubeFacesToCubeString', methods=['POST'])
def upload_faces():
if 'images' not in request.files:
Expand Down
2 changes: 1 addition & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
app = create_app()

if __name__ == '__main__':
app.run(debug=True)
app.run(host='0.0.0.0', debug=True)
Binary file added tests/images/back.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/images/down.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/images/front.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/images/left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/images/right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/images/up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions tests/manual/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import requests
import os

def test_api():
url = 'http://localhost:5000/cubeFacesToCubeString'

image_files = [
'tests/images/up.png',
'tests/images/right.png',
'tests/images/front.png',
'tests/images/down.png',
'tests/images/left.png',
'tests/images/back.png'
]

for img_file in image_files:
if not os.path.exists(img_file):
print(f"Erreur: Le fichier {img_file} n'existe pas")
return

files = []
for img_file in image_files:
files.append(('images', (os.path.basename(img_file), open(img_file, 'rb'), 'image/png')))

try:
response = requests.post(url, files=files)

if response.status_code == 200:
result = response.json()
print("Succès! Réponse de l'API:")
print(f"Cube string: {result.get('cube_string')}")
else:
print(f"Erreur: {response.status_code}")
print(response.text)

except requests.exceptions.RequestException as e:
print(f"Erreur de connexion: {e}")
assert False, f"API connection failed: {e}"

finally:
for _, (_, file, _) in files:
file.close()
Comment thread
quentinformatique marked this conversation as resolved.

if __name__ == '__main__':
test_api()