function run_demo
Orchestrates a complete demonstration of an E-Ink LLM Assistant by creating three sample handwritten content files (question, instruction diagram, math problem) and processing each through an AI pipeline.
/tf/active/vicechatdev/e-ink-llm/demo.py
118 - 153
moderate
Purpose
This async function serves as the main entry point for demonstrating the E-Ink LLM Assistant's capabilities. It creates demo content files, processes them sequentially through an AI processing pipeline, and provides user-friendly console output showing progress and results. The function is designed to showcase the system's ability to handle handwritten content analysis and generate PDF responses.
Source Code
async def run_demo():
"""Run the complete demo"""
print("šļø E-Ink LLM Assistant - DEMO")
print("=" * 50)
print("This demo will create sample handwritten content and process it with AI")
print()
# Create demo files
print("š Creating demo content...")
demo_files = [
create_handwritten_question(),
create_instruction_diagram(),
create_math_problem()
]
print(f"\nš Processing {len(demo_files)} demo files...")
# Process each demo file
for i, demo_file in enumerate(demo_files, 1):
print(f"\nš Processing demo {i}/{len(demo_files)}: {demo_file}")
print("-" * 40)
try:
result = await process_single_file(demo_file)
if result:
print(f"ā
Success! Response saved as: {Path(result).name}")
else:
print(f"ā Failed to process {demo_file}")
except Exception as e:
print(f"ā Error: {e}")
print(f"\nš Demo complete!")
print(f"š Check the current directory for:")
print(f" ⢠Original demo files: demo_*.png")
print(f" ⢠AI responses: RESPONSE_*.pdf")
print(f"\nš” Try opening the PDF responses to see the AI analysis!")
Return Value
Returns None (implicitly). The function produces side effects including: console output showing demo progress, creation of demo PNG files (demo_*.png), and generation of AI response PDF files (RESPONSE_*.pdf) in the current directory.
Dependencies
asynciosyspathlibPILprocessor
Required Imports
import asyncio
import sys
from pathlib import Path
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
from processor import process_single_file
Usage Example
import asyncio
from pathlib import Path
from PIL import Image, ImageDraw, ImageFont
from processor import process_single_file
# Ensure helper functions are defined:
# create_handwritten_question(), create_instruction_diagram(), create_math_problem()
async def main():
await run_demo()
if __name__ == '__main__':
asyncio.run(main())
Best Practices
- Must be called within an async context using 'asyncio.run()' or 'await'
- Ensure all three demo creation functions (create_handwritten_question, create_instruction_diagram, create_math_problem) are defined before calling
- Verify write permissions in the current directory before execution
- Handle exceptions at the caller level as the function catches and logs errors internally but continues processing
- The function processes files sequentially; for production use, consider parallel processing for better performance
- Check that the 'processor' module and its dependencies are properly configured with necessary API keys
- Monitor disk space as the function creates multiple image and PDF files
Tags
Similar Components
AI-powered semantic similarity - components with related functionality: