From 6583dc84c082773443fc3973b1cdf8095fa3fec3 Mon Sep 17 00:00:00 2001 From: lopagela Date: Mon, 6 Nov 2023 14:31:26 +0100 Subject: [PATCH] feat: Disable Gradio Analytics (#1165) * Disable Gradio Analytics Gradio analytics can be disabled by either using the kwargs `enable_analytics` on `gr.Blocks`, or by setting the env variable `GRADIO_ANALYTICS_ENABLED` to something different from `True`. Since that Gradio does not seem to respect their code contract (around `enable_analytics`), and that they are performing other operations only based on the value of `GRADIO_ANALYTICS_ENABLED` (c.f. `gradio.strings` https://github.com/gradio-app/gradio/blob/main/gradio/strings.py#L39), we are disabling gradio analytics by setting the required env variable to `False`. Note: Setting an environment variables using `os.environ['foo'] = 'bar'` on system that are not based on unix might not work. c.f. https://docs.python.org/3/library/os.html#os.environ for details on how `os.environ` works and all its caveats * Update private_gpt/__init__.py --- private_gpt/__init__.py | 12 ++++++++++++ private_gpt/ui/ui.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/private_gpt/__init__.py b/private_gpt/__init__.py index 1f409831e..995365c8d 100644 --- a/private_gpt/__init__.py +++ b/private_gpt/__init__.py @@ -1,5 +1,6 @@ """private-gpt.""" import logging +import os # Set to 'DEBUG' to have extensive logging turned on, even for libraries ROOT_LOG_LEVEL = "INFO" @@ -9,3 +10,14 @@ ) logging.basicConfig(level=ROOT_LOG_LEVEL, format=PRETTY_LOG_FORMAT, datefmt="%H:%M:%S") logging.captureWarnings(True) + +# Disable gradio analytics +# This is done this way because gradio does not solely rely on what values are +# passed to gr.Blocks(enable_analytics=...) but also on the environment +# variable GRADIO_ANALYTICS_ENABLED. `gradio.strings` actually reads this env +# directly, so to fully disable gradio analytics we need to set this env var. +os.environ["GRADIO_ANALYTICS_ENABLED"] = "False" + +# Disable chromaDB telemetry +# It is already disabled, see PR#1144 +# os.environ["ANONYMIZED_TELEMETRY"] = "False" diff --git a/private_gpt/ui/ui.py b/private_gpt/ui/ui.py index 9a276e61d..a5a6ff6ac 100644 --- a/private_gpt/ui/ui.py +++ b/private_gpt/ui/ui.py @@ -111,7 +111,7 @@ def _upload_file(file: TextIO) -> list[list[str]]: "}" ".logo img { height: 25% }", ) as blocks: - with gr.Blocks(), gr.Row(): + with gr.Row(): gr.HTML(f"