Skip to content

Commit

Permalink
changed summmary.py logic (#121)
Browse files Browse the repository at this point in the history
* changed summmary.py logic

* fixing test_summary

* added macos for testing

* fixed_display_test

* fixed docs and exceptions

* added dropout menu for summary

* added new SummaryDetector to AnalysisExplorer

* bug fixing

* code improving

* fixed test_display

* fixed code smells

* reduce tests for macos

* added some tests and exceptions for summary init

* changed CI, runs pytest independently

* exclude test_analysisExplorer from macos in CI

* moved some tests from test_init_summary to test_advanced_init_summary and mark them as long

---------

Co-authored-by: Inga Ulusoy <[email protected]>
  • Loading branch information
piterand and iulusoy committed Jun 27, 2023
1 parent e69e459 commit 5ff5a4f
Show file tree
Hide file tree
Showing 7 changed files with 371 additions and 57 deletions.
38 changes: 32 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,42 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install -e .
- name: Run pytest linux (linux-only)
if: matrix.os == 'ubuntu-22.04'
- name: Run pytest test_colors
run: |
cd ammico
python -m pytest -m "not gcv and not long" -svv --cov=. --cov-report=xml
- name: Run pytest windows(windows-only)
if: matrix.os == 'windows-latest'
python -m pytest test/test_colors.py -svv --cov=. --cov-report=xml
- name: Run pytest test_cropposts
run: |
cd ammico
python -m pytest -m "not gcv and not long and not win_skip" -svv --cov=. --cov-report=xml
python -m pytest test/test_cropposts.py -svv --cov=. --cov-report=xml
- name: Run pytest test_display
run: |
cd ammico
python -m pytest test/test_display.py -svv --cov=. --cov-report=xml
- name: Run pytest test_faces
run: |
cd ammico
python -m pytest test/test_faces.py -svv --cov=. --cov-report=xml
- name: Run pytest test_multimodal_search
run: |
cd ammico
python -m pytest test/test_multimodal_search.py -m "not long" -svv --cov=. --cov-report=xml
- name: Run pytest test_objects
run: |
cd ammico
python -m pytest test/test_objects.py -svv --cov=. --cov-report=xml
- name: Run pytest test_summary
run: |
cd ammico
python -m pytest test/test_summary.py -m "not long" -svv --cov=. --cov-report=xml
- name: Run pytest test_text
run: |
cd ammico
python -m pytest test/test_text.py -m "not gcv" -svv --cov=. --cov-report=xml
- name: Run pytest test_utils
run: |
cd ammico
python -m pytest test/test_utils.py -svv --cov=. --cov-report=xml
- name: Upload coverage
if: matrix.os == 'ubuntu-22.04' && matrix.python-version == '3.9'
uses: codecov/codecov-action@v3
Expand Down
83 changes: 79 additions & 4 deletions ammico/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"CAM16-UCS",
"DIN99",
]
SUMMARY_ANALYSIS_TYPE = ["summary_and_questions", "summary", "questions"]
SUMMARY_MODEL = ["base", "large"]


class AnalysisExplorer:
Expand Down Expand Up @@ -111,13 +113,17 @@ def __init__(self, mydict: dict) -> None:
State("setting_Emotion_emotion_threshold", "value"),
State("setting_Emotion_race_threshold", "value"),
State("setting_Color_delta_e_method", "value"),
State("setting_Summary_analysis_type", "value"),
State("setting_Summary_model", "value"),
State("setting_Summary_list_of_questions", "value"),
prevent_initial_call=True,
)(self._right_output_analysis)

self.app.callback(
Output("settings_TextDetector", "style"),
Output("settings_EmotionDetector", "style"),
Output("settings_ColorDetector", "style"),
Output("settings_Summary_Detector", "style"),
Input("Dropdown_select_Detector", "value"),
)(self._update_detector_setting)

Expand Down Expand Up @@ -240,6 +246,60 @@ def _create_setting_layout(self):
)
],
),
html.Div(
id="settings_Summary_Detector",
style={"display": "none"},
children=[
html.Div(
[
dcc.Dropdown(
options=SUMMARY_ANALYSIS_TYPE,
value="summary_and_questions",
id="setting_Summary_analysis_type",
)
],
style={
"width": "33%",
"display": "inline-block",
},
),
html.Div(
[
dcc.Dropdown(
options=SUMMARY_MODEL,
value="base",
id="setting_Summary_model",
)
],
style={
"width": "33%",
"display": "inline-block",
"margin-top": "10px",
},
),
html.Div(
[
html.Div(
"Please enter a question",
style={
"height": "50px",
"margin-top": "5px",
},
),
dcc.Input(
type="text",
id="setting_Summary_list_of_questions",
style={"height": "auto", "margin-bottom": "auto"},
),
],
style={
"width": "33%",
"display": "inline-block",
"margin-top": "10px",
},
),
],
),
],
)
return settings_layout
Expand Down Expand Up @@ -334,16 +394,19 @@ def _update_detector_setting(self, setting_input):
}

if setting_input == "TextDetector":
return display_flex, display_none, display_none
return display_flex, display_none, display_none, display_none

if setting_input == "EmotionDetector":
return display_none, display_flex, display_none
return display_none, display_flex, display_none, display_none

if setting_input == "ColorDetector":
return display_none, display_none, display_flex
return display_none, display_none, display_flex, display_none

if setting_input == "SummaryDetector":
return display_none, display_none, display_none, display_flex

else:
return display_none, display_none, display_none
return display_none, display_none, display_none, display_none

def _right_output_analysis(
self,
Expand All @@ -355,6 +418,9 @@ def _right_output_analysis(
setting_emotion_emotion_threshold: int,
setting_emotion_race_threshold: int,
setting_color_delta_e_method: str,
setting_summary_analysis_type: str,
setting_summary_model: str,
setting_summary_list_of_questions: str,
) -> dict:
"""Callback function to perform analysis on the selected image and return the output.
Expand Down Expand Up @@ -396,6 +462,15 @@ def _right_output_analysis(
image_copy,
delta_e_method=setting_color_delta_e_method,
)
elif detector_value == "SummaryDetector":
detector_class = identify_function(
image_copy,
analysis_type=setting_summary_analysis_type,
summary_model_type=setting_summary_model,
list_of_questions=[setting_summary_list_of_questions]
if (setting_summary_list_of_questions is not None)
else None,
)
else:
detector_class = identify_function(image_copy)
return detector_class.analyse_image()
Loading

0 comments on commit 5ff5a4f

Please sign in to comment.