Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
Add User-Agent (#12)
Browse files Browse the repository at this point in the history
* Feat: add User-Agent header
---------

Signed-off-by: AnyISalIn <[email protected]>
  • Loading branch information
AnyISalIn authored Jul 11, 2023
1 parent 85938ac commit 93f575e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
17 changes: 14 additions & 3 deletions extension/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@
import json
from types import SimpleNamespace
from .utils import image_to_base64, read_image_files
from .version import __version__

OMNIINFER_CONFIG = os.path.join(os.path.dirname(os.path.abspath(__file__)),
'.omniinfer.json')


def _user_agent(model_name=None):
if model_name:
return 'sd-webui-cloud-inference/{} (model_name: {})'.format(__version__, model_name)
return 'sd-webui-cloud-inference/{}'.format(__version__)


class BaseAPI(object):

def txt2img(self, p) -> list[Image.Image]:
Expand Down Expand Up @@ -112,6 +119,7 @@ def __init__(self, token=None):
self._token = token
self._models = None
self._session = requests.Session()
self._session.headers.update({'User-Agent': _user_agent()})

@classmethod
def load_from_config(cls):
Expand Down Expand Up @@ -231,7 +239,8 @@ def _txt2img(self, model_name, prompts, neg_prompts, sampler_name,
"accept": "application/json",
"content-type": "application/json",
'Accept-Encoding': 'gzip, deflate',
"X-OmniInfer-Source": "source"
"X-OmniInfer-Source": _user_agent(model_name),
"User-Agent": _user_agent(model_name)
}

try:
Expand Down Expand Up @@ -284,7 +293,8 @@ def _img2img(self, model_name, prompts, neg_prompts, sampler_name,
"accept": "application/json",
"content-type": "application/json",
'Accept-Encoding': 'gzip, deflate',
"X-OmniInfer-Source": "sd-webui"
"X-OmniInfer-Source": _user_agent(model_name),
"User-Agent": _user_agent(model_name)
}

res = requests.post("http://api.omniinfer.io/v2/img2img",
Expand Down Expand Up @@ -527,7 +537,8 @@ def refresh_models(self):
headers = {
"accept": "application/json",
'Accept-Encoding': 'gzip, deflate',
"X-OmniInfer-Source": "sd-webui"
"X-OmniInfer-Source": _user_agent(),
"User-Agent": _user_agent()
}

print("[cloud-inference] refreshing models...")
Expand Down
1 change: 1 addition & 0 deletions extension/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.1.2"

0 comments on commit 93f575e

Please sign in to comment.