mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-11-26 01:30:20 +01:00
Add modules/block_requests.py
This has become unnecessary, but it could be useful in the future for other libraries.
This commit is contained in:
parent
687fd2604a
commit
09c781b16f
19
modules/block_requests.py
Normal file
19
modules/block_requests.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
from modules.logging_colors import logger
|
||||||
|
|
||||||
|
|
||||||
|
class RequestBlocker:
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
self.original_get = requests.get
|
||||||
|
requests.get = my_get
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_value, traceback):
|
||||||
|
requests.get = self.original_get
|
||||||
|
|
||||||
|
|
||||||
|
def my_get(url, **kwargs):
|
||||||
|
logger.info('Unwanted HTTP request redirected to localhost :)')
|
||||||
|
kwargs.setdefault('allow_redirects', True)
|
||||||
|
return requests.api.request('get', 'http://127.0.0.1/', **kwargs)
|
17
server.py
17
server.py
@ -1,26 +1,15 @@
|
|||||||
import os
|
import os
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
import requests
|
|
||||||
|
|
||||||
from modules.logging_colors import logger
|
from modules.logging_colors import logger
|
||||||
|
from modules.block_requests import RequestBlocker
|
||||||
|
|
||||||
os.environ['GRADIO_ANALYTICS_ENABLED'] = 'False'
|
os.environ['GRADIO_ANALYTICS_ENABLED'] = 'False'
|
||||||
os.environ['BITSANDBYTES_NOWELCOME'] = '1'
|
os.environ['BITSANDBYTES_NOWELCOME'] = '1'
|
||||||
warnings.filterwarnings('ignore', category=UserWarning, message='TypedStorage is deprecated')
|
warnings.filterwarnings('ignore', category=UserWarning, message='TypedStorage is deprecated')
|
||||||
|
|
||||||
|
with RequestBlocker():
|
||||||
# This is a hack to prevent Gradio from phoning home when it gets imported
|
import gradio as gr
|
||||||
def my_get(url, **kwargs):
|
|
||||||
logger.info('Gradio HTTP request redirected to localhost :)')
|
|
||||||
kwargs.setdefault('allow_redirects', True)
|
|
||||||
return requests.api.request('get', 'http://127.0.0.1/', **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
original_get = requests.get
|
|
||||||
requests.get = my_get
|
|
||||||
import gradio as gr
|
|
||||||
requests.get = original_get
|
|
||||||
|
|
||||||
import matplotlib
|
import matplotlib
|
||||||
matplotlib.use('Agg') # This fixes LaTeX rendering on some systems
|
matplotlib.use('Agg') # This fixes LaTeX rendering on some systems
|
||||||
|
Loading…
Reference in New Issue
Block a user