import subprocess


def install():
    try:
        try:
            from guardrails import Guard
        except Exception as e:
            result = subprocess.call(["pip", "install", "-U", "guardrails-ai==0.4.2"])
            if result != 0:
                print("Guardrails installation failed")

        try:
            from guardrails.hub import GibberishText
        except Exception as e:
            result = subprocess.call(
                ["guardrails", "hub", "install", "hub://guardrails/gibberish_text"]
            )
            if result != 0:
                print(
                    "Guardrails installation failed. Ensure have the latest version of pip installed"
                )

        try:
            from guardrails.hub import SensitiveTopic
        except Exception as e:
            result = subprocess.call(
                ["guardrails", "hub", "install", "hub://guardrails/sensitive_topics"]
            )
            if result != 0:
                print(
                    "Guardrails installation failed. Ensure have the latest version of pip installed"
                )

        try:
            from guardrails.hub import NSFWText
        except Exception as e:
            result = subprocess.call(
                ["guardrails", "hub", "install", "hub://guardrails/nsfw_text"]
            )
            if result != 0:
                print(
                    "Guardrails installation failed. Ensure have the latest version of pip installed"
                )

        try:
            from guardrails.hub import ProfanityFree
        except Exception as e:
            result = subprocess.call(
                ["guardrails", "hub", "install", "hub://guardrails/profanity_free"]
            )
            if result != 0:
                print(
                    "Guardrails installation failed. Ensure have the latest version of pip installed"
                )
            else:
                print("Guardrails ProfanityFree validator installation successful")

        try:
            from guardrails.hub import DetectPII
        except Exception as e:
            result = subprocess.call(
                ["guardrails", "hub", "install", "hub://guardrails/detect_pii"]
            )
            if result != 0:
                print(
                    "Guardrails installation failed. Ensure have the latest version of pip installed"
                )
            else:
                print("Guardrails DetectPII validator installation successful")

        try:
            from guardrails.hub import ReadingTime
        except Exception as e:
            result = subprocess.call(
                ["guardrails", "hub", "install", "hub://guardrails/reading_time"]
            )
            if result != 0:
                print(
                    "Guardrails installation failed. Ensure have the latest version of pip installed"
                )
            else:
                print("Guardrails ReadingTime validator installation successful")

        try:
            from guardrails.hub import ToxicLanguage
        except Exception as e:
            result = subprocess.call(
                ["guardrails", "hub", "install", "hub://guardrails/toxic_language"]
            )
            if result != 0:
                print(
                    "Guardrails installation failed. Ensure have the latest version of pip installed"
                )
            else:
                print("Guardrails ToxicLanguage validator installation successful")

        try:
            from guardrails.hub import CorrectLanguage
        except Exception as e:
            result = subprocess.call(
                ["guardrails", "hub", "install", "hub://scb-10x/correct_language"]
            )
            if result != 0:
                print(
                    "Guardrails installation failed. Ensure have the latest version of pip installed"
                )
            else:
                print("Guardrails CorrectLanguage validator installation successful")

        try:
            from guardrails.hub import SecretsPresent
        except Exception as e:
            result = subprocess.call(
                ["guardrails", "hub", "install", "hub://guardrails/secrets_present"]
            )
            if result != 0:
                print(
                    "Guardrails installation failed. Ensure have the latest version of pip installed"
                )
            else:
                print("Guardrails SecretsPresent validator installation successful")

        try:
            from guardrails.hub import RestrictToTopic
        except Exception as e:
            result = subprocess.call(
                ["guardrails", "hub", "install", "hub://tryolabs/restricttotopic"]
            )
            if result != 0:
                print(
                    "Guardrails installation failed. Ensure have the latest version of pip installed"
                )
            else:
                print("Guardrails RestrictToTopic validator installation successful")

        try:
            from guardrails.hub import UnusualPrompt
        except Exception as e:
            result = subprocess.call(
                ["guardrails", "hub", "install", "hub://guardrails/unusual_prompt"]
            )
            if result != 0:
                print(
                    "Guardrails installation failed. Ensure have the latest version of pip installed"
                )
            else:
                print("Guardrails UnusualPrompt validator installation successful")

        try:
            from guardrails.hub import PolitenessCheck
        except Exception as e:
            result = subprocess.call(
                ["guardrails", "hub", "install", "hub://guardrails/politeness_check"]
            )
            if result != 0:
                print(
                    "Guardrails installation failed. Ensure have the latest version of pip installed"
                )
            else:
                print("Guardrails PolitenessCheck validator installation successful")

        try:
            import nltk
            import ssl

            try:
                _create_unverified_https_context = ssl._create_unverified_context
            except AttributeError:
                pass
            else:
                ssl._create_default_https_context = _create_unverified_https_context
            nltk.download("punkt")
        except Exception as e:
            print(f"Error: {e}")
    except Exception as e:
        print(f"Error: {e}")
