Skip to content

Commit

Permalink
slides examples uses typer cli
Browse files Browse the repository at this point in the history
  • Loading branch information
fpingham committed Feb 9, 2024
1 parent 3295467 commit 83eebf2
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions examples/vision/competitors.py → examples/vision/slides.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import sys
from typing import Dict, List, Optional

import instructor
import typer
from dotenv import find_dotenv, load_dotenv
from openai import OpenAI
from pydantic import BaseModel, Field
from rich import print as rprint

import instructor

load_dotenv(find_dotenv())

# Add logger
Expand Down Expand Up @@ -93,25 +95,24 @@ def run(images: List[str]) -> Competition:

return competitors

import typer

if __name__ == "__main__":
# Run logger
logger.info("Starting app...")

if len(sys.argv) != 2:
print("Usage: python app.py <path_to_image_list_file>")
sys.exit(1)
def main(image_file: str = typer.Argument(..., help="Path to the image list file")):
"""
Main function to process the image list file and identify competitors.
"""
logger.info("Starting app...")

image_file = sys.argv[1]
with open(image_file, "r") as file:
logger.info(f"Reading images from file: {image_file}")
try:
try:
with open(image_file, "r") as file:
logger.info(f"Reading images from file: {image_file}")
image_list = file.read().splitlines()
logger.info(f"{len(image_list)} images read from file: {image_file}")
except Exception as e:
logger.error(f"Error reading images from file: {image_file}")
logger.error(e)
sys.exit(1)
except Exception as e:
logger.error(f"Error reading images from file: {image_file}")
logger.error(e)
raise typer.Exit(code=1)

competitors = run(image_list)

Expand All @@ -131,6 +132,9 @@ def run(images: List[str]) -> Competition:
indent=4,
)

if __name__ == "__main__":
typer.run(main)

"""
Example output:
{
Expand Down

0 comments on commit 83eebf2

Please sign in to comment.