From 4164e2941692312ecc6f0edfeeaae16d7c409c61 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Sun, 25 Feb 2024 15:06:08 -0800 Subject: [PATCH] Block the "To create a public link, set share=True" gradio message --- modules/block_requests.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modules/block_requests.py b/modules/block_requests.py index 38f1a17f..fbc45de4 100644 --- a/modules/block_requests.py +++ b/modules/block_requests.py @@ -7,6 +7,7 @@ from modules.logging_colors import logger original_open = open original_get = requests.get +original_print = print class RequestBlocker: @@ -22,9 +23,11 @@ class OpenMonkeyPatch: def __enter__(self): builtins.open = my_open + builtins.print = my_print def __exit__(self, exc_type, exc_value, traceback): builtins.open = original_open + builtins.print = original_print def my_get(url, **kwargs): @@ -45,3 +48,15 @@ def my_open(*args, **kwargs): return io.BytesIO(file_contents) else: return original_open(*args, **kwargs) + + +def my_print(*args, **kwargs): + if len(args) > 0 and 'To create a public link, set `share=True`' in args[0]: + return + else: + if len(args) > 0 and 'Running on local URL' in args[0]: + args = list(args) + args[0] = f"\n{args[0].strip()}\n" + args = tuple(args) + + original_print(*args, **kwargs)