Skip to content
Merged
7 changes: 6 additions & 1 deletion flaskml_migration_steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ poetry run python src/text-summary/text_summary/main.py /text_summarization/summ

poetry run python src/text-summary/text_summary/main.py /text_summarization/summarize/task_schema
```
16. Add tests for your app in src/<project_dir>/tests. You can use the tests in src/audio-transcription/tests as a reference.
16. Add tests for your app in src/<project_dir>/tests. You can use the tests in src/audio-transcription/tests as a reference. Extend the rb.lib.common_tests.RBAppTest class to test your app. RBAppTest automatically tests the routes, app metadata, and task schema in both the command line and the API. Add additional tests to test the ML service in your app. Refer to the following files for examples to learn from:
```
src/audio-transcription/tests/test_main.py
src/text-summary/tests/test_main_text_summary.py
src/age_and_gender_detection/tests/test_main_age_gender.py
```
17. Make sure all the tests pass and the Github Actions workflow is successful. Refer to .github/workflows/ for the workflow files.
18. Send your pull request for review. Someone from the team will review your code and provide feedback. The PR requires at least one approval from a team member before it can be merged.

This file was deleted.

5 changes: 2 additions & 3 deletions src/age_and_gender_detection/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ license = {text = "MIT License"}
readme = "README.md"
dependencies = [
"numpy",
"onnxruntime (==1.21.0)",
"opencv-python (>=4.11.0.86,<5.0.0.0)",
"flask-ml (>=0.2.5,<0.3.0)"
"onnxruntime",
"opencv-python"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

So you have to put * here and put a version in the project root again so that everybody knows what versions are being used and if there is a project level conflict, then it gets resolved there

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done.

]


Expand Down
21 changes: 13 additions & 8 deletions src/age_and_gender_detection/tests/test_main_age_gender.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ def filter(self, record):
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
)

TEST_IMAGES_DIR = Path("src/age_and_gender_detection/test_images")

EXPECTED_OUTPUT = {
"src/age_and_gender_detection/test_images/bella.jpg": [
str(TEST_IMAGES_DIR / "bella.jpg"): [
{"box": [246, 257, 847, 858], "gender": "Female", "age": "(25-32)"}
],
"src/age_and_gender_detection/test_images/bruce.jpg": [
str(TEST_IMAGES_DIR / "bruce.jpg"): [
{"box": [51, 122, 328, 399], "gender": "Male", "age": "(25-32)"}
],
"src/age_and_gender_detection/test_images/baby.jpg": [
str(TEST_IMAGES_DIR / "baby.jpg"): [
{"box": [345, 217, 592, 464], "gender": "Female", "age": "(0-2)"}
],
"src/age_and_gender_detection/test_images/kid.jpg": [
str(TEST_IMAGES_DIR / "kid.jpg"): [
{"box": [476, 143, 696, 364], "gender": "Male", "age": "(4-6)"}
],
}
Expand Down Expand Up @@ -79,10 +81,13 @@ def test_age_gender_command(self, caplog):
result = self.runner.invoke(self.cli_app, [age_gender_api, str(input_path)])
assert result.exit_code == 0, f"Error: {result.output}"
expected_files = [
"src/age_and_gender_detection/test_images/bella.jpg",
"src/age_and_gender_detection/test_images/bruce.jpg",
"src/age_and_gender_detection/test_images/baby.jpg",
"src/age_and_gender_detection/test_images/kid.jpg",
str(Path(s))
for s in [
"src/age_and_gender_detection/test_images/bella.jpg",
"src/age_and_gender_detection/test_images/bruce.jpg",
"src/age_and_gender_detection/test_images/baby.jpg",
"src/age_and_gender_detection/test_images/kid.jpg",
]
]
for expected_file in expected_files:
assert any(expected_file in message for message in caplog.messages)
Expand Down
5 changes: 2 additions & 3 deletions src/text-summary/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ authors = [
license = {text = "MIT"}
readme = "README.md"
dependencies = [
"ollama (>=0.4.7,<0.5.0)",
"pypdf2 (>=3.0.1,<4.0.0)",
"flask-ml (>=0.2.5,<0.3.0)"
"ollama",
"pypdf2"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same as above comment.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done.

]


Expand Down
2 changes: 1 addition & 1 deletion src/text-summary/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_ensure_model_exists(mock_pull):

# Test case where pull fails
mock_pull.return_value = MagicMock(status="failure")
with pytest.raises(RuntimeError, match="Failed to pull model 'gemma3:1b':"):
with pytest.raises(ValueError, match="Failed to pull model 'gemma3:1b':"):
ensure_model_exists("gemma3:1b")


Expand Down
23 changes: 0 additions & 23 deletions src/text-summary/text_summary/cli.py

This file was deleted.

7 changes: 5 additions & 2 deletions src/text-summary/text_summary/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ def ensure_model_exists(model: str) -> None:
raise ValueError(
f"Model '{model}' is not supported. Supported models are: {SUPPORTED_MODELS}"
)
response = ollama.pull(model)
try:
response = ollama.pull(model)
except ollama.ResponseError as e:
raise ValueError(e.error)
if response.status != "success":
raise RuntimeError(f"Failed to pull model '{model}': {response}")
raise ValueError(f"Failed to pull model '{model}': {response}")


def summarize(model: str, text: str) -> str:
Expand Down