streamware

Streamware Examples

This directory contains example scripts demonstrating various features and usage patterns of the Streamware framework.

๐Ÿค– Interactive LLM Shell (NEW!)

Natural language commands with LLM understanding

# Start interactive shell (terminal)
sq shell

# Start voice shell (browser)
sq voice-shell
# Open http://localhost:8766 in browser

# List available functions
sq functions

Terminal Shell

sq shell
sq> detect person and email admin@company.com immediately
โœ… Start person detection, send email immediately
   Command: sq watch --detect person --email admin@company.com --notify-mode instant
   Execute? [Y/n]: y

Browser Voice Shell

sq voice-shell
# Open http://localhost:8766
# Click ๐ŸŽค and say: "detect person and email me"
# Say "yes" to confirm
See: LLM Shell Guide Voice Shell Guide

๐ŸŽฅ Real-time Visualizer

Motion detection with SVG overlays and DSL metadata streaming

# Basic usage - open http://localhost:8080
sq visualize --url "rtsp://camera/stream" --port 8080

# Lowest latency configuration
sq visualize --url "rtsp://camera/stream" --port 8080 \
  --video-mode meta --fps 10 --transport udp --backend pyav

# MQTT integration - publish to broker
sq mqtt --url "rtsp://camera/stream" --broker localhost
Mode Latency Use Case
--video-mode ws ~100ms Full video (default)
--video-mode meta ~50ms Metadata + 1 FPS preview
--backend pyav ~50ms Direct API, no subprocess
--transport udp ~50ms Lower latency

See: media-processing/realtime_visualizer_examples.sh


Real-time video analysis with YOLO + Vision LLM + TTS

# Person tracking with voice narration
sq live narrator --url "rtsp://camera/stream" --mode track --focus person --tts

# Bird feeder monitoring
sq live narrator --url "rtsp://birdcam/stream" --mode track --focus bird --tts

# Pet camera (cats & dogs)
sq live narrator --url "rtsp://petcam/stream" --mode track --focus pet --tts

# Verbose mode (see timing)
sq live narrator --url "rtsp://camera/stream" --mode track --focus person --tts --verbose

See: media-processing/live_narrator_examples.sh


๐Ÿ—ฃ๏ธ Natural Language Configuration (NEW!)

Configure using natural language - Polish or English

# Track person
sq watch "track person"
sq watch "ล›ledลบ osoby"

# Count objects
sq watch "count people"
sq watch "ile samochodรณw"

# Describe scene
sq watch "describe what's happening"
sq watch "opisz co siฤ™ dzieje"

# Security alerts
sq watch "alert when someone enters"
sq watch "powiadom gdy ktoล› wchodzi"
See: natural_language/ docs/NATURAL_LANGUAGE_CONFIG.md

๐Ÿ“ New Examples

Example Description Quick Start
track_person/ Fast person tracking with YOLO sq watch "track person"
security/ Intrusion detection with LLM sq watch "alert when someone enters"
count_objects/ Count people, cars, animals sq watch "count people"
describe_scene/ LLM scene descriptions sq watch "describe scene"
natural_language/ Natural language config sq watch "ล›ledลบ osoby"

๐Ÿ“ Project Examples

Project Description Examples
media-processing/ Visualizer, MQTT, Live Narrator realtime_visualizer_examples.sh, mqtt_integration.py
llm-ai/ AI text processing, code generation text_to_sql.py, chat_assistant.py
voice-control/ Voice commands, STT/TTS voice_keyboard.py, voice_mouse.py
automation/ Desktop automation mouse_control.py, keyboard_control.py
communication/ Email, Slack, Telegram slack_bot.py, telegram_bot.py
data-pipelines/ ETL, data transformation api_to_database.py, csv_processor.py
deployment/ Docker, K8s, SSH deploy docker_deploy.py, ssh_deploy.sh

๐Ÿš€ Quick Start

# Real-time Visualizer (NEW - motion detection with SVG overlay)
sq visualize --url "rtsp://camera/stream" --port 8080
sq visualize --url "rtsp://camera/stream" --port 8080 --video-mode meta --backend pyav

# MQTT Publisher (NEW - publish DSL to broker)
sq mqtt --url "rtsp://camera/stream" --broker localhost

# Live Narrator (real-time video with TTS)
sq live narrator --url "rtsp://camera/stream" --mode track --focus person --tts

# LLM/AI
python examples/llm-ai/text_to_sql.py "Get all users"
python examples/llm-ai/chat_assistant.py --provider ollama/qwen2.5:14b

# Voice Control
python examples/voice-control/voice_keyboard.py --interactive

# Automation
python examples/automation/mouse_control.py 100 200

# Communication
python examples/communication/slack_bot.py general "Hello!"

# Data Pipelines
python examples/data-pipelines/api_to_database.py

๐ŸŽฌ Video Analysis Modes

Mode Description CLI Command
full Coherent narrative sq media describe_video --file v.mp4 --mode full
stream Frame-by-frame details sq media describe_video --file v.mp4 --mode stream
diff Track changes sq media describe_video --file v.mp4 --mode diff

๐Ÿ“š Full documentation: media-processing/README.md

Document Description
Quick Start Get started in 5 minutes
Quick CLI sq command reference
LLM Component AI providers configuration
Voice Guide Voice control setup
DSL Examples Pipeline syntax

๐Ÿ“ฆ Legacy Examples

File Description
basic_usage.py Fundamental concepts
advanced_patterns.py Workflow patterns
llm_examples.py LLM demonstrations
ssh_examples.py SSH operations
deploy_examples.py Deployment patterns
dsl_examples.py DSL syntax
text2streamware_examples.py Natural language to commands

๐Ÿ”— Source Code References

Component Path
LLM streamware/components/llm.py
Voice streamware/components/voice.py
Voice Keyboard streamware/components/voice_keyboard.py
Voice Mouse streamware/components/voice_mouse.py
Automation streamware/components/automation.py
Media streamware/components/media.py
Email streamware/components/email.py
Slack streamware/components/slack.py
Telegram streamware/components/telegram.py

Quick Start

Run All Basic Examples

cd /path/to/streamware
python examples/basic_usage.py

Run Specific Examples

You can modify the example files to run specific examples:

# In basic_usage.py, modify main() to run specific examples
if __name__ == "__main__":
    example_1_simple_data_flow()
    example_2_file_operations()
    # ... run only what you need

Example Output

When you run the examples, youโ€™ll see output like:

============================================================
STREAMWARE BASIC USAGE EXAMPLES
============================================================

=== Example 1: Simple Data Flow ===
Input: {'name': 'Alice', 'age': 30, 'city': 'New York'}
Output: {"name": "Alice", "age": 30, "city": "New York"}

=== Example 2: File Operations ===
Write result: {'success': True, 'path': '/tmp/streamware_example.txt'}
Read result: Hello from Streamware!
Cleaned up: /tmp/streamware_example.txt

...

Creating Your Own Examples

You can create custom examples by following these patterns:

#!/usr/bin/env python3
"""
My Custom Streamware Example
"""

from streamware import flow, Component, register

def my_example():
    """
    Description of what this example demonstrates
    """
    print("\n=== My Example ===")
    
    # Your code here
    result = flow("component://operation").run(data)
    print(f"Result: {result}")

if __name__ == "__main__":
    my_example()

Testing Examples

All examples are designed to be runnable without external dependencies (where possible). Some examples that require external services will skip or simulate operations.

To test examples:

# Run basic examples
python examples/basic_usage.py

# Run advanced examples
python examples/advanced_patterns.py

# Run with pytest (if you have tests for examples)
pytest examples/test_examples.py -v

Common Patterns

Pattern 1: Simple Pipeline

result = (
    flow("source://data")
    | "transform://process"
    | "sink://destination"
).run()

Pattern 2: With Error Handling

try:
    result = flow("risky://operation").run(data)
except ComponentError as e:
    print(f"Error: {e}")
    result = None

Pattern 3: Custom Component

@register("mycomp")
class MyComponent(Component):
    def process(self, data):
        return transform(data)

result = flow("mycomp://operation").run(data)

Pattern 4: Streaming

for item in flow("source://stream").stream():
    processed = process(item)
    save(processed)

Best Practices

  1. Start Simple: Begin with basic examples before moving to advanced patterns
  2. Experiment: Modify examples to understand how components work
  3. Error Handling: Always include error handling in production code
  4. Testing: Test your pipelines thoroughly
  5. Documentation: Document your custom components and pipelines

Troubleshooting

Import Errors

If you get import errors, make sure streamware is installed:

pip install -e .

Missing Dependencies

Some examples require optional dependencies:

# For communication examples
pip install streamware[communication]

# For all features
pip install streamware[all]

File Permissions

Some examples write to /tmp/. If you encounter permission issues, modify the examples to use a different directory:

import tempfile
temp_dir = tempfile.gettempdir()
temp_file = os.path.join(temp_dir, "output.txt")

Contributing Examples

We welcome contributions of new examples! Please:

  1. Follow the existing example structure
  2. Include clear documentation
  3. Test your examples
  4. Submit a pull request

Support


Happy streaming with Streamware! ๐Ÿš€