#!/bin/bash

HF_DATASET_REPO="InstaDeepAI/mlipaudit-results"
HF_DATASET_LOCAL_PATH="/app/results"

echo "Attempting to download dataset from ${HF_DATASET_REPO} to ${HF_DATASET_LOCAL_PATH}..."

# Ensure the local data directory exists
mkdir -p ${HF_DATASET_LOCAL_PATH}

hf download ${HF_DATASET_REPO} --local-dir ${HF_DATASET_LOCAL_PATH} --repo-type dataset

# Find all regular files (-type f) in the downloaded directory and its subdirectories, and delete them.
find "${HF_DATASET_LOCAL_PATH}" -maxdepth 1 -type f -delete

if [ $? -eq 0 ]; then
    echo "Dataset downloaded successfully!"
else
    echo "Failed to download dataset."
    exit 1 # Exit if download fails
fi

echo "Starting Streamlit app..."
exec mlipaudit gui /app/results --is-public

