#!/bin/bash

# Check if tensorflowjs is installed
if ! command -v tensorflowjs_converter &> /dev/null
then
    echo "tensorflowjs_converter could not be found. Please install it using: pip install tensorflowjs"
    exit 1
fi

MODEL_TYPE=$1
INPUT_MODEL=$2
OUTPUT_DIR=$3

if [ -z "$MODEL_TYPE" ] || [ -z "$INPUT_MODEL" ] || [ -z "$OUTPUT_DIR" ]; then
    echo "Usage: ./convert_model.sh [suit|value] [path_to_h5_model] [output_directory]"
    exit 1
fi

echo "Converting $MODEL_TYPE model from $INPUT_MODEL to $OUTPUT_DIR..."

# Create output directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"

# Perform conversion
tensorflowjs_converter --input_format=keras "$INPUT_MODEL" "$OUTPUT_DIR"

if [ $? -eq 0 ]; then
    echo "Conversion successful. Model saved to $OUTPUT_DIR"
else
    echo "Conversion failed."
    exit 1
fi
