### Install Rapidata Python SDK Source: https://docs.rapidata.ai/quickstart This snippet demonstrates how to install the Rapidata Python SDK using pip, the standard package installer for Python. The `-U` flag ensures the package is upgraded to the latest version if already installed. ```Python pip install -U rapidata ``` -------------------------------- ### Start Rapidata AI Order Collection Source: https://docs.rapidata.ai/quickstart This snippet demonstrates how to initiate the collection of responses for an order by calling the `.run()` method. Once executed, annotators will immediately begin working on the order. ```Python order.run() ``` -------------------------------- ### Preview Rapidata AI Order Source: https://docs.rapidata.ai/quickstart This snippet shows how to preview an order using the `.preview()` method on the order object. This allows users to verify how tasks will be presented to annotators before starting the collection process. ```Python order.preview() ``` -------------------------------- ### Initialize RapidataClient with Interactive Login Source: https://docs.rapidata.ai/quickstart This code initializes the RapidataClient, which is used to manage orders. The first time this is run on a machine, it will prompt the user to log in, and then save the credentials locally for subsequent uses. ```Python from rapidata import RapidataClient #The first time executing it on a machine will require you to log in rapi = RapidataClient() ``` -------------------------------- ### Create Compare Order with Rapidata AI Source: https://docs.rapidata.ai/quickstart This snippet demonstrates how to create a compare order using the `rapi.order.create_compare_order` method. It specifies the order's name, the instruction for annotators, optional contexts, and the image datapoints to be compared. Note that calling this function uploads and prepares data, but does not start annotation. ```Python order = rapi.order.create_compare_order( name="Example Alignment Order", instruction="Which image matches the description better?", contexts=["A small blue book sitting on a large red book."], datapoints=[["https://assets.rapidata.ai/midjourney-5.2_37_3.jpg", "https://assets.rapidata.ai/flux-1-pro_37_0.jpg"]], ) ``` ```APIDOC rapi.order.create_compare_order( name: str, instruction: str, contexts: list[str] (optional), datapoints: list[list[str]] ) Parameters: name: Type: str Description: The name of the order. This is used to identify the order in the Rapidata Dashboard and to find the order again later. instruction: Type: str Description: The instruction you want to show the annotators to select the image by. contexts: Type: list[str] Description: The prompt that will be shown along side the two images and the instruction. (optional parameter) datapoints: Type: list[list[str]] Description: The image pairs we want to compare (order is randomized for every annotator). This can be any public URL (that points to an image, video or audio) or a local file path. This is a list of all datapoints you want to compare. Each datapoint consists of 2 files that are compared, as well as an optional context (which in this case is the prompt). The same instruction will be shown for each datapoint. There is a limit of 100 datapoints per order. ``` -------------------------------- ### Download Rapidata AI Order Results Source: https://docs.rapidata.ai/quickstart This snippet demonstrates how to download the results of a completed order by simply calling the `.get_results()` method on the order object. The results can then be further analyzed. ```Python results = order.get_results() ``` -------------------------------- ### Preview Rapidata AI Order Source: https://docs.rapidata.ai/examples/compare_order Shows how to preview an existing Rapidata AI order. Running this code allows developers to see the interface and content that annotators will interact with, ensuring the order setup is correct before deployment. ```Python order.preview() ``` -------------------------------- ### Initialize RapidataClient with Client ID and Secret Source: https://docs.rapidata.ai/quickstart This snippet provides an alternative method for initializing the RapidataClient by directly passing a Client ID and Secret. These credentials can be generated from the Rapidata web application settings and are useful for non-interactive environments. ```Python from rapidata import RapidataClient rapi = RapidataClient(client_id="Your client ID", client_secret="Your client secret") ``` -------------------------------- ### Preview a Rapidata Order in Python Source: https://docs.rapidata.ai/examples/compare_order This Python snippet shows how to preview an existing Rapidata order. Running `order.preview()` opens a local preview of what annotators will see, allowing for verification of the task setup before deployment. ```python order.preview() ``` -------------------------------- ### Create an Advanced Image Comparison Order with Validation Sets Source: https://docs.rapidata.ai/examples/compare_order This Python code illustrates how to create a more advanced 'compare' order using the RapidataClient, incorporating a validation set. It defines an instruction, validation prompts, validation image pairs, and their corresponding ground truths. This setup helps ensure the quality of responses by providing known examples for annotators. ```python from rapidata import RapidataClient # ===== TASK CONFIGURATION ===== INSTRUCTION: str = "Which image follows the prompt more accurately?" # ===== VALIDATION DATA ===== # This validation set helps ensure quality responses by providing known examples VALIDATION_PROMPTS: list[str] = [ "2 cats sitting on both sides of a dog", "girl wearing a futuristic costume without her face being covered by a mask", "a train traveling fast through a forest", ] VALIDATION_IMAGE_PAIRS: list[list[str]] = [ ["https://assets.rapidata.ai/2_cats_1_dog.jpg", "https://assets.rapidata.ai/2_dogs_1_cat.jpg"], ["https://assets.rapidata.ai/girl_without_mask.jpg", "https://assets.rapidata.ai/girl_with_mask.jpg"], ["https://assets.rapidata.ai/train_normal.jpg", "https://assets.rapidata.ai/train_surfing.jpg"], ] VALIDATION_TRUTHS: list[str] = [ "https://assets.rapidata.ai/2_cats_1_dog.jpg", # First image: 2 cats, 1 dog "https://assets.rapidata.ai/girl_without_mask.jpg", # First image: girl without mask "https://assets.rapidata.ai/train_normal.jpg", # First image: normal train through forest ] ``` -------------------------------- ### Recommended Instructions for Image Comparison Tasks Source: https://docs.rapidata.ai/human_prompting This snippet provides examples of clear and positive instructions for various image comparison tasks, including preference, prompt adherence, and coherence comparisons. It also includes an example for comparing two texts. ```python # Comparing image preference instruction="Which image do you prefer?" # Comparing prompt adherence instruction="Which image matches the description better?" # Comparing image coherence instruction="Which images has more glitches and is more likely to be AI generated?" # Comparing two texts instruction="Which of these sentences makes more sense?" ``` -------------------------------- ### Monitor Rapidata AI Order Progress Source: https://docs.rapidata.ai/quickstart This snippet shows how to monitor the progress of an order directly within the code by calling the `.display_progress_bar()` method. This provides an indication of how many datapoints have been labeled. ```Python order.display_progress_bar() ``` -------------------------------- ### Preview a Rapidata Order Source: https://docs.rapidata.ai/examples/free_text_order Shows how to preview an existing Rapidata order. This allows you to see the interface and experience from the annotator's perspective before the order is fully launched or completed. ```Python order.preview() ``` -------------------------------- ### Preview Rapidata Order in Browser Source: https://docs.rapidata.ai/examples/locate_order This snippet shows how to generate a preview of the created Rapidata order. Running this code will open a browser window displaying the order as annotators would see it, allowing for verification of instructions and layout. ```python order.preview() ``` -------------------------------- ### Preview Rapidata Order Source: https://docs.rapidata.ai/examples/select_words_order Shows how to preview the created Rapidata order to see the annotator's view directly within the development environment. ```python order.preview() ``` -------------------------------- ### Install Rapidata Python SDK Source: https://docs.rapidata.ai/index This command installs the Rapidata Python SDK using pip, ensuring you have the latest version for development and access to all its functionalities. ```Python pip install -U rapidata ``` -------------------------------- ### Python Example for create_compare_set Parameters Source: https://docs.rapidata.ai/reference/rapidata/rapidata_client/validation/validation_set_manager Illustrates the structure of `instruction`, `datapoints`, and `truths` parameters for the `create_compare_set` function with a concrete example. ```python instruction: "Which image has a cat?" datapoints = [["image1.jpg", "image2.jpg"], ["image3.jpg", "image4.jpg"]] truths: ["image1.jpg", "image4.jpg"] ``` -------------------------------- ### Preview a Rapidata Order Source: https://docs.rapidata.ai/examples/draw_order This snippet shows how to preview an existing Rapidata order. Running this code will open a preview interface, allowing you to see exactly what the annotators will experience when working on the task. ```python order.preview() ``` -------------------------------- ### Preview a Rapidata Order Source: https://docs.rapidata.ai/examples/ranking_order This code snippet allows you to preview the created order in the browser, showing what annotators will see during the ranking process. ```Python order.preview() ``` -------------------------------- ### View Rapidata Order in Browser Source: https://docs.rapidata.ai/examples/select_words_order Illustrates how to open the created Rapidata order directly in a web browser for a full view of the annotation interface. ```python order.view() ``` -------------------------------- ### View a Rapidata Order in Browser Source: https://docs.rapidata.ai/examples/ranking_order This code snippet opens the created order directly in your web browser, providing a full view of the order interface. ```Python order.view() ``` -------------------------------- ### Preview Rapidata Order in Console Source: https://docs.rapidata.ai/examples/classify_order Shows how to use the `order.preview()` method to display a visual representation of the order directly within the console, allowing for a quick check of the annotator interface. ```Python order.preview() ``` -------------------------------- ### Retrieve Rapidata AI Orders Source: https://docs.rapidata.ai/quickstart This snippet illustrates how to retrieve existing orders. The `find_orders` method allows filtering by name or retrieving the most recent orders. Alternatively, a specific order can be retrieved using its unique ID with the `get_order_by_id` method. ```Python example_orders = rapi.order.find_orders("Example Alignment Order") # if no name is provided it will just return the most recent one most_recent_order = rapi.order.find_orders()[0] ``` ```Python order = rapi.order.get_order_by_id("order_id") ``` -------------------------------- ### Create a Basic Free Text Order Source: https://docs.rapidata.ai/examples/free_text_order Demonstrates initializing the RapidataClient and creating a basic free-text order. This order is designed to gather questions for an AI chatbot, specifying an instruction and a visual datapoint. The code then runs the order, displays progress, and prints the collected results. ```Python from rapidata import RapidataClient if __name__ == "__main__": rapi = RapidataClient() order = rapi.order.create_free_text_order( name="Example prompt generation", instruction="What would you like to ask an AI? please spell out the question", datapoints=["https://assets.rapidata.ai/ai_question.png"], ).run() order.display_progress_bar() results = order.get_results() print(results) ``` -------------------------------- ### Open Rapidata Order in Browser Source: https://docs.rapidata.ai/examples/locate_order This code demonstrates how to open the full Rapidata order in a web browser. This allows users to access the order's details, progress, and management interface directly. ```python order.view() ``` -------------------------------- ### Preview Rapidata AI Classification Order Source: https://docs.rapidata.ai/examples/classify_order This snippet demonstrates how to preview a created Rapidata AI classification order. Running this code will open a local preview, allowing developers to see exactly what annotators will experience during the task. ```python order.preview() ``` -------------------------------- ### Create a Draw Order for Image Annotation Source: https://docs.rapidata.ai/examples/draw_order This code snippet demonstrates how to initialize the RapidataClient and create a 'draw order'. It defines a list of image URLs as datapoints and sets instructions for annotators to color in specific objects. The order is then run, its progress displayed, and results are retrieved. ```python from rapidata import RapidataClient IMAGE_URLS = ["https://assets.rapidata.ai/midjourney-5.2_37_3.jpg", "https://assets.rapidata.ai/flux-1-pro_37_0.jpg", "https://assets.rapidata.ai/frames-23-1-25_37_4.png", "https://assets.rapidata.ai/aurora-20-1-25_37_3.png"] if __name__ == "__main__": rapi = RapidataClient() order = rapi.order.create_draw_order( name="Example Image Comparison", instruction="Color in all the blue books", datapoints=IMAGE_URLS, responses_per_datapoint=35, ).run() order.display_progress_bar() results = order.get_results() print(results) ``` -------------------------------- ### Create an Advanced Free Text Order with Filters Source: https://docs.rapidata.ai/examples/free_text_order Expands on the basic free-text order by incorporating advanced settings and filters. This example applies a minimum character length (5) for responses and restricts annotators to those with their phone language set to English, ensuring higher quality and targeted data collection. ```Python from rapidata import ( RapidataClient, FreeTextMinimumCharacters, LanguageFilter, ) if __name__ == "__main__": rapi = RapidataClient() order = rapi.order.create_free_text_order( name="Example prompt generation", instruction="What would you like to ask an AI? please spell out the question", datapoints=["https://assets.rapidata.ai/ai_question.png"], settings=[FreeTextMinimumCharacters(5)], filters=[LanguageFilter(["en"])], ).run() order.display_progress_bar() results = order.get_results() print(results) ``` -------------------------------- ### Create and Process Image Prompt Alignment Order with RapidataClient Source: https://docs.rapidata.ai/examples/compare_order Demonstrates the main workflow for creating and managing an image prompt alignment order using RapidataClient. It initializes the client, creates a validation set, then creates a comparison order with specified parameters, tracks its progress, and retrieves the results. ```Python def main(): client = RapidataClient() validation_set_id = create_validation_set(client) order = client.order.create_compare_order( name="Example Image Prompt Alignment Order", instruction=INSTRUCTION, datapoints=IMAGE_PAIRS, contexts=PROMPTS, responses_per_datapoint=25, validation_set_id=validation_set_id ).run() order.display_progress_bar() results = order.get_results() print(results) if __name__ == "__main__": main() ``` -------------------------------- ### RapidataClient API Reference Source: https://docs.rapidata.ai/examples/classify_order This section outlines key components and methods of the `RapidataClient` used for interacting with the Rapidata AI platform, including methods for validation set creation and classification order management. ```APIDOC RapidataClient: __init__(): Initializes the client for Rapidata AI. validation: create_classification_set(name: str, instruction: str, answer_options: list[str], contexts: list[str], datapoints: list[str], truths: list[list[str]]) -> ValidationSet: Creates a new classification validation set. - name: Name of the validation set. - instruction: Instructions for annotators. - answer_options: Possible answers for classification. - contexts: Contexts for datapoints. - datapoints: URLs of images/data to validate. - truths: Expected correct answers for each datapoint. Returns: The created ValidationSet object. order: create_classification_order(name: str, instruction: str, answer_options: list[str], contexts: list[str], datapoints: list[str], validation_set_id: str, responses_per_datapoint: int, settings: list[Any]) -> Order: Creates and configures a new classification order. - name: Name of the classification order. - instruction: Instructions for annotators. - answer_options: Possible answers for classification. - contexts: Contexts for datapoints. - datapoints: URLs of images/data to classify. - validation_set_id: ID of the validation set to use. - responses_per_datapoint: Number of responses required per datapoint. - settings: Additional order settings (e.g., NoShuffle()). Returns: The created Order object. Order: run() -> Order: Starts the classification order. Returns: The Order object itself. display_progress_bar(): Displays a progress bar for the order's completion. get_results() -> Any: Retrieves the results of the completed classification order. Returns: The classification results. preview(): Opens a local preview of the order for annotator's view. view(): Opens the order in the default web browser. ``` -------------------------------- ### Creating a Rapidata Comparison Order Source: https://docs.rapidata.ai/human_prompting This Python example shows how to create a `compare_order` using the `rapi.order.create_compare_order` method. It demonstrates setting the order name, instruction, datapoints (image URLs), and integrating predefined task selections for a comparison task. ```python order = rapi.order.create_compare_order( name="Image Coherence Comparison", instruction="Which images has more glitches and is more likely to be AI generated?", # Clear, positive framing datapoints=[["https://assets.rapidata.ai/flux-1.1-pro/33_2.jpg", "https://assets.rapidata.ai/stable-diffusion-3/33_0.jpg"]], selections=selections # Include the above-defined selections ) ``` -------------------------------- ### Standard Python Entry Point Source: https://docs.rapidata.ai/examples/classify_order This standard Python construct ensures that the `main` function is called only when the script is executed directly, not when imported as a module. ```python if __name__ == "__main__": main() ``` -------------------------------- ### Open Rapidata Order in Browser Source: https://docs.rapidata.ai/examples/classify_order Illustrates the use of `order.view()` to open the created Rapidata order in the default web browser, providing a full interactive view of the annotation task. ```Python order.view() ``` -------------------------------- ### Open Rapidata AI Order in Browser Source: https://docs.rapidata.ai/examples/compare_order Provides the code to open an existing Rapidata AI order directly in the default web browser. This is useful for quickly accessing and managing the order's status or details through the Rapidata AI platform's UI. ```Python order.view() ``` -------------------------------- ### Open a Rapidata Order in Browser with Python Source: https://docs.rapidata.ai/examples/compare_order This Python code demonstrates how to open an existing Rapidata order directly in the browser. The `order.view()` method provides a convenient way to access the order's interface for management or monitoring. ```python order.view() ``` -------------------------------- ### View a Rapidata Order in Browser Source: https://docs.rapidata.ai/examples/free_text_order Illustrates how to open an existing Rapidata order directly in your default web browser. This provides a convenient way to monitor the order's status and details on the Rapidata platform. ```Python order.view() ``` -------------------------------- ### Create Validation Set with RapidataClient Source: https://docs.rapidata.ai/examples/compare_order Defines a Python function `create_validation_set` that uses the RapidataClient to create a comparison validation set. This set is crucial for ensuring the quality of responses in image prompt alignment tasks by providing ground truth for evaluation. ```Python def create_validation_set(client: RapidataClient) -> str: """ Create a validation set to ensure quality responses. Args: client: The RapidataClient instance Returns: The validation set ID """ validation_set = client.validation.create_compare_set( name="Example Image Prompt Alignment Validation Set", instruction=INSTRUCTION, contexts=VALIDATION_PROMPTS, datapoints=VALIDATION_IMAGE_PAIRS, truths=VALIDATION_TRUTHS ) return validation_set.id ``` -------------------------------- ### Create Basic Image Classification Order with Rapidata Python SDK Source: https://docs.rapidata.ai/examples/classify_order Demonstrates how to initialize the RapidataClient and create a classification order. It defines image URLs and contexts, sets up a Likert scale for answers, and uses NoShuffle to maintain answer option order. The order is then executed, its progress displayed, and results retrieved. ```Python from rapidata import RapidataClient, NoShuffle # List of image URLs representing different emotions IMAGE_URLS: list[str] = [ "https://assets.rapidata.ai/tshirt-4o.png", # Related T-Shirt with the text "Running on caffeine & dreams" "https://assets.rapidata.ai/tshirt-aurora.jpg", # Related T-shirt with the text "Running on caffeine & dreams" "https://assets.rapidata.ai/teamleader-aurora.jpg", # Unrelated image ] CONTEXTS: list[str] = [ "A t-shirt with the text 'Running on caffeine & dreams'" ] * len(IMAGE_URLS) # Each image will have the same context to be rated by if __name__ == "__main__": rapi = RapidataClient() # Create a classification order for emotions based on the images order = rapi.order.create_classification_order( name="Likert Scale Example", instruction="How well does the image match the description?", answer_options=["1: Not at all", "2: A little", "3: Moderately", "4: Very well", "5: Perfectly"], contexts=CONTEXTS, datapoints=IMAGE_URLS, responses_per_datapoint=25, settings=[NoShuffle()] # Do not shuffle the answer options ).run() # Execute the order # Display a progress bar for the order order.display_progress_bar() # Retrieve and print the results of the classification results = order.get_results() ``` -------------------------------- ### Open a Rapidata Order in Browser Source: https://docs.rapidata.ai/examples/draw_order This code allows you to open an existing Rapidata order directly in your web browser. This is useful for managing or monitoring the order's progress through the Rapidata platform's user interface. ```python order.view() ``` -------------------------------- ### Recommended Instructions for Classification Tasks Source: https://docs.rapidata.ai/human_prompting This Python snippet offers examples of instructions for different classification task types, including simple object classification and Likert scale classification. It shows how to define `answer_options` for Likert scales. ```python # Simple classification instruction="What object is in the image?" # Likert classification (add no shuffling setting) instruction="How well does the video match the description?" answer_options=["1: Perfectly", "2: Very well", "3: Moderately", "4: A little", "5: Not at all"] ``` -------------------------------- ### Define Prompts and Image Pairs for Rapidata AI Source: https://docs.rapidata.ai/examples/compare_order Defines lists of text prompts and corresponding image URL pairs (Flux vs. Midjourney versions) used as input for Rapidata AI's image prompt alignment tasks. These lists serve as the dataset for validation and ordering. ```Python PROMPTS: list[str] = [ "A sign that says 'Diffusion'.", "A yellow flower sticking out of a green pot.", "hyperrealism render of a surreal alien humanoid.", "psychedelic duck", "A small blue book sitting on a large red book." ] IMAGE_PAIRS: list[list[str]] = [ ["https://assets.rapidata.ai/flux_sign_diffusion.jpg", "https://assets.rapidata.ai/mj_sign_diffusion.jpg"], ["https://assets.rapidata.ai/flux_flower.jpg", "https://assets.rapidata.ai/mj_flower.jpg"], ["https://assets.rapidata.ai/flux_alien.jpg", "https://assets.rapidata.ai/mj_alien.jpg"], ["https://assets.rapidata.ai/flux_duck.jpg", "https://assets.rapidata.ai/mj_duck.jpg"], ["https://assets.rapidata.ai/flux_book.jpg", "https://assets.rapidata.ai/mj_book.jpg"] ] ``` -------------------------------- ### Open Rapidata AI Classification Order in Browser Source: https://docs.rapidata.ai/examples/classify_order This snippet provides the command to open a Rapidata AI classification order directly in the default web browser. This is useful for monitoring the order's progress or making manual adjustments via the Rapidata AI platform. ```python order.view() ``` -------------------------------- ### Create Rapidata Select Words Order Source: https://docs.rapidata.ai/examples/select_words_order Demonstrates how to initialize the RapidataClient and create a 'select words' order to detect image-text alignment mistakes. It specifies image URLs, prompts, responses per datapoint, and applies a language filter, also referencing a pre-existing validation set. ```python from rapidata import RapidataClient IMAGE_URLS = ['https://assets.rapidata.ai/dalle-3_244_0.jpg', 'https://assets.rapidata.ai/dalle-3_30_1.jpg', 'https://assets.rapidata.ai/dalle-3_268_2.jpg', 'https://assets.rapidata.ai/dalle-3_26_2.jpg'] PROMPTS = ['The black camera was next to the white tripod.', 'Four cars on the street.', 'Car is bigger than the airplane.', 'One cat and two dogs sitting on the grass.'] PROMPTS_WITH_NO_MISTAKES = [prompt + " [No_mistakes]" for prompt in PROMPTS] # selection is split based on spaces if __name__ == "__main__": rapi = RapidataClient() order = rapi.order.create_select_words_order( name="Detect Mistakes in Image-Text Alignment", instruction="The image is based on the text below. Select mistakes, i.e., words that are not aligned with the image.", datapoints=IMAGE_URLS, responses_per_datapoint=15, sentences=PROMPTS_WITH_NO_MISTAKES, filters=[ rapi.order.filters.language(["en"]), ], validation_set_id="6761a86eef7af86285630ea8" # in this example, the validation set has already been created ).run() order.display_progress_bar() result = order.get_results() print(result) ``` -------------------------------- ### Configure Logger for Production with File Logging (Python) Source: https://docs.rapidata.ai/logging This snippet demonstrates how to configure the logger for a production environment, setting the logging level to INFO and directing logs to a specified file path. It also shows examples of logging informational and error messages. ```Python configure_logger( level="INFO", log_file="/var/log/rapidata/app.log" ) logger.info("Application started") logger.error("Connection failed, retrying...") ``` -------------------------------- ### Configure Advanced Classification Order with Validation Data Source: https://docs.rapidata.ai/examples/classify_order This snippet outlines the configuration for an advanced classification order, including defining a Likert scale, instructions, and crucially, a validation set. The validation data provides known examples to guide annotators and ensure higher quality responses. ```Python from rapidata import RapidataClient, NoShuffle # ===== TASK CONFIGURATION ===== # Likert scale options (from lowest to highest agreement) ANSWER_OPTIONS: list[str] = [ "1: Not at all", "2: A little", "3: Moderately", "4: Very well", "5: Perfectly" ] INSTRUCTION: str = "How well does the image match the description?" # ===== VALIDATION DATA ===== # This validation set helps ensure quality responses by providing known examples VALIDATION_IMAGE_URLS: list[str] = [ "https://assets.rapidata.ai/email-4o.png", "https://assets.rapidata.ai/email-aurora.jpg", "https://assets.rapidata.ai/teacher-aurora.jpg", ] VALIDATION_CONTEXT: str = "A laptop screen with clearly readable text, addressed to the marketing team about an upcoming meeting" VALIDATION_CONTEXTS: list[str] = [VALIDATION_CONTEXT] * len(VALIDATION_IMAGE_URLS) ``` -------------------------------- ### Create a Basic Image Comparison Order with Rapidata Python SDK Source: https://docs.rapidata.ai/examples/compare_order This Python code demonstrates how to initialize the RapidataClient and create a basic 'compare' order. It defines a list of prompts and corresponding image pairs (Flux vs. Midjourney) and then uses `create_compare_order` to set up the task. The order is configured with an instruction, datapoints (image pairs), responses per datapoint, and contexts (prompts). Finally, it runs the order, displays progress, and prints the results. ```python from rapidata import RapidataClient PROMPTS: list[str] = [ "A sign that says 'Diffusion'.", "A yellow flower sticking out of a green pot.", "hyperrealism render of a surreal alien humanoid.", "psychedelic duck", "A small blue book sitting on a large red book." ] # Image pairs to be matched with prompts (flux vs midjourney versions) IMAGE_PAIRS: list[list[str]] = [ ["https://assets.rapidata.ai/flux_sign_diffusion.jpg", "https://assets.rapidata.ai/mj_sign_diffusion.jpg"], ["https://assets.rapidata.ai/flux_flower.jpg", "https://assets.rapidata.ai/mj_flower.jpg"], ["https://assets.rapidata.ai/flux_alien.jpg", "https://assets.rapidata.ai/mj_alien.jpg"], ["https://assets.rapidata.ai/flux_duck.jpg", "https://assets.rapidata.ai/mj_duck.jpg"], ["https://assets.rapidata.ai/flux_book.jpg", "https://assets.rapidata.ai/mj_book.jpg"] ] if __name__ == "__main__": rapi = RapidataClient() order = rapi.order.create_compare_order( name="Example Image Prompt Alignment Order", instruction="Which image follows the prompt more accurately?", datapoints=IMAGE_PAIRS, responses_per_datapoint=25, contexts=PROMPTS, # prompt is the context for each image pair ).run() order.display_progress_bar() results = order.get_results() ``` -------------------------------- ### Create and Run a Ranking Order with Rapidata Python SDK Source: https://docs.rapidata.ai/examples/ranking_order This code initializes the RapidataClient, defines a list of image URLs (datapoints), and then creates and runs a ranking order. The order is configured to rank rabbit images, with an instruction focused on pairwise comparison, a total comparison budget of 50, and a random comparison ratio of 0.5. It then displays a progress bar, retrieves, and prints the results. ```Python from rapidata import RapidataClient DATAPOINTS = [ "https://assets.rapidata.ai/f9d92460-a362-493c-af91-bf50046453ae.webp", "https://assets.rapidata.ai/9bcd8b18-e9ad-4449-84d4-b3d72e200e9c.webp", "https://assets.rapidata.ai/266f6446-3ca8-4c2d-b070-13558b35a4e0.webp", "https://assets.rapidata.ai/f787f02c-e5d0-43ca-aa6e-aea747845cf3.webp", "https://assets.rapidata.ai/7e518a1b-4d1c-4a86-9109-26646684cc02.webp", "https://assets.rapidata.ai/10af47bd-3502-4534-b917-73dba5feaf76.webp", "https://assets.rapidata.ai/59725ca0-1fd5-4850-a15c-4221e191e293.webp", "https://assets.rapidata.ai/65d3939d-c1b8-433c-b180-13dae80f0519.webp", "https://assets.rapidata.ai/c13b8feb-fb97-4646-8dfc-97f05d37a637.webp", "https://assets.rapidata.ai/586dc517-c987-4d06-8a6f-553508b86356.webp", "https://assets.rapidata.ai/f4884ecd-cacb-4387-ab18-3b6e7dcdf10c.webp", "https://assets.rapidata.ai/79076f76-a432-4ef9-9007-6d09a218417a.webp" ] if __name__ == "__main__": rapi = RapidataClient() order = rapi.order.create_ranking_order( name="Example Ranking Order", instruction="Which rabbit looks cooler?", datapoints=DATAPOINTS, total_comparison_budget=50, #Make 50 comparisons, each comparison containing 2 datapoints random_comparisons_ratio=0.5 #First half of the comparisons are random, the second half are close matchups ).run() order.display_progress_bar() results = order.get_results() print(results) ``` -------------------------------- ### Initialize RapidataClient Instance Source: https://docs.rapidata.ai/reference/rapidata/rapidata_client/rapidata_client Initializes the RapidataClient instance, setting up the necessary authentication and internal service managers. It attempts to load credentials from a config file if not provided, or prompts for login. The client then initializes managers for orders, validation, and demographics. ```python def __init__( self, client_id: str | None = None, client_secret: str | None = None, environment: str = "rapidata.ai", oauth_scope: str = "openid", cert_path: str | None = None, token: dict | None = None, leeway: int = 60 ): """Initialize the RapidataClient. If both the client_id and client_secret are None, it will try using your credentials under "~/.config/rapidata/credentials.json". If this is not successful, it will open a browser window and ask you to log in, then save your new credentials in said json file. Args: client_id (str): The client ID for authentication. client_secret (str): The client secret for authentication. environment (str, optional): The API endpoint. oauth_scope (str, optional): The scopes to use for authentication. In general this does not need to be changed. cert_path (str, optional): An optional path to a certificate file useful for development. token (dict, optional): If you already have a token that the client should use for authentication. Important, if set, this needs to be the complete token object containing the access token, token type and expiration time. leeway (int, optional): An optional leeway to use to determine if a token is expired. Defaults to 60 seconds. Attributes: order (RapidataOrderManager): The RapidataOrderManager instance. validation (ValidationSetManager): The ValidationSetManager instance. """ logger.debug("Checking version") self._check_version() logger.debug("Initializing OpenAPIService") self._openapi_service = OpenAPIService( client_id=client_id, client_secret=client_secret, environment=environment, oauth_scope=oauth_scope, cert_path=cert_path, token=token, leeway=leeway, ) logger.debug("Initializing RapidataOrderManager") self.order = RapidataOrderManager(openapi_service=self._openapi_service) logger.debug("Initializing ValidationSetManager") self.validation = ValidationSetManager(openapi_service=self._openapi_service) logger.debug("Initializing DemographicManager") self._demographic = DemographicManager(openapi_service=self._openapi_service) ``` -------------------------------- ### Python Example: Data Structure for Select Words Truths Source: https://docs.rapidata.ai/reference/rapidata/rapidata_client/validation/validation_set_manager Illustrative example of the `datapoints`, `sentences`, and `truths` parameters for the `create_select_words_set` function. It demonstrates how word indices map to correct selections within sentences for given datapoints. ```Python datapoints: ["datapoint1", "datapoint2"] sentences: ["this example 1", "this example with another text"] truths: [[0, 1], [2]] ``` -------------------------------- ### Execute Full Rapidata AI Classification Workflow Source: https://docs.rapidata.ai/examples/classify_order This `main` function orchestrates the complete Rapidata AI workflow. It initializes the client, creates a validation set, then defines and runs a classification order. The order is configured with instructions, answer options, contexts, datapoints, and links to the previously created validation set. It also includes steps to display progress and retrieve results. ```python def main(): """Run the complete example workflow""" # Initialize the client client = RapidataClient() # Step 1: Create validation set validation_set_id = create_validation_set(client) print(f"Created validation set with ID: {validation_set_id}") # Step 2: Create and run the classification order print("Creating and running classification order...") order = client.order.create_classification_order( name="Likert Scale Example", instruction=INSTRUCTION, answer_options=ANSWER_OPTIONS, contexts=CONTEXTS, datapoints=IMAGE_URLS, validation_set_id=validation_set_id, # Using our validation set responses_per_datapoint=25, settings=[NoShuffle()] # Keep Likert scale in order ).run() # Start the order order.display_progress_bar() results = order.get_results() print(results) ``` -------------------------------- ### Example: Data for create_draw_set Source: https://docs.rapidata.ai/reference/rapidata/rapidata_client/validation/validation_set_manager Illustrates the structure of `datapoints` and `truths` lists for use with the `create_draw_set` function, showing how they map to validation scenarios. ```Python datapoints: ["datapoint1", "datapoint2"] truths: [[Box(0, 0, 100, 100)], [Box(50, 50, 150, 150)]] ``` -------------------------------- ### Create and Run Rapidata Video Comparison Order Source: https://docs.rapidata.ai/index This Python snippet shows how to create a comparison order for videos using the RapidataClient. It compares two video URLs based on a given instruction and context, displays progress, and retrieves the evaluation results. ```Python from rapidata import RapidataClient rapi = RapidataClient() order = rapi.order.create_compare_order( name="Example Video Comparison", instruction="Which video fits the description better?", contexts=["A group of elephants painting vibrant murals on a city wall during a lively street festival."], datapoints=[["https://assets.rapidata.ai/0074_sora_1.mp4", "https://assets.rapidata.ai/0074_hunyuan_1724.mp4"]], ).run() order.display_progress_bar() results = order.get_results() print(results) ``` -------------------------------- ### Example: Defining datapoints and truths for timestamp validation Source: https://docs.rapidata.ai/reference/rapidata/rapidata_client/validation/validation_set_manager Illustrates how to structure the `datapoints` and `truths` parameters for the `create_timestamp_set` function, showing the mapping between datapoints and their corresponding time intervals. ```Python datapoints: ["datapoint1", "datapoint2"]\ntruths: [[(0, 10)], [(20, 30)]] ``` -------------------------------- ### Example: Defining truths for locate validation set Source: https://docs.rapidata.ai/reference/rapidata/rapidata_client/validation/validation_set_manager Illustrates how to structure `datapoints` and `truths` for the `create_locate_set` method, showing the mapping of bounding box truths to individual datapoints. ```Python datapoints: ["datapoint1", "datapoint2"] truths: [[Box(0, 0, 100, 100)], [Box(50, 50, 150, 150)]] ``` -------------------------------- ### Example: `truths` Parameter Data Structure Source: https://docs.rapidata.ai/reference/rapidata/rapidata_client/validation/validation_set_manager Illustrates the expected structure for the `options`, `datapoints`, and `truths` parameters when calling `create_classification_set`. It demonstrates how to specify multiple correct answers for a single datapoint. ```Python options: ["yes", "no", "maybe"] datapoints: ["datapoint1", "datapoint2"] truths: [["yes"], ["no", "maybe"]] ``` -------------------------------- ### API & Python: Get Validation Set by ID Source: https://docs.rapidata.ai/reference/rapidata/rapidata_client/validation/validation_set_manager This section includes both the API documentation and the Python implementation for the `get_validation_set_by_id` method. This method allows for the retrieval of an existing validation set using its unique identifier. ```APIDOC get_validation_set_by_id( validation_set_id: str, ) -> RapidataValidationSet Get a validation set by ID. Parameters: - validation_set_id (str, required): The ID of the validation set. Returns: - RapidataValidationSet: The ValidationSet instance. ``` ```python def get_validation_set_by_id(self, validation_set_id: str) -> RapidataValidationSet: """Get a validation set by ID. Args: validation_set_id (str): The ID of the validation set. Returns: RapidataValidationSet: The ValidationSet instance. """ validation_set = self.__openapi_service.validation_api.validation_set_validation_set_id_get(validation_set_id=validation_set_id) return RapidataValidationSet(validation_set_id, str(validation_set.name), self.__openapi_service) ``` -------------------------------- ### Create and Run Rapidata Image Comparison Order Source: https://docs.rapidata.ai/index This Python snippet demonstrates how to create a comparison order for images using the RapidataClient. It compares two image URLs based on a given instruction and context, displays progress, and retrieves the evaluation results. ```Python from rapidata import RapidataClient rapi = RapidataClient() order = rapi.order.create_compare_order( name="Example Image Comparison", instruction="Which image matches the description better?", contexts=["A small blue book sitting on a large red book."], datapoints=[["https://assets.rapidata.ai/midjourney-5.2_37_3.jpg", "https://assets.rapidata.ai/flux-1-pro_37_0.jpg"]], ).run() order.display_progress_bar() results = order.get_results() print(results) ``` -------------------------------- ### Create Rapidata Locate Order for Image Artifact Detection Source: https://docs.rapidata.ai/examples/locate_order This Python code demonstrates how to initialize the RapidataClient and create a 'Locate' order. The order is configured to detect visual glitches in a set of image URLs, providing specific instructions to annotators and setting parameters like responses per datapoint, optional response time alerts, and a pre-defined validation set ID. ```python from rapidata import RapidataClient, RapidataSettings IMAGE_URLS = ["https://assets.rapidata.ai/eac11c3e-ad57-402b-90ed-23378d2ff869.jpg", "https://assets.rapidata.ai/04e7e3c6-5554-47ca-bdb2-950e48ac3e6c.jpg", "https://assets.rapidata.ai/91d9913c-b399-47f8-ad19-767798cc951c.jpg", "https://assets.rapidata.ai/d1cbf51d-7712-4819-96b4-20e030c573de.jpg"] if __name__ == "__main__": rapi = RapidataClient() order = rapi.order.create_locate_order( name="Artifact detection example", instruction="Look close, find incoherent errors, like senseless or malformed objects, incomprehensible details, or visual glitches? Tap to select.", datapoints=IMAGE_URLS, responses_per_datapoint=35, settings=[RapidataSettings.alert_on_fast_response(2500)], # This is optional, it will alert you if the annotators are responding before 2.5 seconds validation_set_id="6768a557026456ec851f51f9" # in this example, the validation set has already been created ).run() ```