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

feat(openadapt.privacy.providers): add private_ai as a scrubbing provider #486

Merged
merged 57 commits into from
Nov 11, 2023

Conversation

KrishPatel13
Copy link
Collaborator

@KrishPatel13 KrishPatel13 commented Aug 29, 2023

What kind of change does this PR introduce?
Add PrivateAI as Scrubbing Provider.

Summary
Motivation: #418 (comment)

Checklist

  • My code follows the style guidelines of OpenAdapt
  • I have performed a self-review of my code
  • If applicable, I have added tests to prove my fix is functional/effective
  • I have linted my code locally prior to submission
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (e.g. README.md, requirements.txt)
  • New and existing unit tests pass locally with my changes

How can your code be run and tested?

Other information

@KrishPatel13 KrishPatel13 marked this pull request as ready for review August 30, 2023 03:12
@KrishPatel13
Copy link
Collaborator Author

Now, add tests for text, pdf and image scrubbing using private ai

@KrishPatel13
Copy link
Collaborator Author

Now, if there is some issue with PRIVATE_AI_API_KEY (not valid or not present) then all then tests in test_private_ai_scrub.py get skipped.

See how it will look:

(openadapt-py3.10) PS P:\OpenAdapt AI - MLDS AI\cloned_repo\my_forked\OpenAdapt> pytest .\tests\openadapt\privacy\providers\test_private_ai_scrub.py
=============================================================================================== test session starts ================================================================================================
platform win32 -- Python 3.10.11, pytest-7.1.3, pluggy-1.3.0
rootdir: P:\OpenAdapt AI - MLDS AI\cloned_repo\my_forked\OpenAdapt, configfile: pyproject.toml
plugins: anyio-3.7.1
collected 15 items

tests\openadapt\privacy\providers\test_private_ai_scrub.py sssssssssssssss                                                                                                                                    [100%]

=============================================================================================== 15 skipped in 0.44s ================================================================================================ 
(openadapt-py3.10) PS P:\OpenAdapt AI - MLDS AI\cloned_repo\my_forked\OpenAdapt> 

@KrishPatel13 KrishPatel13 self-assigned this Aug 30, 2023
@KrishPatel13 KrishPatel13 requested a review from abrichr August 30, 2023 19:53
@KrishPatel13 KrishPatel13 requested a review from abrichr September 1, 2023 00:21
@KrishPatel13
Copy link
Collaborator Author

@abrichr Addressed all of your comments!

Ready for merging

@KrishPatel13
Copy link
Collaborator Author

KrishPatel13 commented Sep 1, 2023

Once this is merged, please see: #418 (comment), #330 (comment)

@KrishPatel13
Copy link
Collaborator Author

@abrichr I have addressed your comments again, to use BytesIO wherever possible.

Here is how pytest looks like after all:

(openadapt-py3.10) PS P:\OpenAdapt AI - MLDS AI\cloned_repo\my_forked\OpenAdapt> pytest
==================================================== test session starts =====================================================
platform win32 -- Python 3.10.11, pytest-7.1.3, pluggy-1.3.0
rootdir: P:\OpenAdapt AI - MLDS AI\cloned_repo\my_forked\OpenAdapt, configfile: pyproject.toml
plugins: anyio-3.7.1
collected 60 items

tests\openadapt\test_crop.py .                                                                                          [  1%]
tests\openadapt\test_events.py .......                                                                                  [ 13%]
tests\openadapt\test_summary.py ..                                                                                      [ 16%]
tests\openadapt\privacy\test_providers.py .                                                                             [ 18%]
tests\openadapt\privacy\providers\test_comprehend_scrub.py ...............                                              [ 43%]
tests\openadapt\privacy\providers\test_presidio_scrub.py .................                                                                      [ 71%]
tests\openadapt\privacy\providers\test_private_ai_scrub.py .................                                                                    [100%]

================================================================== warnings summary ==================================================================
tests/openadapt/privacy/providers/test_presidio_scrub.py::test_scrub_image
  C:\Users\Krish Patel\AppData\Local\pypoetry\Cache\virtualenvs\openadapt-vs6jmx3S-py3.10\lib\site-packages\pytesseract\pytesseract.py:382: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
    return LooseVersion(

tests/openadapt/privacy/providers/test_presidio_scrub.py::test_scrub_image
  C:\Users\Krish Patel\AppData\Local\pypoetry\Cache\virtualenvs\openadapt-vs6jmx3S-py3.10\lib\site-packages\setuptools\_distutils\version.py:345: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
    other = LooseVersion(other)

tests/openadapt/privacy/providers/test_private_ai_scrub.py::test_image_redaction
tests/openadapt/privacy/providers/test_private_ai_scrub.py::test_image_redaction
tests/openadapt/privacy/providers/test_private_ai_scrub.py::test_image_redaction
tests/openadapt/privacy/providers/test_private_ai_scrub.py::test_image_redaction
  C:\Users\Krish Patel\AppData\Local\pypoetry\Cache\virtualenvs\openadapt-vs6jmx3S-py3.10\lib\site-packages\easyocr\utils.py:576: DeprecationWarning: ANTIALIAS is deprecated and will be removed in Pillow 10 (2023-07-01). Use LANCZOS or Resampling.LANCZOS instead.
    img = cv2.resize(img,(int(model_height*ratio),model_height),interpolation=Image.ANTIALIAS)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
===================================================== 60 passed, 6 warnings in 280.52s (0:04:40) ===================================================== 
(openadapt-py3.10) PS P:\OpenAdapt AI - MLDS AI\cloned_repo\my_forked\OpenAdapt> 

Ready for merging!

Copy link
Member

@abrichr abrichr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@abrichr abrichr merged commit 396bbb5 into OpenAdaptAI:main Nov 11, 2023
1 check passed
@abrichr abrichr deleted the feat/private_ai branch November 11, 2023 16:27
R-ohit-B-isht pushed a commit to R-ohit-B-isht/OpenAdapt that referenced this pull request Jun 21, 2024
…ider (OpenAdaptAI#486)

* ran black

* add blank file for priavte ai

* add class `PrivateAIScrubbingProvider`

* add pvt_ai api key in config

* ran `pre-commit run --all`

* add scrub_text function

* progress for image redaction

* format

* complete scrub_image

* start scrub_pdf

* add pdf redaction code

* add more wrapper for invalid reponse from priavate ai

* try to fix pytest

* try to fix pytest

* remove lst

* remove uncessary methods

* text scrubbing test all passses

* pdf_redaction test works

* add test_image_redaction test in pyetst

* add easy ocr to poetry

* pytest is fixed

* remove versino files

* remove un-neccasry files

* add code to remove uncessary files after pytest

* addressed OpenAdaptAI#486 (comment)

* address comment OpenAdaptAI#486 (comment)

* reduce line chars

* addressed comment: OpenAdaptAI#486 (comment)

* fix flake8

* use f strings

* address comment: OpenAdaptAI#486 (comment)

* address comment: OpenAdaptAI#486 (comment)

* change to value error

* remove .keys()

* add constants

* fix flake8 erros

* use BytesIO

* address comment OpenAdaptAI#486 (comment)

* rna black

* final commit

* remove unused code

* refactor typo

* rename `redact_file_path` to `redacted_file_path`

* use BytesIO wherever possible

* fix flake8

* add documentation links

* Apply suggestions from code review

* Update tests/openadapt/privacy/providers/test_private_ai_scrub.py

* fix poetry.lock

* poetry.lock

---------

Co-authored-by: Krish Patel <[email protected]>
Co-authored-by: Richard Abrich <[email protected]>
Co-authored-by: Richard Abrich <[email protected]>
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.

2 participants