bytelyst-devops-tools/supabase monitor/example.py

114 lines
3.3 KiB
Python

"""
Simple example script to demonstrate the YouTube processing workflow.
"""
import os
import sys
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
def run_example():
"""Run a simple example of the workflow."""
print("YouTube Processing Workflow - Simple Example")
print("=" * 55)
# Check if API keys are configured
missing_keys = []
if not os.getenv("PERPLEXITY_API_KEY") and not os.getenv("OPENAI_API_KEY"):
missing_keys.append("PERPLEXITY_API_KEY or OPENAI_API_KEY")
if missing_keys:
print("Missing required configuration:")
for key in missing_keys:
print(f" - {key}")
print(f"\nPlease add these to your .env file and try again.")
print(f" See env.example for reference.")
return False
print("Configuration looks good!")
# Example parameters
youtube_url = "https://www.youtube.com/watch?v=WepSY1rgoys" # User's video
target_language = "English"
summarization_prompt = "Summarize in 5 bullet points for students to revise quickly"
print(f"\nProcessing: {youtube_url}")
print(f"Target Language: {target_language}")
print(f"Summary Prompt: {summarization_prompt}")
print(f"\nRunning workflow...")
try:
from workflow import YouTubeProcessingWorkflow
# Initialize workflow
workflow = YouTubeProcessingWorkflow()
# Process the video
results = workflow.process_youtube_video(
youtube_url=youtube_url,
target_language=target_language,
summarization_prompt=summarization_prompt,
workflow_metadata={
"example_run": True,
"source": "example.py"
}
)
# Print summary
workflow.print_workflow_summary(results)
return results["success"]
except ImportError as e:
print(f"Import error: {str(e)}")
print(f" Please make sure all dependencies are installed:")
print(f" pip install -r requirements.txt")
return False
except Exception as e:
print(f"Error running example: {str(e)}")
return False
def print_usage():
"""Print usage instructions."""
print("Usage Options:")
print("=" * 30)
print("1. Run simple example:")
print(" python example.py")
print("")
print("2. Run demo with multiple examples:")
print(" python demo.py")
print("")
print("3. Run command line workflow:")
print(" python workflow.py <youtube_url> <language> <prompt>")
print("")
print("4. Start REST API server:")
print(" python api.py")
print("")
print("5. Run tests:")
print(" python test.py")
print("")
print("Example CLI usage:")
print(' python workflow.py "https://www.youtube.com/watch?v=example" "Spanish" "Summarize in 3 bullet points"')
def main():
"""Main function."""
if len(sys.argv) > 1 and sys.argv[1] == "--help":
print_usage()
return
success = run_example()
if success:
print(f"\nExample completed successfully!")
else:
print(f"\nExample failed. Check the errors above.")
print_usage()
if __name__ == "__main__":
main()