#!/bin/bash

cp /scripts/llama-factory.conf /etc/nginx/conf.d/
sed -i "s/LLAMA_FACTORY_NGINX_PORT/$LLAMA_FACTORY_NGINX_PORT/g" /etc/nginx/conf.d/llama-factory.conf
sed -i "s/GRADIO_SERVER_PORT/$GRADIO_SERVER_PORT/g" /etc/nginx/conf.d/llama-factory.conf
service nginx restart

cd /opt/LLaMA-Factory

if [ -f cache/hugging_face_token_file ]; then
  HUGGING_FACE_TOKEN=$(cat cache/hugging_face_token_file)
  if [ -n "$HUGGING_FACE_TOKEN" ]; then
    huggingface-cli login --token $HUGGING_FACE_TOKEN
  fi
  unset HUGGING_FACE_TOKEN
fi


llamafactory-cli webui