Skip to content

Commit

Permalink
Fix duplicate logging issue with pretty print flag in expression comp…
Browse files Browse the repository at this point in the history
…rehension

- Refactored `pretty_print_expression()` method to handle both pretty and standard logging within itself.
- Modified `_webcam_detection_thread` method to call `pretty_print_expression()` instead of duplicating log messages.
- Ensured single logging output for expression comprehensions based on the `pretty_print` flag.
  • Loading branch information
CharlesCNorton committed Jul 9, 2024
1 parent 09ea9e4 commit c025ed6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='yoflo',
version='0.2.7',
version='0.2.8',
packages=find_packages(),
include_package_data=True,
install_requires=[
Expand Down
13 changes: 8 additions & 5 deletions yoflo/yoflo.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,10 @@ def _webcam_detection_thread(self):
results = self.run_expression_comprehension(image_pil, self.phrase)
if results:
clean_result = results.replace('<s>', '').replace('</s>', '').strip().lower()
logging.info(f"Expression Comprehension: {clean_result}")
if self.pretty_print:
self.pretty_print_expression(clean_result)
self.pretty_print_expression(clean_result)
self.inference_count += 1
self.update_inference_rate()
if clean_result in ['yes', 'no']:
if clean_result in ['yes', 'no'] and self.log_to_file_active:
if self.log_to_file_active:
self.log_alert(f"Expression Comprehension: {clean_result} at {datetime.now()}")
if self.inference_phrases:
Expand Down Expand Up @@ -298,7 +296,12 @@ def pretty_print_expression(self, clean_result):
"""Pretty print the expression comprehension result to the console."""
try:
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
logging.info(f"Expression Comprehension: {clean_result} at {timestamp}")
if self.pretty_print:
logging.info("\n" + "="*50)
logging.info(f"Expression Comprehension: {clean_result} at {timestamp}")
logging.info("="*50 + "\n")
else:
logging.info(f"Expression Comprehension: {clean_result} at {timestamp}")
except Exception as e:
logging.error(f"Error in pretty_print_expression: {e}")

Expand Down

0 comments on commit c025ed6

Please sign in to comment.