Skip to content

Conversation

@Grantimus9
Copy link
Contributor

Summary

Implements a new workflow block that loads images from URLs with caching capabilities. This block enables workflows to dynamically fetch images from web URLs and use them as input for other workflow steps.

Features

  • URL Input Support: Accepts both direct URL strings and parameter references ($inputs.image_url)
  • Caching: Optional LRU cache to avoid re-downloading the same images (enabled by default)
  • Security: Uses existing load_image_from_url function for URL validation and secure image loading
  • Error Handling: Comprehensive error handling with descriptive messages for invalid URLs or unsupported formats
  • Union Types: Supports both direct values and parameter references for all inputs

Implementation Details

  • Block Type: roboflow_core/load_image_from_url@v1
  • Inputs:
    • url: Image URL (string or parameter reference)
    • cache: Enable/disable caching (boolean or parameter reference, defaults to true)
  • Output: image - WorkflowImageData object ready for use in other workflow steps
  • Icon: Uses fas fa-image for visual identification

Testing

  • 17 comprehensive tests covering all functionality
  • Tests use mocking to avoid network dependencies during CI/CD
  • Validates manifest creation, runtime behavior, caching, and error handling
  • Includes specific test for real-world URL scenarios

Files Added/Modified

  • inference/core/workflows/core_steps/transformations/load_image_from_url/v1.py - Main implementation
  • inference/core/workflows/core_steps/transformations/load_image_from_url/__init__.py - Module initialization
  • tests/workflows/unit_tests/core_steps/transformations/test_load_image_from_url.py - Test suite
  • inference/core/workflows/core_steps/loader.py - Block registration

🤖 Generated with Claude Code

@CLAassistant
Copy link

CLAassistant commented Aug 19, 2025

CLA assistant check
All committers have signed the CLA.

@Grantimus9 Grantimus9 force-pushed the feature-load-image-from-url-workflow-block branch from 5bc8798 to fb5726e Compare August 20, 2025 01:58
- Add LoadImageFromUrlBlockV1 transformation block
- Support Union types for URL and cache inputs (direct values + parameters)
- Implement LRU cache for image storage
- Use existing load_image_from_url for security/validation
- Add comprehensive test suite (17 tests, 100% requirement coverage)
- Update block icon from fa-download to fa-image
- Register block in workflow loader

🤖 Generated with [Claude Code](https://claude.ai/code)
- Fix black formatting issues in load_image_from_url/v1.py
- Fix import sorting in loader.py

🤖 Generated with [Claude Code](https://claude.ai/code)
@Grantimus9 Grantimus9 force-pushed the feature-load-image-from-url-workflow-block branch from fb5726e to 3fd90b7 Compare August 20, 2025 02:03
- Add LoadImageFromUrlBlockV1 transformation block
- Support Union types for URL and cache inputs (direct values + parameters)
- Implement LRU cache for image storage
- Use existing load_image_from_url for security/validation
- Add comprehensive test suite (17 tests, 100% requirement coverage)
- Update block icon from fa-download to fa-image
- Register block in workflow loader

🤖 Generated with [Claude Code](https://claude.ai/code)
- Fix black formatting issues in load_image_from_url/v1.py
- Fix import sorting in loader.py

🤖 Generated with [Claude Code](https://claude.ai/code)
@Grantimus9 Grantimus9 force-pushed the feature-load-image-from-url-workflow-block branch from 3fd90b7 to 3d2989b Compare August 20, 2025 02:14
Copy link
Contributor

@yeldarby yeldarby left a comment

Choose a reason for hiding this comment

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

Working for loading image & passing to some blocks but Model blocks seem to require a Batch oriented image & can't figure out how to modify this in a way that tells the execution engine that it's properly batched.

codeflash-ai bot added a commit that referenced this pull request Aug 26, 2025
…-image-from-url-workflow-block`)

The optimization applies **module-level pre-computation** to eliminate repeated list construction. The original code creates a new 122-element list every time `load_blocks()` is called, while the optimized version creates the list once at import time and stores it in a module constant `_BLOCKS`.

**Key changes:**
- **Pre-computed constant**: The block list is moved to module-level constant `_BLOCKS`, constructed once during import
- **Direct return**: `load_blocks()` now simply returns the pre-built list instead of constructing it each call

**Why this achieves 713% speedup:**
- **Eliminates list construction overhead**: The original spends ~80% of execution time (14.9ms out of 18.7ms) just constructing the list literal with 122 class references
- **Reduces memory allocations**: No repeated list object creation on each function call
- **Maintains object reference semantics**: Same classes are returned, preserving all behavior and type information

**Test case performance patterns:**
The optimization shows consistent 600-900% speedup across all test scenarios, with particularly strong gains in:
- Repeated calls (784-936% faster) - benefits most from avoiding re-construction
- Large-scale operations that call `load_blocks()` multiple times
- Basic functionality tests (615-762% faster) - all benefit from the single list return

This is a classic **constant folding** optimization where expensive computation (list construction) is moved from runtime to import time.
@codeflash-ai
Copy link
Contributor

codeflash-ai bot commented Aug 26, 2025

⚡️ Codeflash found optimizations for this PR

📄 714% (7.14x) speedup for load_blocks in inference/core/workflows/core_steps/loader.py

⏱️ Runtime : 158 microseconds 19.4 microseconds (best of 266 runs)

I created a new dependent PR with the suggested changes. Please review:

If you approve, it will be merged into this PR (branch feature-load-image-from-url-workflow-block).

@hansent
Copy link
Contributor

hansent commented Sep 4, 2025

@Grantimus9 still workgin on this? I think the required changes in execution engine laded. Any other blockers or maybe we just need to merge in latest master and test?

@Grantimus9
Copy link
Contributor Author

Just merge and test. Don't wait on me, but I'm also happy to do it later, probably tomorrow.

@hansent hansent requested a review from yeldarby September 5, 2025 19:42
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.

4 participants