Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐞Modify the import structure of models that don't rely on core requirements. #2408

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

harimkang
Copy link
Collaborator

📝 Description

This PR modifies anomalib to check if the python-dotenv package is available and import the required VlmAd model.

Issue:
python-dotenv is not included in core dependencies, so if only have core installed and using it, we will not be able to import VlmAd.
This will be imported and cause an error even if the user using core only does not use VlmAd.

pip install anomalib[core]==1.2.0
from anomalib.models.image import Padim

Traceback (most recent call last):
  File "/home/harimkan/workspace/repo/otx-regression/api_test_2.py", line 1, in <module>
    from anomalib.models.image import Padim
  File "/home/harimkan/workspace/repo/otx-regression/venv/lib/python3.10/site-packages/anomalib/models/__init__.py", line 15, in <module>
    from .image import (
  File "/home/harimkan/workspace/repo/otx-regression/venv/lib/python3.10/site-packages/anomalib/models/image/__init__.py", line 23, in <module>
    from .vlm_ad import VlmAd
  File "/home/harimkan/workspace/repo/otx-regression/venv/lib/python3.10/site-packages/anomalib/models/image/vlm_ad/__init__.py", line 6, in <module>
    from .lightning_model import VlmAd
  File "/home/harimkan/workspace/repo/otx-regression/venv/lib/python3.10/site-packages/anomalib/models/image/vlm_ad/lightning_model.py", line 14, in <module>
    from .backends import Backend, ChatGPT, Huggingface, Ollama
  File "/home/harimkan/workspace/repo/otx-regression/venv/lib/python3.10/site-packages/anomalib/models/image/vlm_ad/backends/__init__.py", line 7, in <module>
    from .chat_gpt import ChatGPT
  File "/home/harimkan/workspace/repo/otx-regression/venv/lib/python3.10/site-packages/anomalib/models/image/vlm_ad/backends/chat_gpt.py", line 12, in <module>
    from dotenv import load_dotenv
ModuleNotFoundError: No module named 'dotenv'

✨ Changes

Select what type of change your PR is:

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • 🔨 Refactor (non-breaking change which refactors the code base)
  • 🚀 New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🔒 Security update

✅ Checklist

Before you submit your pull request, please make sure you have completed the following steps:

  • 📋 I have summarized my changes in the CHANGELOG and followed the guidelines for my type of change (skip for minor changes, documentation updates, and test enhancements).
  • 📚 I have made the necessary updates to the documentation (if applicable).
  • 🧪 I have written tests that support my changes and prove that my fix is effective or my feature works (if applicable).

For more information about code review checklists, see the Code Review Checklist.

… in the import.

Signed-off-by: Kang, Harim <harim.kang@intel.com>
Signed-off-by: Kang, Harim <harim.kang@intel.com>
@harimkang
Copy link
Collaborator Author

harimkang commented Nov 5, 2024

@samet-akcay In fact, we have a way of raising python-dotenv to core rather than doing something as messy as this PR. What do you think?

@samet-akcay
Copy link
Contributor

@harimkang, good find! Thanks for reporting and fixing!

@ashwinvaidya17 is python-dotenv only used within VlmAd stuff?

@ashwinvaidya17
Copy link
Collaborator

@harimkang, good find! Thanks for reporting and fixing!

@ashwinvaidya17 is python-dotenv only used within VlmAd stuff?

Yeah it is only used on VlmAd so that we can fetch the API key from either the dot file or the system environment.

@samet-akcay
Copy link
Contributor

samet-akcay commented Nov 5, 2024

@harimkang, there are some other model-specific packages that are only used by individual models. I would like to keep the core dependencies as minimum as possible. Your approach here would be useful for such models too.

I was wondering if there is any way to make this approach more generic, so we could use it for other models or imports as well. --Not for this PR though, something to think about for the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants