fa041677180ea69638193882a16d82d986bd9d622f496af1a36c5226756a5355
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +1 -0
- sd-webui-stablesr/srmodule/__pycache__/struct_cond.cpython-310.pyc +0 -0
- sd-webui-stablesr/srmodule/attn.py +111 -0
- sd-webui-stablesr/srmodule/colorfix.py +114 -0
- sd-webui-stablesr/srmodule/spade.py +206 -0
- sd-webui-stablesr/srmodule/struct_cond.py +353 -0
- sd-webui-stablesr/tools/extract_srmodule.py +20 -0
- sd-webui-stablesr/tools/extract_vaecfw.py +20 -0
- sd_feed/.DS_Store +0 -0
- sd_feed/.gitignore +5 -0
- sd_feed/Readme.md +82 -0
- sd_feed/assets/5ulvww8bblta1.webp +0 -0
- sd_feed/assets/extensions.png +0 -0
- sd_feed/assets/feed.png +0 -0
- sd_feed/assets/feedsetting1.png +0 -0
- sd_feed/assets/lhijrt5lblta1.webp +0 -0
- sd_feed/assets/pinterest.png +3 -0
- sd_feed/assets/potd.png +0 -0
- sd_feed/assets/share.png +0 -0
- sd_feed/assets/shareandearn.png +0 -0
- sd_feed/html/feedtab.html +291 -0
- sd_feed/html/lora.html +24 -0
- sd_feed/html/potd.html +135 -0
- sd_feed/html/profile.html +21 -0
- sd_feed/install.py +5 -0
- sd_feed/javascript/axios.min.js +2 -0
- sd_feed/javascript/best_feed.js +638 -0
- sd_feed/javascript/goosviewmodel.js +860 -0
- sd_feed/javascript/loradownload.js +55 -0
- sd_feed/javascript/userprofile.js +74 -0
- sd_feed/javascript/vue.global.js +0 -0
- sd_feed/newtype_v3/__init__.py +0 -0
- sd_feed/newtype_v3/__pycache__/__init__.cpython-310.pyc +0 -0
- sd_feed/newtype_v3/__pycache__/images.cpython-310.pyc +0 -0
- sd_feed/newtype_v3/__pycache__/locs.cpython-310.pyc +0 -0
- sd_feed/newtype_v3/__pycache__/lora.cpython-310.pyc +0 -0
- sd_feed/newtype_v3/__pycache__/lora_types.cpython-310.pyc +0 -0
- sd_feed/newtype_v3/__pycache__/newtype_v3.cpython-310.pyc +0 -0
- sd_feed/newtype_v3/__pycache__/users.cpython-310.pyc +0 -0
- sd_feed/newtype_v3/images.py +279 -0
- sd_feed/newtype_v3/locs.py +10 -0
- sd_feed/newtype_v3/lora.py +32 -0
- sd_feed/newtype_v3/lora_types.py +7 -0
- sd_feed/newtype_v3/newtype_v3.py +293 -0
- sd_feed/newtype_v3/tabs/__init__.py +6 -0
- sd_feed/newtype_v3/tabs/__pycache__/__init__.cpython-310.pyc +0 -0
- sd_feed/newtype_v3/tabs/__pycache__/feed.cpython-310.pyc +0 -0
- sd_feed/newtype_v3/tabs/feed.py +26 -0
- sd_feed/newtype_v3/users.py +48 -0
- sd_feed/newtype_v3/utils/__init__.py +0 -0
.gitattributes
CHANGED
|
@@ -39,3 +39,4 @@ Auto-Photoshop-StableDiffusion-Plugin/docs/prompt_shortcut.gif filter=lfs diff=l
|
|
| 39 |
Stable-Diffusion-Webui-Civitai-Helper/img/all_in_one.png filter=lfs diff=lfs merge=lfs -text
|
| 40 |
posex/image/sample-webui2.jpg filter=lfs diff=lfs merge=lfs -text
|
| 41 |
posex/image/sample-webui2.png filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 39 |
Stable-Diffusion-Webui-Civitai-Helper/img/all_in_one.png filter=lfs diff=lfs merge=lfs -text
|
| 40 |
posex/image/sample-webui2.jpg filter=lfs diff=lfs merge=lfs -text
|
| 41 |
posex/image/sample-webui2.png filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
sd_feed/assets/pinterest.png filter=lfs diff=lfs merge=lfs -text
|
sd-webui-stablesr/srmodule/__pycache__/struct_cond.cpython-310.pyc
ADDED
|
Binary file (7.5 kB). View file
|
|
|
sd-webui-stablesr/srmodule/attn.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
This file is modified from the TiledVAE attn.py, so that the StableSR can save much VRAM.
|
| 3 |
+
'''
|
| 4 |
+
import math
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
from modules import shared, sd_hijack
|
| 8 |
+
from modules.sd_hijack_optimizations import get_available_vram, get_xformers_flash_attention_op, sub_quad_attention
|
| 9 |
+
|
| 10 |
+
try:
|
| 11 |
+
import xformers
|
| 12 |
+
import xformers.ops
|
| 13 |
+
except ImportError:
|
| 14 |
+
pass
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def get_attn_func():
|
| 18 |
+
method = sd_hijack.model_hijack.optimization_method
|
| 19 |
+
if method is None:
|
| 20 |
+
return attn_forward
|
| 21 |
+
method = method.lower()
|
| 22 |
+
# The method should be one of the following:
|
| 23 |
+
# ['none', 'sdp-no-mem', 'sdp', 'xformers', ''sub-quadratic', 'v1', 'invokeai', 'doggettx']
|
| 24 |
+
if method not in ['none', 'sdp-no-mem', 'sdp', 'xformers', 'sub-quadratic', 'v1', 'invokeai', 'doggettx']:
|
| 25 |
+
print(f"[StableSR] Warning: Unknown attention optimization method {method}. Please try to update the extension.")
|
| 26 |
+
return attn_forward
|
| 27 |
+
|
| 28 |
+
if method == 'none':
|
| 29 |
+
return attn_forward
|
| 30 |
+
elif method == 'xformers':
|
| 31 |
+
return xformers_attnblock_forward
|
| 32 |
+
elif method == 'sdp-no-mem':
|
| 33 |
+
return sdp_no_mem_attnblock_forward
|
| 34 |
+
elif method == 'sdp':
|
| 35 |
+
return sdp_attnblock_forward
|
| 36 |
+
elif method == 'sub-quadratic':
|
| 37 |
+
return sub_quad_attnblock_forward
|
| 38 |
+
elif method == 'doggettx':
|
| 39 |
+
return cross_attention_attnblock_forward
|
| 40 |
+
|
| 41 |
+
return attn_forward
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
# The following functions are all copied from modules.sd_hijack_optimizations
|
| 45 |
+
# However, the residual & normalization are removed and computed separately.
|
| 46 |
+
|
| 47 |
+
def attn_forward(q, k, v):
|
| 48 |
+
# compute attention
|
| 49 |
+
# q: b,hw,c
|
| 50 |
+
k = k.permute(0, 2, 1) # b,c,hw
|
| 51 |
+
c = k.shape[1]
|
| 52 |
+
w_ = torch.bmm(q, k) # b,hw,hw w[b,i,j]=sum_c q[b,i,c]k[b,c,j]
|
| 53 |
+
w_ = w_ * (int(c)**(-0.5))
|
| 54 |
+
w_ = torch.nn.functional.softmax(w_, dim=2)
|
| 55 |
+
|
| 56 |
+
# attend to values
|
| 57 |
+
v = v.permute(0, 2, 1) # b,c,hw
|
| 58 |
+
w_ = w_.permute(0, 2, 1) # b,hw,hw (first hw of k, second of q)
|
| 59 |
+
# b, c,hw (hw of q) h_[b,c,j] = sum_i v[b,c,i] w_[b,i,j]
|
| 60 |
+
h_ = torch.bmm(v, w_)
|
| 61 |
+
|
| 62 |
+
return h_.permute(0, 2, 1)
|
| 63 |
+
|
| 64 |
+
def xformers_attnblock_forward(q, k, v):
|
| 65 |
+
return xformers.ops.memory_efficient_attention(q, k, v, op=get_xformers_flash_attention_op(q, k, v))
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def cross_attention_attnblock_forward(q, k, v):
|
| 69 |
+
# compute attention
|
| 70 |
+
k = k.permute(0, 2, 1)# b,c,hw
|
| 71 |
+
v = v.permute(0, 2, 1)# b,c,hw
|
| 72 |
+
c = k.shape[1]
|
| 73 |
+
h_ = torch.zeros_like(k, device=q.device)
|
| 74 |
+
|
| 75 |
+
mem_free_total = get_available_vram()
|
| 76 |
+
|
| 77 |
+
tensor_size = q.shape[0] * q.shape[1] * k.shape[2] * q.element_size()
|
| 78 |
+
mem_required = tensor_size * 2.5
|
| 79 |
+
steps = 1
|
| 80 |
+
|
| 81 |
+
if mem_required > mem_free_total:
|
| 82 |
+
steps = 2**(math.ceil(math.log(mem_required / mem_free_total, 2)))
|
| 83 |
+
|
| 84 |
+
slice_size = q.shape[1] // steps if (q.shape[1] % steps) == 0 else q.shape[1]
|
| 85 |
+
for i in range(0, q.shape[1], slice_size):
|
| 86 |
+
end = i + slice_size
|
| 87 |
+
|
| 88 |
+
w1 = torch.bmm(q[:, i:end], k) # b,hw,hw w[b,i,j]=sum_c q[b,i,c]k[b,c,j]
|
| 89 |
+
w2 = w1 * (int(c)**(-0.5))
|
| 90 |
+
del w1
|
| 91 |
+
w3 = torch.nn.functional.softmax(w2, dim=2, dtype=q.dtype)
|
| 92 |
+
del w2
|
| 93 |
+
|
| 94 |
+
# attend to values
|
| 95 |
+
w4 = w3.permute(0, 2, 1) # b,hw,hw (first hw of k, second of q)
|
| 96 |
+
del w3
|
| 97 |
+
|
| 98 |
+
h_[:, :, i:end] = torch.bmm(v, w4) # b, c,hw (hw of q) h_[b,c,j] = sum_i v[b,c,i] w_[b,i,j]
|
| 99 |
+
del w4
|
| 100 |
+
|
| 101 |
+
return h_.permute(0, 2, 1)
|
| 102 |
+
|
| 103 |
+
def sdp_no_mem_attnblock_forward(q, k, v):
|
| 104 |
+
with torch.backends.cuda.sdp_kernel(enable_flash=True, enable_math=True, enable_mem_efficient=False):
|
| 105 |
+
return sdp_attnblock_forward(q, k, v)
|
| 106 |
+
|
| 107 |
+
def sdp_attnblock_forward(q, k, v):
|
| 108 |
+
return torch.nn.functional.scaled_dot_product_attention(q, k, v, dropout_p=0.0, is_causal=False)
|
| 109 |
+
|
| 110 |
+
def sub_quad_attnblock_forward(q, k, v):
|
| 111 |
+
return sub_quad_attention(q, k, v, q_chunk_size=shared.cmd_opts.sub_quad_q_chunk_size, kv_chunk_size=shared.cmd_opts.sub_quad_kv_chunk_size, chunk_threshold=shared.cmd_opts.sub_quad_chunk_threshold, use_checkpoint=True)
|
sd-webui-stablesr/srmodule/colorfix.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from PIL import Image
|
| 3 |
+
from torch import Tensor
|
| 4 |
+
from torch.nn import functional as F
|
| 5 |
+
|
| 6 |
+
from torchvision.transforms import ToTensor, ToPILImage
|
| 7 |
+
|
| 8 |
+
def adain_color_fix(target: Image, source: Image):
|
| 9 |
+
# Convert images to tensors
|
| 10 |
+
to_tensor = ToTensor()
|
| 11 |
+
target_tensor = to_tensor(target).unsqueeze(0)
|
| 12 |
+
source_tensor = to_tensor(source).unsqueeze(0)
|
| 13 |
+
|
| 14 |
+
# Apply adaptive instance normalization
|
| 15 |
+
result_tensor = adaptive_instance_normalization(target_tensor, source_tensor)
|
| 16 |
+
|
| 17 |
+
# Convert tensor back to image
|
| 18 |
+
to_image = ToPILImage()
|
| 19 |
+
result_image = to_image(result_tensor.squeeze(0).clamp_(0.0, 1.0))
|
| 20 |
+
|
| 21 |
+
return result_image
|
| 22 |
+
|
| 23 |
+
def wavelet_color_fix(target: Image, source: Image):
|
| 24 |
+
# Convert images to tensors
|
| 25 |
+
to_tensor = ToTensor()
|
| 26 |
+
target_tensor = to_tensor(target).unsqueeze(0)
|
| 27 |
+
source_tensor = to_tensor(source).unsqueeze(0)
|
| 28 |
+
|
| 29 |
+
# Apply wavelet reconstruction
|
| 30 |
+
result_tensor = wavelet_reconstruction(target_tensor, source_tensor)
|
| 31 |
+
|
| 32 |
+
# Convert tensor back to image
|
| 33 |
+
to_image = ToPILImage()
|
| 34 |
+
result_image = to_image(result_tensor.squeeze(0).clamp_(0.0, 1.0))
|
| 35 |
+
|
| 36 |
+
return result_image
|
| 37 |
+
|
| 38 |
+
def calc_mean_std(feat: Tensor, eps=1e-5):
|
| 39 |
+
"""Calculate mean and std for adaptive_instance_normalization.
|
| 40 |
+
Args:
|
| 41 |
+
feat (Tensor): 4D tensor.
|
| 42 |
+
eps (float): A small value added to the variance to avoid
|
| 43 |
+
divide-by-zero. Default: 1e-5.
|
| 44 |
+
"""
|
| 45 |
+
size = feat.size()
|
| 46 |
+
assert len(size) == 4, 'The input feature should be 4D tensor.'
|
| 47 |
+
b, c = size[:2]
|
| 48 |
+
feat_var = feat.view(b, c, -1).var(dim=2) + eps
|
| 49 |
+
feat_std = feat_var.sqrt().view(b, c, 1, 1)
|
| 50 |
+
feat_mean = feat.view(b, c, -1).mean(dim=2).view(b, c, 1, 1)
|
| 51 |
+
return feat_mean, feat_std
|
| 52 |
+
|
| 53 |
+
def adaptive_instance_normalization(content_feat:Tensor, style_feat:Tensor):
|
| 54 |
+
"""Adaptive instance normalization.
|
| 55 |
+
Adjust the reference features to have the similar color and illuminations
|
| 56 |
+
as those in the degradate features.
|
| 57 |
+
Args:
|
| 58 |
+
content_feat (Tensor): The reference feature.
|
| 59 |
+
style_feat (Tensor): The degradate features.
|
| 60 |
+
"""
|
| 61 |
+
size = content_feat.size()
|
| 62 |
+
style_mean, style_std = calc_mean_std(style_feat)
|
| 63 |
+
content_mean, content_std = calc_mean_std(content_feat)
|
| 64 |
+
normalized_feat = (content_feat - content_mean.expand(size)) / content_std.expand(size)
|
| 65 |
+
return normalized_feat * style_std.expand(size) + style_mean.expand(size)
|
| 66 |
+
|
| 67 |
+
def wavelet_blur(image: Tensor, radius: int):
|
| 68 |
+
"""
|
| 69 |
+
Apply wavelet blur to the input tensor.
|
| 70 |
+
"""
|
| 71 |
+
# input shape: (1, 3, H, W)
|
| 72 |
+
# convolution kernel
|
| 73 |
+
kernel_vals = [
|
| 74 |
+
[0.0625, 0.125, 0.0625],
|
| 75 |
+
[0.125, 0.25, 0.125],
|
| 76 |
+
[0.0625, 0.125, 0.0625],
|
| 77 |
+
]
|
| 78 |
+
kernel = torch.tensor(kernel_vals, dtype=image.dtype, device=image.device)
|
| 79 |
+
# add channel dimensions to the kernel to make it a 4D tensor
|
| 80 |
+
kernel = kernel[None, None]
|
| 81 |
+
# repeat the kernel across all input channels
|
| 82 |
+
kernel = kernel.repeat(3, 1, 1, 1)
|
| 83 |
+
image = F.pad(image, (radius, radius, radius, radius), mode='replicate')
|
| 84 |
+
# apply convolution
|
| 85 |
+
output = F.conv2d(image, kernel, groups=3, dilation=radius)
|
| 86 |
+
return output
|
| 87 |
+
|
| 88 |
+
def wavelet_decomposition(image: Tensor, levels=5):
|
| 89 |
+
"""
|
| 90 |
+
Apply wavelet decomposition to the input tensor.
|
| 91 |
+
This function only returns the low frequency & the high frequency.
|
| 92 |
+
"""
|
| 93 |
+
high_freq = torch.zeros_like(image)
|
| 94 |
+
for i in range(levels):
|
| 95 |
+
radius = 2 ** i
|
| 96 |
+
low_freq = wavelet_blur(image, radius)
|
| 97 |
+
high_freq += (image - low_freq)
|
| 98 |
+
image = low_freq
|
| 99 |
+
|
| 100 |
+
return high_freq, low_freq
|
| 101 |
+
|
| 102 |
+
def wavelet_reconstruction(content_feat:Tensor, style_feat:Tensor):
|
| 103 |
+
"""
|
| 104 |
+
Apply wavelet decomposition, so that the content will have the same color as the style.
|
| 105 |
+
"""
|
| 106 |
+
# calculate the wavelet decomposition of the content feature
|
| 107 |
+
content_high_freq, content_low_freq = wavelet_decomposition(content_feat)
|
| 108 |
+
del content_low_freq
|
| 109 |
+
# calculate the wavelet decomposition of the style feature
|
| 110 |
+
style_high_freq, style_low_freq = wavelet_decomposition(style_feat)
|
| 111 |
+
del style_high_freq
|
| 112 |
+
# reconstruct the content feature with the style's high frequency
|
| 113 |
+
return content_high_freq + style_low_freq
|
| 114 |
+
|
sd-webui-stablesr/srmodule/spade.py
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Copyright (C) 2019 NVIDIA Corporation. All rights reserved.
|
| 3 |
+
Licensed under the CC BY-NC-SA 4.0 license (https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode).
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import re
|
| 7 |
+
import torch
|
| 8 |
+
import torch.nn as nn
|
| 9 |
+
|
| 10 |
+
from ldm.modules.diffusionmodules.util import normalization, checkpoint
|
| 11 |
+
from ldm.modules.diffusionmodules.openaimodel import ResBlock, UNetModel
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class SPADE(nn.Module):
|
| 15 |
+
def __init__(self, norm_nc, label_nc=256, config_text='spadeinstance3x3'):
|
| 16 |
+
super().__init__()
|
| 17 |
+
assert config_text.startswith('spade')
|
| 18 |
+
parsed = re.search('spade(\D+)(\d)x\d', config_text)
|
| 19 |
+
ks = int(parsed.group(2))
|
| 20 |
+
self.param_free_norm = normalization(norm_nc)
|
| 21 |
+
|
| 22 |
+
# The dimension of the intermediate embedding space. Yes, hardcoded.
|
| 23 |
+
nhidden = 128
|
| 24 |
+
|
| 25 |
+
pw = ks // 2
|
| 26 |
+
self.mlp_shared = nn.Sequential(
|
| 27 |
+
nn.Conv2d(label_nc, nhidden, kernel_size=ks, padding=pw),
|
| 28 |
+
nn.ReLU()
|
| 29 |
+
)
|
| 30 |
+
self.mlp_gamma = nn.Conv2d(nhidden, norm_nc, kernel_size=ks, padding=pw)
|
| 31 |
+
self.mlp_beta = nn.Conv2d(nhidden, norm_nc, kernel_size=ks, padding=pw)
|
| 32 |
+
|
| 33 |
+
def forward(self, x_dic, segmap_dic):
|
| 34 |
+
return checkpoint(
|
| 35 |
+
self._forward, (x_dic, segmap_dic), self.parameters(), True
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
def _forward(self, x_dic, segmap_dic):
|
| 39 |
+
segmap = segmap_dic[str(x_dic.size(-1))]
|
| 40 |
+
x = x_dic
|
| 41 |
+
|
| 42 |
+
# Part 1. generate parameter-free normalized activations
|
| 43 |
+
normalized = self.param_free_norm(x)
|
| 44 |
+
|
| 45 |
+
# Part 2. produce scaling and bias conditioned on semantic map
|
| 46 |
+
# segmap = F.interpolate(segmap, size=x.size()[2:], mode='nearest')
|
| 47 |
+
actv = self.mlp_shared(segmap)
|
| 48 |
+
|
| 49 |
+
repeat_factor = normalized.shape[0]//segmap.shape[0]
|
| 50 |
+
if repeat_factor > 1:
|
| 51 |
+
out = normalized
|
| 52 |
+
out *= (1 + self.mlp_gamma(actv).repeat_interleave(repeat_factor, dim=0))
|
| 53 |
+
out += self.mlp_beta(actv).repeat_interleave(repeat_factor, dim=0)
|
| 54 |
+
else:
|
| 55 |
+
out = normalized
|
| 56 |
+
out *= (1 + self.mlp_gamma(actv))
|
| 57 |
+
out += self.mlp_beta(actv)
|
| 58 |
+
return out
|
| 59 |
+
|
| 60 |
+
def dual_resblock_forward(self: ResBlock, x, emb, spade: SPADE, get_struct_cond):
|
| 61 |
+
if self.updown:
|
| 62 |
+
in_rest, in_conv = self.in_layers[:-1], self.in_layers[-1]
|
| 63 |
+
h = in_rest(x)
|
| 64 |
+
h = self.h_upd(h)
|
| 65 |
+
x = self.x_upd(x)
|
| 66 |
+
h = in_conv(h)
|
| 67 |
+
else:
|
| 68 |
+
h = self.in_layers(x)
|
| 69 |
+
emb_out = self.emb_layers(emb).type(h.dtype)
|
| 70 |
+
while len(emb_out.shape) < len(h.shape):
|
| 71 |
+
emb_out = emb_out[..., None]
|
| 72 |
+
if self.use_scale_shift_norm:
|
| 73 |
+
out_norm, out_rest = self.out_layers[0], self.out_layers[1:]
|
| 74 |
+
scale, shift = torch.chunk(emb_out, 2, dim=1)
|
| 75 |
+
h = out_norm(h) * (1 + scale) + shift
|
| 76 |
+
h = out_rest(h)
|
| 77 |
+
else:
|
| 78 |
+
h = h + emb_out
|
| 79 |
+
h = self.out_layers(h)
|
| 80 |
+
h = spade(h, get_struct_cond())
|
| 81 |
+
return self.skip_connection(x) + h
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
class SPADELayers(nn.Module):
|
| 85 |
+
def __init__(self):
|
| 86 |
+
'''
|
| 87 |
+
A container class for fast SPADE layer loading.
|
| 88 |
+
params inferred from the official checkpoint
|
| 89 |
+
'''
|
| 90 |
+
super().__init__()
|
| 91 |
+
self.input_blocks = nn.ModuleList([
|
| 92 |
+
nn.Identity(),
|
| 93 |
+
SPADE(320),
|
| 94 |
+
SPADE(320),
|
| 95 |
+
nn.Identity(),
|
| 96 |
+
SPADE(640),
|
| 97 |
+
SPADE(640),
|
| 98 |
+
nn.Identity(),
|
| 99 |
+
SPADE(1280),
|
| 100 |
+
SPADE(1280),
|
| 101 |
+
nn.Identity(),
|
| 102 |
+
SPADE(1280),
|
| 103 |
+
SPADE(1280),
|
| 104 |
+
])
|
| 105 |
+
self.middle_block = nn.ModuleList([
|
| 106 |
+
SPADE(1280),
|
| 107 |
+
nn.Identity(),
|
| 108 |
+
SPADE(1280),
|
| 109 |
+
])
|
| 110 |
+
self.output_blocks = nn.ModuleList([
|
| 111 |
+
SPADE(1280),
|
| 112 |
+
SPADE(1280),
|
| 113 |
+
SPADE(1280),
|
| 114 |
+
SPADE(1280),
|
| 115 |
+
SPADE(1280),
|
| 116 |
+
SPADE(1280),
|
| 117 |
+
SPADE(640),
|
| 118 |
+
SPADE(640),
|
| 119 |
+
SPADE(640),
|
| 120 |
+
SPADE(320),
|
| 121 |
+
SPADE(320),
|
| 122 |
+
SPADE(320),
|
| 123 |
+
])
|
| 124 |
+
self.input_ids = [1,2,4,5,7,8,10,11]
|
| 125 |
+
self.output_ids = list(range(12))
|
| 126 |
+
self.mid_ids = [0,2]
|
| 127 |
+
self.forward_cache_name = 'org_forward_stablesr'
|
| 128 |
+
self.unet = None
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def hook(self, unet: UNetModel, get_struct_cond):
|
| 132 |
+
# hook all resblocks
|
| 133 |
+
self.unet = unet
|
| 134 |
+
resblock: ResBlock = None
|
| 135 |
+
for i in self.input_ids:
|
| 136 |
+
resblock = unet.input_blocks[i][0]
|
| 137 |
+
# debug
|
| 138 |
+
# assert isinstance(resblock, ResBlock)
|
| 139 |
+
if not hasattr(resblock, self.forward_cache_name):
|
| 140 |
+
setattr(resblock, self.forward_cache_name, resblock._forward)
|
| 141 |
+
resblock._forward = lambda x, timesteps, resblock=resblock, spade=self.input_blocks[i]: dual_resblock_forward(resblock, x, timesteps, spade, get_struct_cond)
|
| 142 |
+
|
| 143 |
+
for i in self.output_ids:
|
| 144 |
+
resblock = unet.output_blocks[i][0]
|
| 145 |
+
# debug
|
| 146 |
+
# assert isinstance(resblock, ResBlock)
|
| 147 |
+
if not hasattr(resblock, self.forward_cache_name):
|
| 148 |
+
setattr(resblock, self.forward_cache_name, resblock._forward)
|
| 149 |
+
resblock._forward = lambda x, timesteps, resblock=resblock, spade=self.output_blocks[i]: dual_resblock_forward(resblock, x, timesteps, spade, get_struct_cond)
|
| 150 |
+
|
| 151 |
+
for i in self.mid_ids:
|
| 152 |
+
resblock = unet.middle_block[i]
|
| 153 |
+
# debug
|
| 154 |
+
# assert isinstance(resblock, ResBlock)
|
| 155 |
+
if not hasattr(resblock, self.forward_cache_name):
|
| 156 |
+
setattr(resblock, self.forward_cache_name, resblock._forward)
|
| 157 |
+
resblock._forward = lambda x, timesteps, resblock=resblock, spade=self.middle_block[i]: dual_resblock_forward(resblock, x, timesteps, spade, get_struct_cond)
|
| 158 |
+
|
| 159 |
+
def unhook(self):
|
| 160 |
+
unet = self.unet
|
| 161 |
+
if unet is None: return
|
| 162 |
+
resblock: ResBlock = None
|
| 163 |
+
for i in self.input_ids:
|
| 164 |
+
resblock = unet.input_blocks[i][0]
|
| 165 |
+
if hasattr(resblock, self.forward_cache_name):
|
| 166 |
+
resblock._forward = getattr(resblock, self.forward_cache_name)
|
| 167 |
+
delattr(resblock, self.forward_cache_name)
|
| 168 |
+
|
| 169 |
+
for i in self.output_ids:
|
| 170 |
+
resblock = unet.output_blocks[i][0]
|
| 171 |
+
if hasattr(resblock, self.forward_cache_name):
|
| 172 |
+
resblock._forward = getattr(resblock, self.forward_cache_name)
|
| 173 |
+
delattr(resblock, self.forward_cache_name)
|
| 174 |
+
|
| 175 |
+
for i in self.mid_ids:
|
| 176 |
+
resblock = unet.middle_block[i]
|
| 177 |
+
if hasattr(resblock, self.forward_cache_name):
|
| 178 |
+
resblock._forward = getattr(resblock, self.forward_cache_name)
|
| 179 |
+
delattr(resblock, self.forward_cache_name)
|
| 180 |
+
self.unet = None
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
def load_from_dict(self, state_dict):
|
| 184 |
+
"""
|
| 185 |
+
Load model weights from a dictionary.
|
| 186 |
+
:param state_dict: a dict of parameters.
|
| 187 |
+
"""
|
| 188 |
+
filtered_dict = {}
|
| 189 |
+
for k, v in state_dict.items():
|
| 190 |
+
if k.startswith("model.diffusion_model."):
|
| 191 |
+
key = k[len("model.diffusion_model.") :]
|
| 192 |
+
# remove the '.0.spade' within the key
|
| 193 |
+
if 'middle_block' not in key:
|
| 194 |
+
key = key.replace('.0.spade', '')
|
| 195 |
+
else:
|
| 196 |
+
key = key.replace('.spade', '')
|
| 197 |
+
filtered_dict[key] = v
|
| 198 |
+
self.load_state_dict(filtered_dict)
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
if __name__ == '__main__':
|
| 202 |
+
path = '../models/stablesr_sd21.ckpt'
|
| 203 |
+
state_dict = torch.load(path)
|
| 204 |
+
model = SPADELayers()
|
| 205 |
+
model.load_from_dict(state_dict)
|
| 206 |
+
print(model)
|
sd-webui-stablesr/srmodule/struct_cond.py
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import math
|
| 2 |
+
import torch
|
| 3 |
+
import torch.nn as nn
|
| 4 |
+
|
| 5 |
+
from ldm.modules.diffusionmodules.openaimodel import (
|
| 6 |
+
TimestepEmbedSequential,
|
| 7 |
+
ResBlock,
|
| 8 |
+
Downsample,
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
from ldm.modules.diffusionmodules.util import (
|
| 12 |
+
conv_nd,
|
| 13 |
+
linear,
|
| 14 |
+
timestep_embedding,
|
| 15 |
+
checkpoint,
|
| 16 |
+
normalization,
|
| 17 |
+
zero_module,
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
from srmodule.attn import get_attn_func
|
| 21 |
+
|
| 22 |
+
attn_func = None
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class QKVAttentionLegacy(nn.Module):
|
| 26 |
+
"""
|
| 27 |
+
A module which performs QKV attention. Matches legacy QKVAttention + input/ouput heads shaping
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
def __init__(self, n_heads):
|
| 31 |
+
super().__init__()
|
| 32 |
+
self.n_heads = n_heads
|
| 33 |
+
|
| 34 |
+
def forward(self, qkv):
|
| 35 |
+
"""
|
| 36 |
+
Apply QKV attention.
|
| 37 |
+
:param qkv: an [N x (3 * H * C) x T] tensor of Qs, Ks, and Vs.
|
| 38 |
+
:return: an [N x (H * C) x T] tensor after attention.
|
| 39 |
+
"""
|
| 40 |
+
bs, width, length = qkv.shape
|
| 41 |
+
assert width % (3 * self.n_heads) == 0
|
| 42 |
+
ch = width // (3 * self.n_heads)
|
| 43 |
+
q, k, v = qkv.reshape(bs * self.n_heads, ch * 3, length).split(ch, dim=1)
|
| 44 |
+
# Legacy Attention
|
| 45 |
+
# scale = 1 / math.sqrt(math.sqrt(ch))
|
| 46 |
+
# weight = torch.einsum(
|
| 47 |
+
# "bct,bcs->bts", q * scale, k * scale
|
| 48 |
+
# ) # More stable with f16 than dividing afterwards
|
| 49 |
+
# weight = torch.softmax(weight.float(), dim=-1).type(weight.dtype)
|
| 50 |
+
# a = torch.einsum("bts,bcs->bct", weight, v)
|
| 51 |
+
# a = a.reshape(bs, -1, length)
|
| 52 |
+
q, k, v = map(
|
| 53 |
+
lambda t:t.permute(0,2,1)
|
| 54 |
+
.contiguous(),
|
| 55 |
+
(q, k, v),
|
| 56 |
+
)
|
| 57 |
+
global attn_func
|
| 58 |
+
a = attn_func(q, k, v)
|
| 59 |
+
a = (
|
| 60 |
+
a.permute(0,2,1)
|
| 61 |
+
.reshape(bs, -1, length)
|
| 62 |
+
)
|
| 63 |
+
return a
|
| 64 |
+
|
| 65 |
+
class AttentionBlock(nn.Module):
|
| 66 |
+
"""
|
| 67 |
+
An attention block that allows spatial positions to attend to each other.
|
| 68 |
+
Originally ported from here, but adapted to the N-d case.
|
| 69 |
+
https://github.com/hojonathanho/diffusion/blob/1e0dceb3b3495bbe19116a5e1b3596cd0706c543/diffusion_tf/models/unet.py#L66.
|
| 70 |
+
"""
|
| 71 |
+
|
| 72 |
+
def __init__(
|
| 73 |
+
self,
|
| 74 |
+
channels,
|
| 75 |
+
num_heads=1,
|
| 76 |
+
num_head_channels=-1,
|
| 77 |
+
use_checkpoint=False,
|
| 78 |
+
use_new_attention_order=False,
|
| 79 |
+
):
|
| 80 |
+
super().__init__()
|
| 81 |
+
self.channels = channels
|
| 82 |
+
if num_head_channels == -1:
|
| 83 |
+
self.num_heads = num_heads
|
| 84 |
+
else:
|
| 85 |
+
assert (
|
| 86 |
+
channels % num_head_channels == 0
|
| 87 |
+
), f"q,k,v channels {channels} is not divisible by num_head_channels {num_head_channels}"
|
| 88 |
+
self.num_heads = channels // num_head_channels
|
| 89 |
+
self.norm = normalization(channels)
|
| 90 |
+
self.qkv = conv_nd(1, channels, channels * 3, 1)
|
| 91 |
+
self.attention = QKVAttentionLegacy(self.num_heads)
|
| 92 |
+
|
| 93 |
+
self.proj_out = zero_module(conv_nd(1, channels, channels, 1))
|
| 94 |
+
|
| 95 |
+
def forward(self, x):
|
| 96 |
+
return checkpoint(self._forward, (x,), self.parameters(), True) # TODO: check checkpoint usage, is True # TODO: fix the .half call!!!
|
| 97 |
+
|
| 98 |
+
def _forward(self, x):
|
| 99 |
+
b, c, *spatial = x.shape
|
| 100 |
+
x = x.reshape(b, c, -1)
|
| 101 |
+
qkv = self.qkv(self.norm(x))
|
| 102 |
+
h = self.attention(qkv)
|
| 103 |
+
h = self.proj_out(h)
|
| 104 |
+
return (x + h).reshape(b, c, *spatial)
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
class EncoderUNetModelWT(nn.Module):
|
| 108 |
+
"""
|
| 109 |
+
The half UNet model with attention and timestep embedding.
|
| 110 |
+
For usage, see UNet.
|
| 111 |
+
"""
|
| 112 |
+
|
| 113 |
+
def __init__(
|
| 114 |
+
self,
|
| 115 |
+
in_channels,
|
| 116 |
+
model_channels,
|
| 117 |
+
out_channels,
|
| 118 |
+
num_res_blocks,
|
| 119 |
+
attention_resolutions,
|
| 120 |
+
dropout=0,
|
| 121 |
+
channel_mult=(1, 2, 4, 8),
|
| 122 |
+
conv_resample=True,
|
| 123 |
+
dims=2,
|
| 124 |
+
use_checkpoint=False,
|
| 125 |
+
use_fp16=False,
|
| 126 |
+
num_heads=4,
|
| 127 |
+
num_head_channels=-1,
|
| 128 |
+
num_heads_upsample=-1,
|
| 129 |
+
use_scale_shift_norm=False,
|
| 130 |
+
resblock_updown=False,
|
| 131 |
+
use_new_attention_order=False,
|
| 132 |
+
):
|
| 133 |
+
super().__init__()
|
| 134 |
+
|
| 135 |
+
if num_heads_upsample == -1:
|
| 136 |
+
num_heads_upsample = num_heads
|
| 137 |
+
|
| 138 |
+
self.in_channels = in_channels
|
| 139 |
+
self.model_channels = model_channels
|
| 140 |
+
self.out_channels = out_channels
|
| 141 |
+
self.num_res_blocks = num_res_blocks
|
| 142 |
+
self.attention_resolutions = attention_resolutions
|
| 143 |
+
self.dropout = dropout
|
| 144 |
+
self.channel_mult = channel_mult
|
| 145 |
+
self.conv_resample = conv_resample
|
| 146 |
+
self.use_checkpoint = use_checkpoint
|
| 147 |
+
self.dtype = torch.float16 if use_fp16 else torch.float32
|
| 148 |
+
self.num_heads = num_heads
|
| 149 |
+
self.num_head_channels = num_head_channels
|
| 150 |
+
self.num_heads_upsample = num_heads_upsample
|
| 151 |
+
|
| 152 |
+
time_embed_dim = model_channels * 4
|
| 153 |
+
self.time_embed = nn.Sequential(
|
| 154 |
+
linear(model_channels, time_embed_dim),
|
| 155 |
+
nn.SiLU(),
|
| 156 |
+
linear(time_embed_dim, time_embed_dim),
|
| 157 |
+
)
|
| 158 |
+
|
| 159 |
+
self.input_blocks = nn.ModuleList(
|
| 160 |
+
[
|
| 161 |
+
TimestepEmbedSequential(
|
| 162 |
+
conv_nd(dims, in_channels, model_channels, 3, padding=1)
|
| 163 |
+
)
|
| 164 |
+
]
|
| 165 |
+
)
|
| 166 |
+
self._feature_size = model_channels
|
| 167 |
+
input_block_chans = []
|
| 168 |
+
ch = model_channels
|
| 169 |
+
ds = 1
|
| 170 |
+
for level, mult in enumerate(channel_mult):
|
| 171 |
+
for _ in range(num_res_blocks):
|
| 172 |
+
layers = [
|
| 173 |
+
ResBlock(
|
| 174 |
+
ch,
|
| 175 |
+
time_embed_dim,
|
| 176 |
+
dropout,
|
| 177 |
+
out_channels=mult * model_channels,
|
| 178 |
+
dims=dims,
|
| 179 |
+
use_checkpoint=use_checkpoint,
|
| 180 |
+
use_scale_shift_norm=use_scale_shift_norm,
|
| 181 |
+
)
|
| 182 |
+
]
|
| 183 |
+
ch = mult * model_channels
|
| 184 |
+
if ds in attention_resolutions:
|
| 185 |
+
layers.append(
|
| 186 |
+
AttentionBlock(
|
| 187 |
+
ch,
|
| 188 |
+
use_checkpoint=use_checkpoint,
|
| 189 |
+
num_heads=num_heads,
|
| 190 |
+
num_head_channels=num_head_channels,
|
| 191 |
+
use_new_attention_order=use_new_attention_order,
|
| 192 |
+
)
|
| 193 |
+
)
|
| 194 |
+
self.input_blocks.append(TimestepEmbedSequential(*layers))
|
| 195 |
+
self._feature_size += ch
|
| 196 |
+
if level != len(channel_mult) - 1:
|
| 197 |
+
out_ch = ch
|
| 198 |
+
self.input_blocks.append(
|
| 199 |
+
TimestepEmbedSequential(
|
| 200 |
+
ResBlock(
|
| 201 |
+
ch,
|
| 202 |
+
time_embed_dim,
|
| 203 |
+
dropout,
|
| 204 |
+
out_channels=out_ch,
|
| 205 |
+
dims=dims,
|
| 206 |
+
use_checkpoint=use_checkpoint,
|
| 207 |
+
use_scale_shift_norm=use_scale_shift_norm,
|
| 208 |
+
down=True,
|
| 209 |
+
)
|
| 210 |
+
if resblock_updown
|
| 211 |
+
else Downsample(
|
| 212 |
+
ch, conv_resample, dims=dims, out_channels=out_ch
|
| 213 |
+
)
|
| 214 |
+
)
|
| 215 |
+
)
|
| 216 |
+
ch = out_ch
|
| 217 |
+
input_block_chans.append(ch)
|
| 218 |
+
ds *= 2
|
| 219 |
+
self._feature_size += ch
|
| 220 |
+
|
| 221 |
+
self.middle_block = TimestepEmbedSequential(
|
| 222 |
+
ResBlock(
|
| 223 |
+
ch,
|
| 224 |
+
time_embed_dim,
|
| 225 |
+
dropout,
|
| 226 |
+
dims=dims,
|
| 227 |
+
use_checkpoint=use_checkpoint,
|
| 228 |
+
use_scale_shift_norm=use_scale_shift_norm,
|
| 229 |
+
),
|
| 230 |
+
AttentionBlock(
|
| 231 |
+
ch,
|
| 232 |
+
use_checkpoint=use_checkpoint,
|
| 233 |
+
num_heads=num_heads,
|
| 234 |
+
num_head_channels=num_head_channels,
|
| 235 |
+
use_new_attention_order=use_new_attention_order,
|
| 236 |
+
),
|
| 237 |
+
ResBlock(
|
| 238 |
+
ch,
|
| 239 |
+
time_embed_dim,
|
| 240 |
+
dropout,
|
| 241 |
+
dims=dims,
|
| 242 |
+
use_checkpoint=use_checkpoint,
|
| 243 |
+
use_scale_shift_norm=use_scale_shift_norm,
|
| 244 |
+
),
|
| 245 |
+
)
|
| 246 |
+
input_block_chans.append(ch)
|
| 247 |
+
self._feature_size += ch
|
| 248 |
+
self.input_block_chans = input_block_chans
|
| 249 |
+
|
| 250 |
+
self.fea_tran = nn.ModuleList([])
|
| 251 |
+
|
| 252 |
+
for i in range(len(input_block_chans)):
|
| 253 |
+
self.fea_tran.append(
|
| 254 |
+
ResBlock(
|
| 255 |
+
input_block_chans[i],
|
| 256 |
+
time_embed_dim,
|
| 257 |
+
dropout,
|
| 258 |
+
out_channels=out_channels,
|
| 259 |
+
dims=dims,
|
| 260 |
+
use_checkpoint=use_checkpoint,
|
| 261 |
+
use_scale_shift_norm=use_scale_shift_norm,
|
| 262 |
+
)
|
| 263 |
+
)
|
| 264 |
+
|
| 265 |
+
@torch.no_grad()
|
| 266 |
+
def forward(self, x, timesteps):
|
| 267 |
+
"""
|
| 268 |
+
Apply the model to an input batch.
|
| 269 |
+
:param x: an [N x C x ...] Tensor of inputs.
|
| 270 |
+
:param timesteps: a 1-D batch of timesteps.
|
| 271 |
+
:return: an [N x K] Tensor of outputs.
|
| 272 |
+
"""
|
| 273 |
+
emb = self.time_embed(timestep_embedding(timesteps, self.model_channels))
|
| 274 |
+
|
| 275 |
+
result_list = []
|
| 276 |
+
results = {}
|
| 277 |
+
h = x.type(self.dtype)
|
| 278 |
+
for module in self.input_blocks:
|
| 279 |
+
last_h = h
|
| 280 |
+
h = module(h, emb)
|
| 281 |
+
if h.size(-1) != last_h.size(-1):
|
| 282 |
+
result_list.append(last_h)
|
| 283 |
+
h = self.middle_block(h, emb)
|
| 284 |
+
result_list.append(h)
|
| 285 |
+
|
| 286 |
+
assert len(result_list) == len(self.fea_tran)
|
| 287 |
+
|
| 288 |
+
for i in range(len(result_list)):
|
| 289 |
+
results[str(result_list[i].size(-1))] = self.fea_tran[i](result_list[i], emb)
|
| 290 |
+
|
| 291 |
+
return results
|
| 292 |
+
|
| 293 |
+
def load_from_dict(self, state_dict):
|
| 294 |
+
"""
|
| 295 |
+
Load model weights from a dictionary.
|
| 296 |
+
:param state_dict: a dict of parameters.
|
| 297 |
+
"""
|
| 298 |
+
filtered_dict = {}
|
| 299 |
+
for k, v in state_dict.items():
|
| 300 |
+
if k.startswith("structcond_stage_model."):
|
| 301 |
+
filtered_dict[k[len("structcond_stage_model.") :]] = v
|
| 302 |
+
self.load_state_dict(filtered_dict)
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
def build_unetwt() -> EncoderUNetModelWT:
|
| 306 |
+
"""
|
| 307 |
+
Build a model from a state dict.
|
| 308 |
+
:param state_dict: a dict of parameters.
|
| 309 |
+
:return: a nn.Module.
|
| 310 |
+
"""
|
| 311 |
+
# The settings is from official setting yaml file.
|
| 312 |
+
# https://github.com/IceClear/StableSR/blob/main/configs/stableSRNew/v2-finetune_text_T_512.yaml
|
| 313 |
+
|
| 314 |
+
model = EncoderUNetModelWT(
|
| 315 |
+
in_channels=4,
|
| 316 |
+
model_channels=256,
|
| 317 |
+
out_channels=256,
|
| 318 |
+
num_res_blocks=2,
|
| 319 |
+
attention_resolutions=[ 4, 2, 1 ],
|
| 320 |
+
dropout=0.0,
|
| 321 |
+
channel_mult=[1, 1, 2, 2],
|
| 322 |
+
conv_resample=True,
|
| 323 |
+
dims=2,
|
| 324 |
+
use_checkpoint=False,
|
| 325 |
+
use_fp16=False,
|
| 326 |
+
num_heads=4,
|
| 327 |
+
num_head_channels=-1,
|
| 328 |
+
num_heads_upsample=-1,
|
| 329 |
+
use_scale_shift_norm=False,
|
| 330 |
+
resblock_updown=False,
|
| 331 |
+
use_new_attention_order=False,
|
| 332 |
+
)
|
| 333 |
+
global attn_func
|
| 334 |
+
attn_func = get_attn_func()
|
| 335 |
+
return model
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
if __name__ == "__main__":
|
| 339 |
+
'''
|
| 340 |
+
Test the lr encoder model.
|
| 341 |
+
'''
|
| 342 |
+
path = '../models/stablesr_sd21.ckpt'
|
| 343 |
+
state_dict = torch.load(path)
|
| 344 |
+
for key in state_dict.keys():
|
| 345 |
+
print(key)
|
| 346 |
+
model = build_unetwt()
|
| 347 |
+
model.load_from_dict(state_dict)
|
| 348 |
+
model = model.cuda()
|
| 349 |
+
test_latent = torch.randn(1, 4, 64, 64).half().cuda()
|
| 350 |
+
test_timesteps = torch.tensor([0]).half().cuda()
|
| 351 |
+
with torch.no_grad():
|
| 352 |
+
test_result = model(test_latent, test_timesteps)
|
| 353 |
+
print(test_result.keys())
|
sd-webui-stablesr/tools/extract_srmodule.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
This script extracts the spade and structcond module from the official stablesr_000117.ckpt
|
| 3 |
+
'''
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
stablesr_path = 'models/stablesr_000117.ckpt'
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
with open(stablesr_path, 'rb') as f:
|
| 11 |
+
stablesr_ckpt = torch.load(f, map_location='cpu')
|
| 12 |
+
|
| 13 |
+
srmodule = {}
|
| 14 |
+
for k, v in stablesr_ckpt['state_dict'].items():
|
| 15 |
+
if 'spade' in k or 'structcond' in k:
|
| 16 |
+
srmodule[k] = v
|
| 17 |
+
# print(k)
|
| 18 |
+
# save
|
| 19 |
+
|
| 20 |
+
torch.save(srmodule, 'models/stablesr_sd21.ckpt')
|
sd-webui-stablesr/tools/extract_vaecfw.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
|
| 3 |
+
vae_path = 'models/vqgan_cfw_00011.ckpt'
|
| 4 |
+
|
| 5 |
+
with open(vae_path, 'rb') as f:
|
| 6 |
+
vae_ckpt = torch.load(f, map_location='cpu')
|
| 7 |
+
|
| 8 |
+
prune_keys = []
|
| 9 |
+
for k, v in vae_ckpt['state_dict'].items():
|
| 10 |
+
if 'decoder.fusion_layer' in k:
|
| 11 |
+
prune_keys.append(k)
|
| 12 |
+
print(k)
|
| 13 |
+
|
| 14 |
+
vae_cfw = {}
|
| 15 |
+
for k in prune_keys:
|
| 16 |
+
vae_cfw[k] = vae_ckpt['state_dict'][k]
|
| 17 |
+
del vae_ckpt['state_dict'][k]
|
| 18 |
+
|
| 19 |
+
torch.save(vae_ckpt, 'models/vqgan_cfw_00011_vae_only.ckpt')
|
| 20 |
+
torch.save(vae_cfw, 'models/vqgan_cfw_00011_cfw_only.ckpt')
|
sd_feed/.DS_Store
ADDED
|
Binary file (8.2 kB). View file
|
|
|
sd_feed/.gitignore
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__
|
| 2 |
+
pyc
|
| 3 |
+
user.json
|
| 4 |
+
*.pin
|
| 5 |
+
temp.png
|
sd_feed/Readme.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## Feed
|
| 2 |
+
<p align="center">
|
| 3 |
+
<img src="assets/feed.png" alt="Filter Images"/>
|
| 4 |
+
</p>
|
| 5 |
+
|
| 6 |
+
- This is a custom extension for AUTOMATIC1111/stable-diffusion-webui.
|
| 7 |
+
- You can enjoy browsing from tab and getting reputation with your pictures
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
[](https://www.youtube.com/watch?v=hq1MMXSYjTQ)
|
| 12 |
+
|
| 13 |
+
### Installation
|
| 14 |
+
- The extension can be installed directly from within the **Extension** tab within the Webui.
|
| 15 |
+
- You can also install it manually by running the following command from within the webui directory:
|
| 16 |
+
|
| 17 |
+
git clone https://github.com/todhm/sd_feed.git
|
| 18 |
+
|
| 19 |
+
and restart your stable-diffusion-webui, then you can see the new tab "Feed", and other features on txt2img tab and img2img tab.
|
| 20 |
+
<p align="center">
|
| 21 |
+
<a href="" rel="noopener">
|
| 22 |
+
<img src="assets/extensions.png" alt="Project logo"></a>
|
| 23 |
+
</p>
|
| 24 |
+
|
| 25 |
+
### Introduction
|
| 26 |
+
- You can **upload** your masterpiece on the Feed Tap.
|
| 27 |
+
- You can press the recommend button on the photos created by others.
|
| 28 |
+
- You can see **Pics Of The Day**(POTD) which is most recommended today.
|
| 29 |
+
- You can easily check the generation data of your favorite photos.
|
| 30 |
+
- You can easily Send your favorite photos to t2i or i2i.
|
| 31 |
+
|
| 32 |
+
### Features
|
| 33 |
+
#### Upload Your Masterpiece!
|
| 34 |
+
<img src="assets/feedsetting1.png" alt="Filter Images"/>
|
| 35 |
+
|
| 36 |
+
Upload your image right after generation!
|
| 37 |
+
|
| 38 |
+
### Feed
|
| 39 |
+
<img src="assets/5ulvww8bblta1.webp" alt="Filter Images"/>
|
| 40 |
+
|
| 41 |
+
Browse People's images!
|
| 42 |
+
|
| 43 |
+
there are four feeds
|
| 44 |
+
- newest : pics of all over the world
|
| 45 |
+
- popular : pics what people like
|
| 46 |
+
- favorite : pics that you pushed like button
|
| 47 |
+
- my pics : that you uploaded
|
| 48 |
+
|
| 49 |
+
### Tweak!
|
| 50 |
+
<img src="assets/lhijrt5lblta1.webp" alt="Filter Images"/>
|
| 51 |
+
|
| 52 |
+
Check the parameters and generate your own!
|
| 53 |
+
|
| 54 |
+
You can easily send to t2i,i2i or Copy the Generation data and also communicate!
|
| 55 |
+
|
| 56 |
+
### Pics Of The Day!📷
|
| 57 |
+
<img src="assets/potd.png" alt="Filter Images"/>
|
| 58 |
+
you can be the king of the day!
|
| 59 |
+
|
| 60 |
+
most popular pic of the day will be exhibited on generation tab!
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
#### Getting Started
|
| 64 |
+
To start using our WebUI Extension for Reputation-Based Feed Sharing, simply install the extension on your browser and create an account. You can then start uploading your feed and browsing other people's feed and prompts.
|
| 65 |
+
|
| 66 |
+
#### Feedback and Support
|
| 67 |
+
We are constantly improving our extension based on user feedback, so please let us know if you have any suggestions or issues. You can contact us at
|
| 68 |
+
|
| 69 |
+
---
|
| 70 |
+
### Warning
|
| 71 |
+
- Your uploaded image might be exposed to our promotion contents.
|
| 72 |
+
- It does not mean we will make a profit from your contents. There is possibility that other people might see your content indirectly when we trying to introduce our feed to other people.
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
### Todo & Further Features.
|
| 76 |
+
|
| 77 |
+
- We want to support a image producers by adding a sponsor features to pouplar images.
|
| 78 |
+
- We also planned to extend community functions by adding comments on each functions.
|
| 79 |
+
- Any suggestions are welcomed. Please leave us your comments.
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
|
sd_feed/assets/5ulvww8bblta1.webp
ADDED
|
sd_feed/assets/extensions.png
ADDED
|
sd_feed/assets/feed.png
ADDED
|
sd_feed/assets/feedsetting1.png
ADDED
|
sd_feed/assets/lhijrt5lblta1.webp
ADDED
|
sd_feed/assets/pinterest.png
ADDED
|
Git LFS Details
|
sd_feed/assets/potd.png
ADDED
|
sd_feed/assets/share.png
ADDED
|
sd_feed/assets/shareandearn.png
ADDED
|
sd_feed/html/feedtab.html
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<div class="feed-tab-header" style="display:flex;width:100%;justify-content:space-between;" id="feed-header">
|
| 2 |
+
<div class="feed-tab-class">
|
| 3 |
+
<button
|
| 4 |
+
v-for="(item, index) in modeSelectList"
|
| 5 |
+
:key="index"
|
| 6 |
+
class="feed-tab-default"
|
| 7 |
+
:class="{ 'selected' : item.value === mode}"
|
| 8 |
+
@click="setMode(item.value)"
|
| 9 |
+
>{{ item.name }}</button>
|
| 10 |
+
<button
|
| 11 |
+
class="feed-tab-default"
|
| 12 |
+
:class="{ 'selected' : mode === 'nicknameSearch'}"
|
| 13 |
+
id="feed-user-tab"
|
| 14 |
+
@click="setNicknameSearch">
|
| 15 |
+
</button>
|
| 16 |
+
</div>
|
| 17 |
+
<div class="feed-tab-class-search">
|
| 18 |
+
<input id="prompt-input" type="text" v-model="prompt" @keyup.enter="fetchNewImage" style="margin-right:5px;">
|
| 19 |
+
<button @click="fetchNewImage" id="feed-search-btn">Search</button>
|
| 20 |
+
</div>
|
| 21 |
+
</div>
|
| 22 |
+
<div>
|
| 23 |
+
<div class="product-slider" style="display:flex;justify-content:center;">
|
| 24 |
+
<div style="display:flex;justify-content:flex-end;width:100%;margin-top:20px;">
|
| 25 |
+
<div style="display:flex;">
|
| 26 |
+
<button style="margin-right:20px;" @click="selectRealTag" class="tag-button" :class="{ 'tag-button-selected': realTag, 'tag-button-unselected': !realTag }">REAL</button>
|
| 27 |
+
</div>
|
| 28 |
+
<div style="display:flex;">
|
| 29 |
+
<button style="margin-right:100px;" @click="selectAnimeTag" class="tag-button" :class="{ 'tag-button-selected': animeTag, 'tag-button-unselected': !animeTag }">ILLUST</button>
|
| 30 |
+
</div>
|
| 31 |
+
<div>
|
| 32 |
+
<label class="toggle-btn">
|
| 33 |
+
<span class="toggle-letter">Filter NSFW</span>
|
| 34 |
+
<input type="checkbox" v-model="filterNsfw" @change="fetchNewImage">
|
| 35 |
+
<span class="slider round"></span>
|
| 36 |
+
</label>
|
| 37 |
+
</div>
|
| 38 |
+
</div>
|
| 39 |
+
</div>
|
| 40 |
+
<div class="product-slider" style="display:flex;justify-content:center;" v-if="mode=='nicknameSearch'">
|
| 41 |
+
<div class="page-max-width">
|
| 42 |
+
<div style="max-width:100%;display:flex;align-items: start;">
|
| 43 |
+
<div style="margin-left:37px;margin-right:37px;margin-bottom:37px;">
|
| 44 |
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="160" zoomAndPan="magnify" viewBox="0 0 39 38.999999" height="160" preserveAspectRatio="xMidYMid meet" version="1.0"><rect x="-3.9" width="46.8" fill="#ffffff" y="-3.9" height="46.799999" fill-opacity="1"/><rect x="-3.9" width="46.8" fill="#ffffff" y="-3.9" height="46.799999" fill-opacity="1"/><rect x="-3.9" width="46.8" fill="#ffffff" y="-3.9" height="46.799999" fill-opacity="1"/><path fill="#000000" d="M 33.289062 5.710938 C 29.605469 2.027344 24.707031 0 19.5 0 C 14.292969 0 9.394531 2.027344 5.710938 5.710938 C 2.027344 9.394531 0 14.292969 0 19.5 C 0 24.707031 2.027344 29.605469 5.710938 33.289062 C 9.394531 36.972656 14.292969 39 19.5 39 C 24.707031 39 29.605469 36.972656 33.289062 33.289062 C 36.972656 29.605469 39 24.707031 39 19.5 C 39 14.292969 36.972656 9.394531 33.289062 5.710938 Z M 6.597656 6.597656 C 10.042969 3.148438 14.625 1.25 19.5 1.25 C 24.375 1.25 28.957031 3.148438 32.402344 6.597656 C 35.851562 10.042969 37.746094 14.625 37.746094 19.5 C 37.746094 23.550781 36.433594 27.402344 34.011719 30.566406 C 32.085938 27.871094 29.007812 26.277344 25.664062 26.277344 L 13.335938 26.277344 C 9.992188 26.277344 6.914062 27.871094 4.988281 30.566406 C 2.5625 27.402344 1.25 23.550781 1.25 19.5 C 1.25 14.625 3.148438 10.042969 6.597656 6.597656 Z M 19.5 25.25 C 24.507812 25.25 28.585938 21.171875 28.585938 16.164062 C 28.585938 11.152344 24.507812 7.078125 19.5 7.078125 C 14.488281 7.078125 10.414062 11.152344 10.414062 16.164062 C 10.414062 21.171875 14.488281 25.25 19.5 25.25 Z M 19.5 25.25 " fill-opacity="1" fill-rule="nonzero"/></svg>
|
| 45 |
+
</div>
|
| 46 |
+
<div>
|
| 47 |
+
<div style="display:flex;align-items:center;">
|
| 48 |
+
<div style="padding: 10px; border-radius: 5px; display:flex;align-items:center;">
|
| 49 |
+
<p style="line-height:normal;line-height:0;font-size: 25px;font-weight: 800;margin-right: 10px;">By.</p>
|
| 50 |
+
<p style="line-height: 0;font-size: 20px;margin-right: 10p;">{{searchNickname}}</p>
|
| 51 |
+
</div>
|
| 52 |
+
</div>
|
| 53 |
+
<div v-html="parsedSearchProfile" style="padding: 10px; border-radius: 5px; display:flex;align-items:center;">
|
| 54 |
+
|
| 55 |
+
</div>
|
| 56 |
+
</div>
|
| 57 |
+
</div>
|
| 58 |
+
</div>
|
| 59 |
+
</div>
|
| 60 |
+
<div class="product-slider" style="display:flex;justify-content:center;" v-if="mode=='private'">
|
| 61 |
+
<div class="page-max-width">
|
| 62 |
+
<div style="max-width:100%;display:flex;align-items: start;">
|
| 63 |
+
<div style="margin-left:37px;margin-right:37px;margin-bottom:37px;">
|
| 64 |
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="160" zoomAndPan="magnify" viewBox="0 0 39 38.999999" height="160" preserveAspectRatio="xMidYMid meet" version="1.0"><rect x="-3.9" width="46.8" fill="#ffffff" y="-3.9" height="46.799999" fill-opacity="1"/><rect x="-3.9" width="46.8" fill="#ffffff" y="-3.9" height="46.799999" fill-opacity="1"/><rect x="-3.9" width="46.8" fill="#ffffff" y="-3.9" height="46.799999" fill-opacity="1"/><path fill="#000000" d="M 33.289062 5.710938 C 29.605469 2.027344 24.707031 0 19.5 0 C 14.292969 0 9.394531 2.027344 5.710938 5.710938 C 2.027344 9.394531 0 14.292969 0 19.5 C 0 24.707031 2.027344 29.605469 5.710938 33.289062 C 9.394531 36.972656 14.292969 39 19.5 39 C 24.707031 39 29.605469 36.972656 33.289062 33.289062 C 36.972656 29.605469 39 24.707031 39 19.5 C 39 14.292969 36.972656 9.394531 33.289062 5.710938 Z M 6.597656 6.597656 C 10.042969 3.148438 14.625 1.25 19.5 1.25 C 24.375 1.25 28.957031 3.148438 32.402344 6.597656 C 35.851562 10.042969 37.746094 14.625 37.746094 19.5 C 37.746094 23.550781 36.433594 27.402344 34.011719 30.566406 C 32.085938 27.871094 29.007812 26.277344 25.664062 26.277344 L 13.335938 26.277344 C 9.992188 26.277344 6.914062 27.871094 4.988281 30.566406 C 2.5625 27.402344 1.25 23.550781 1.25 19.5 C 1.25 14.625 3.148438 10.042969 6.597656 6.597656 Z M 19.5 25.25 C 24.507812 25.25 28.585938 21.171875 28.585938 16.164062 C 28.585938 11.152344 24.507812 7.078125 19.5 7.078125 C 14.488281 7.078125 10.414062 11.152344 10.414062 16.164062 C 10.414062 21.171875 14.488281 25.25 19.5 25.25 Z M 19.5 25.25 " fill-opacity="1" fill-rule="nonzero"/></svg>
|
| 65 |
+
</div>
|
| 66 |
+
<template v-if="!editMode">
|
| 67 |
+
<div>
|
| 68 |
+
<div style="display:flex;align-items:center;">
|
| 69 |
+
<div style="padding: 10px; border-radius: 5px; display:flex;align-items:center;">
|
| 70 |
+
<p style="line-height:normal;line-height:0;font-size: 25px;font-weight: 800;margin-right: 10px;">By.</p>
|
| 71 |
+
<p style="line-height: 0;font-size: 20px;margin-right: 10p;">{{nickname}}</p>
|
| 72 |
+
</div>
|
| 73 |
+
<button @click="setEditMode" style="width:24px;height:24px;">
|
| 74 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather feather-edit-2"><path d="M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"></path></svg>
|
| 75 |
+
</button>
|
| 76 |
+
</div>
|
| 77 |
+
<div style="padding: 10px; border-radius: 5px; display:flex;align-items:center;" v-html="parsedProfile">
|
| 78 |
+
</div>
|
| 79 |
+
<div style="padding: 10px; border-radius: 5px; display:flex;align-items:center;">
|
| 80 |
+
If you have any question or want to modify your data contact us at Discord: #Zag5956
|
| 81 |
+
</div>
|
| 82 |
+
</div>
|
| 83 |
+
</template>
|
| 84 |
+
<template v-else>
|
| 85 |
+
<div style="width:100%;">
|
| 86 |
+
<div style="width:100%;">
|
| 87 |
+
<input style="padding: 10px; border-radius: 5px; border: 1px solid #ccc; flex-grow: 1;" type="text" v-model="nickname">
|
| 88 |
+
<button style="width:24px;height:24px;margin-right:15px;margin-left:15px;" @click="saveNickname">💾</button>
|
| 89 |
+
<button style="width:24px;height:24px;" @click="setEditMode">
|
| 90 |
+
✖️
|
| 91 |
+
</button>
|
| 92 |
+
</div>
|
| 93 |
+
<div style="width:100%;">
|
| 94 |
+
<textarea v-model="profile" @input="handleTextareaInput" id="profile-writer-type" class="profile-writer-type" placeholder="Type your profile"></textarea>
|
| 95 |
+
</div>
|
| 96 |
+
</div>
|
| 97 |
+
</template>
|
| 98 |
+
</div>
|
| 99 |
+
<div style="display:flex;justify-content:center;" v-if="imageList.length == 0 & mode=='private'" class="private-upload">
|
| 100 |
+
<div style="width:100%;">
|
| 101 |
+
<label for="image-input-file" style="background-color:#AFB6BD;width:100%;aspect-ratio:1/1;">
|
| 102 |
+
<div style="background-color:#AFB6BD;width:100%;aspect-ratio:1/1;display:flex; align-items:center;justify-content:center;">
|
| 103 |
+
<div style="background-color:white;width:80%;aspect-ratio:1/1;display:flex; align-items:center;justify-content:center;">
|
| 104 |
+
<div v-if="!loading">
|
| 105 |
+
<div style="color:#AFB6BD;font-size:18px;display:flex;justify-content:center;">
|
| 106 |
+
Please Upload Image
|
| 107 |
+
</div>
|
| 108 |
+
<div style="color:#AFB6BD;font-size:15px;display:flex;justify-content:center;">-or-</div>
|
| 109 |
+
<div style="color:#AFB6BD;font-size:18px;display:flex;justify-content:center;">Click and upload</div>
|
| 110 |
+
</div>
|
| 111 |
+
<div v-if="loading">
|
| 112 |
+
<div style="color:#AFB6BD;font-size:18px;display:center;justify-content:center;">
|
| 113 |
+
Loading Image...
|
| 114 |
+
</div>
|
| 115 |
+
</div>
|
| 116 |
+
</div>
|
| 117 |
+
</div>
|
| 118 |
+
</label>
|
| 119 |
+
<input
|
| 120 |
+
id="image-input-file"
|
| 121 |
+
type="file"
|
| 122 |
+
multiple
|
| 123 |
+
accept="image/*"
|
| 124 |
+
style="display:none;"
|
| 125 |
+
@change="uploadImage"
|
| 126 |
+
>
|
| 127 |
+
</div>
|
| 128 |
+
</div>
|
| 129 |
+
</div>
|
| 130 |
+
</div>
|
| 131 |
+
<div class="product-slider" v-if="imageList.length > 0">
|
| 132 |
+
<div class="pinterest-column-gallery" id="columns">
|
| 133 |
+
<div v-if="mode=='private'" class="pinterest-column-item">
|
| 134 |
+
<label for="image-input-file" style="background-color:#AFB6BD;width:100%;aspect-ratio:1/1;">
|
| 135 |
+
<div style="background-color:#AFB6BD;width:100%;aspect-ratio:1/1;display:flex; align-items:center;justify-content:center;">
|
| 136 |
+
<div style="background-color:white;width:80%;aspect-ratio:1/1;display:flex; align-items:center;justify-content:center;">
|
| 137 |
+
<div v-if="!uploadLoading">
|
| 138 |
+
<div style="color:#AFB6BD;font-size:18px;display:flex;justify-content:center;">
|
| 139 |
+
Please Upload Image
|
| 140 |
+
</div>
|
| 141 |
+
<div style="color:#AFB6BD;font-size:15px;display:flex;justify-content:center;">-or-</div>
|
| 142 |
+
<div style="color:#AFB6BD;font-size:18px;display:flex;justify-content:center;">Click and upload</div>
|
| 143 |
+
</div>
|
| 144 |
+
<div v-if="uploadLoading">
|
| 145 |
+
<div style="color:#AFB6BD;font-size:18px;display:center;justify-content:center;">
|
| 146 |
+
Loading Image...
|
| 147 |
+
</div>
|
| 148 |
+
</div>
|
| 149 |
+
</div>
|
| 150 |
+
</div>
|
| 151 |
+
</label>
|
| 152 |
+
<input
|
| 153 |
+
id="image-input-file"
|
| 154 |
+
type="file"
|
| 155 |
+
multiple
|
| 156 |
+
accept="image/*"
|
| 157 |
+
style="display:none;"
|
| 158 |
+
@change="uploadImage"
|
| 159 |
+
>
|
| 160 |
+
</div>
|
| 161 |
+
<template v-for="(imageData, j) in sortedDataList" :key="j">
|
| 162 |
+
<div class="pinterest-column-item">
|
| 163 |
+
<img :src="imageData.url" @click="openModal(imageData)">
|
| 164 |
+
<div class="item-overlay">
|
| 165 |
+
<div style="display:flex;align-items: center;height:100%;">
|
| 166 |
+
<template v-if="!imageData.liked">
|
| 167 |
+
<div class="liked-button-div not-liked-div" @click="addToWishList(imageData)">
|
| 168 |
+
<button class="like-button">👍 {{formatNumber(imageData.likecount)}}</button>
|
| 169 |
+
</div>
|
| 170 |
+
</template>
|
| 171 |
+
<template v-else>
|
| 172 |
+
<div class="liked-button-div already-liked-div" @click="deleteWishList(imageData)">
|
| 173 |
+
<button class="like-button already-liked-button">👍 {{formatNumber(imageData.likecount)}}</button>
|
| 174 |
+
</div>
|
| 175 |
+
</template>
|
| 176 |
+
<div style="
|
| 177 |
+
display: flex;
|
| 178 |
+
justify-content: center;
|
| 179 |
+
align-items: center;
|
| 180 |
+
margin-left:5px;
|
| 181 |
+
height:100%;
|
| 182 |
+
">
|
| 183 |
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="20" zoomAndPan="magnify" viewBox="0 0 39 38.999999" height="20" preserveAspectRatio="xMidYMid meet" version="1.0"><defs><clipPath id="a06d7ef085"><path d="M 1.484375 7.214844 L 37.484375 7.214844 L 37.484375 31.964844 L 1.484375 31.964844 Z M 1.484375 7.214844 " clip-rule="nonzero"/></clipPath></defs><g clip-path="url(#a06d7ef085)"><path fill="#ffffff" d="M 19.484375 7.214844 C 11.300781 7.214844 4.316406 12.347656 1.484375 19.589844 C 4.316406 26.835938 11.300781 31.964844 19.484375 31.964844 C 27.664062 31.964844 34.652344 26.835938 37.484375 19.589844 C 34.652344 12.347656 27.671875 7.214844 19.484375 7.214844 Z M 19.484375 27.839844 C 14.96875 27.839844 11.300781 24.144531 11.300781 19.589844 C 11.300781 15.039062 14.96875 11.339844 19.484375 11.339844 C 24 11.339844 27.664062 15.039062 27.664062 19.589844 C 27.664062 24.144531 24 27.839844 19.484375 27.839844 Z M 19.484375 14.640625 C 16.777344 14.640625 14.574219 16.859375 14.574219 19.589844 C 14.574219 22.320312 16.777344 24.539062 19.484375 24.539062 C 22.191406 24.539062 24.394531 22.320312 24.394531 19.589844 C 24.394531 16.859375 22.191406 14.640625 19.484375 14.640625 Z M 19.484375 14.640625 " fill-opacity="1" fill-rule="nonzero"/></g></svg>
|
| 184 |
+
</div>
|
| 185 |
+
<div style="display:flex;justify-content: center;align-items: center;color:white;">
|
| 186 |
+
{{formatNumber(imageData.total_clicks)}}
|
| 187 |
+
</div>
|
| 188 |
+
<div style="display: flex;justify-content: center;align-items: center;margin-left:5px;height:100%;">
|
| 189 |
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" zoomAndPan="magnify" viewBox="0 0 39 38.999999" height="16" preserveAspectRatio="xMidYMid meet" version="1.0"><defs><clipPath id="6d2be58645"><path d="M 2.515625 24 L 36.265625 24 L 36.265625 39 L 2.515625 39 Z M 2.515625 24 " clip-rule="nonzero"/></clipPath></defs><path fill="#ffffff" d="M 19.453125 0.21875 C 18.429688 0.21875 17.601562 1.054688 17.601562 2.085938 L 17.601562 22.101562 L 13.253906 17.730469 C 11.507812 16.023438 8.933594 18.601562 10.632812 20.367188 C 10.632812 20.367188 18.144531 27.925781 18.144531 27.925781 C 18.84375 28.65625 20.0625 28.632812 20.765625 27.925781 C 20.765625 27.925781 28.277344 20.367188 28.277344 20.367188 C 29.96875 18.605469 27.410156 16.023438 25.652344 17.730469 C 25.652344 17.730469 21.308594 22.101562 21.308594 22.101562 L 21.308594 2.085938 C 21.308594 1.054688 20.476562 0.21875 19.453125 0.21875 Z M 19.453125 0.21875 " fill-opacity="1" fill-rule="nonzero"/><g clip-path="url(#6d2be58645)"><path fill="#ffffff" d="M 4.433594 24.738281 C 3.410156 24.738281 2.578125 25.574219 2.578125 26.605469 L 2.578125 29.359375 C 2.578125 34.554688 6.78125 38.78125 11.945312 38.78125 L 26.964844 38.78125 C 32.128906 38.78125 36.328125 34.554688 36.328125 29.359375 L 36.328125 26.605469 C 36.328125 25.574219 35.5 24.738281 34.476562 24.738281 C 33.453125 24.738281 32.621094 25.574219 32.621094 26.605469 L 32.621094 29.359375 C 32.621094 32.496094 30.082031 35.050781 26.964844 35.050781 L 11.945312 35.050781 C 8.824219 35.050781 6.289062 32.496094 6.289062 29.359375 L 6.289062 26.605469 C 6.289062 25.574219 5.457031 24.738281 4.433594 24.738281 Z M 4.433594 24.738281 " fill-opacity="1" fill-rule="nonzero"/></g></svg>
|
| 190 |
+
</div>
|
| 191 |
+
<div style="display:flex;justify-content: center;align-items: center;color:white;">
|
| 192 |
+
{{formatNumber(imageData.total_sendto)}}
|
| 193 |
+
</div>
|
| 194 |
+
<div style="display: flex;justify-content: center;align-items: center;margin-left:5px;height:100%;">
|
| 195 |
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="20" zoomAndPan="magnify" viewBox="0 0 39 38.999999" height="20" preserveAspectRatio="xMidYMid meet" version="1.0"><defs><clipPath id="ae37d71e45"><path d="M 5.074219 5.542969 L 33.574219 5.542969 L 33.574219 33.292969 L 5.074219 33.292969 Z M 5.074219 5.542969 " clip-rule="nonzero"/></clipPath></defs><g clip-path="url(#ae37d71e45)"><path fill="#ffffff" d="M 11.796875 33.273438 C 11.722656 33.273438 11.648438 33.253906 11.582031 33.21875 C 11.4375 33.136719 11.347656 32.988281 11.347656 32.820312 L 11.347656 28.015625 L 9.152344 28.015625 C 6.902344 28.015625 5.074219 26.171875 5.074219 23.90625 L 5.074219 9.671875 C 5.074219 7.410156 6.902344 5.566406 9.152344 5.566406 L 29.492188 5.566406 C 31.742188 5.566406 33.570312 7.410156 33.570312 9.671875 L 33.570312 23.90625 C 33.570312 26.171875 31.742188 28.015625 29.492188 28.015625 L 20.226562 28.015625 C 17.496094 29.746094 14.765625 31.472656 12.035156 33.203125 C 11.964844 33.25 11.878906 33.273438 11.796875 33.273438 Z M 11.796875 33.273438 " fill-opacity="1" fill-rule="nonzero"/></g></svg>
|
| 196 |
+
</div>
|
| 197 |
+
<div style="display:flex;justify-content: center;align-items: center;color:white;">
|
| 198 |
+
{{formatNumber(imageData.total_comments)}}
|
| 199 |
+
</div>
|
| 200 |
+
</div>
|
| 201 |
+
<div style="display:flex;align-items:center;">
|
| 202 |
+
<a class="item-author" @click="moveFeedProfileTab(imageData.nickname)" href="javascript:void(0);">by {{imageData.nickname}}</a>
|
| 203 |
+
</div>
|
| 204 |
+
</div>
|
| 205 |
+
</template>
|
| 206 |
+
</div>
|
| 207 |
+
</div>
|
| 208 |
+
</div>
|
| 209 |
+
<template v-if="this.showModal">
|
| 210 |
+
<div class="promptModal">
|
| 211 |
+
<div class="prompt-modal-page">
|
| 212 |
+
<div class="prompt-modal-image" @click="closeOutsideModal">
|
| 213 |
+
<img :src="src" alt="Pretty Image" class="prompt-modal-image-tag"/>
|
| 214 |
+
</div>
|
| 215 |
+
<div class="prompt-modal-sidebar">
|
| 216 |
+
<div class="modal-sidebar-header">
|
| 217 |
+
<div style="display:flex;">
|
| 218 |
+
<div class="modal-like-wrapper">
|
| 219 |
+
<template v-if="!currentItem.liked">
|
| 220 |
+
<div class="big-liked-button-div not-liked-div" @click="addToWishList(currentItem)">
|
| 221 |
+
<button class="like-button">👍 {{formatNumber(currentItem.likecount)}}</button>
|
| 222 |
+
</div>
|
| 223 |
+
</template>
|
| 224 |
+
<template v-else>
|
| 225 |
+
<div class="big-liked-button-div already-liked-div" @click="deleteWishList(currentItem)">
|
| 226 |
+
<button class="like-button already-liked-button">👍 {{formatNumber(currentItem.likecount)}}</button>
|
| 227 |
+
</div>
|
| 228 |
+
</template>
|
| 229 |
+
</div>
|
| 230 |
+
<div class="modal-writer-wrappers">
|
| 231 |
+
<a href="javascript:void(0);" @click="moveFeedProfileTab(currentItem.nickname)" class="modal-writer">By {{currentItem.nickname}}</a>
|
| 232 |
+
<div class="modal-writer-time">{{currentItem.created_at}}</div>
|
| 233 |
+
</div>
|
| 234 |
+
</div>
|
| 235 |
+
<div class="modal-writer-wrapper-exit" @click="close()">
|
| 236 |
+
<div>
|
| 237 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="35" height="35" viewBox="0 0 35 35" fill="none">
|
| 238 |
+
<path d="M19.9037 17.8831L27.752 25.7314V27.7998H25.6837L17.8354 19.9514L9.98703 27.7998H7.9187V25.7314L15.767 17.8831L7.9187 10.0348V7.96643H9.98703L17.8354 15.8148L25.6837 7.96643H27.752V10.0348L19.9037 17.8831Z" fill="white"/>
|
| 239 |
+
<rect x="1.32679" y="1.37439" width="33.0173" height="33.0173" rx="4.50866" stroke="#0E0E0E" stroke-width="0.982675"/>
|
| 240 |
+
</svg>
|
| 241 |
+
</div>
|
| 242 |
+
</div>
|
| 243 |
+
</div>
|
| 244 |
+
<div class="modal-write-input-wrapper">
|
| 245 |
+
<div class="modal-write-input-div">
|
| 246 |
+
<textarea v-model="comment" @input="handleTextareaInput" id="modal-writer-type" class="modal-writer-type" @focus="makeSaveButtonVisible" placeholder="Type your comment"></textarea>
|
| 247 |
+
</div>
|
| 248 |
+
<div style="display:flex;justify-content:center;width:100%;">
|
| 249 |
+
<div v-if="showCommentWrite" class="write-row-button">
|
| 250 |
+
<button class="btn-write-row btn-cancel" @click="hideSaveButtonVisible">Cancel</button>
|
| 251 |
+
<button class="btn-write-row btn-save" @click="writeComment()">Comment</button>
|
| 252 |
+
</div>
|
| 253 |
+
</div>
|
| 254 |
+
</div>
|
| 255 |
+
<div style="margin-top:10px;border-bottom: 1px solid #AFB6BD;padding-bottom:17px;">
|
| 256 |
+
<template v-for="(commentData, j) in comments" :key="j">
|
| 257 |
+
<div style="margin-left:10px;margin-right:10px;">
|
| 258 |
+
<div style="display:flex;width:100%;margin-bottom:12px;color:white;">
|
| 259 |
+
<div style="margin-right:10px;color:white;font-size:17px;font-weight:700;">{{commentData.user.nickname}}</div>
|
| 260 |
+
<div style="color:white;font-size:12px;font-weight:300;">{{commentData.created_at}}</div>
|
| 261 |
+
</div>
|
| 262 |
+
<div style="display:flex;width:100%;color:white;">
|
| 263 |
+
<div style="color:white;font-size:13px;">{{commentData.text}}</div>
|
| 264 |
+
</div>
|
| 265 |
+
</div>
|
| 266 |
+
</template>
|
| 267 |
+
</div>
|
| 268 |
+
<div class="prompt-send-to">
|
| 269 |
+
<button class="btn-send-to btn-send-to-text" @click="this.sendToTextToImage()">Send to t2i</button>
|
| 270 |
+
<button class="btn-send-to btn-send-to-img" @click="this.sendToImageToImage()">Send to i2i</button>
|
| 271 |
+
</div>
|
| 272 |
+
<div style="margin-top:12px;">
|
| 273 |
+
<div style="margin-left: 10px;margin-right: 10px;">
|
| 274 |
+
<div style="color:white;margin-bottom:12px;">Generation Data</div>
|
| 275 |
+
<div style="box-sizing: border-box;display: flex;flex-direction: column;justify-content: center;align-items: flex-start;padding-left:20px;padding-right:20px;padding-top:10px;padding-bottom:10px;border: 1px solid #AFB6BD;border-radius: 5px;color:white;">
|
| 276 |
+
<template v-for="(value, key) in metadata">
|
| 277 |
+
<template v-if="/^[A-Z]/.test(key)">
|
| 278 |
+
{{key}}:{{value}},
|
| 279 |
+
</template>
|
| 280 |
+
</template>
|
| 281 |
+
</div>
|
| 282 |
+
<div style="display:flex;justify-content:center;margin-top:20px;">
|
| 283 |
+
<button @click="copyClipboard" style="text-align:center;box-sizing: border-box;display: flex;flex-direction: column;justify-content: center;align-items: flex-start;padding-top:10px;padding-bottom:10px;border: 1px solid #AFB6BD;border-radius: 5px;color:white;width:100%;">
|
| 284 |
+
<div style="color:white;margin:auto;">Copy Generation Data</div></button>
|
| 285 |
+
</div>
|
| 286 |
+
</div>
|
| 287 |
+
</div>
|
| 288 |
+
</div>
|
| 289 |
+
</div>
|
| 290 |
+
</div>
|
| 291 |
+
</template>
|
sd_feed/html/lora.html
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<div class="feed-tab-header" style="display:flex;width:100%;justify-content:space-between;" id="lora-search-table">
|
| 2 |
+
<input value="" id="lora-download-url" style="display:none;"/>
|
| 3 |
+
<input value="" id="lora-filename" style="display:none;"/>
|
| 4 |
+
<table v-if="loraList.length>0">
|
| 5 |
+
<thead>
|
| 6 |
+
<th>File Name</th>
|
| 7 |
+
<th></th>
|
| 8 |
+
</thead>
|
| 9 |
+
<tbody>
|
| 10 |
+
<template v-for="(loraData, j) in loraList" :key="j">
|
| 11 |
+
<tr>
|
| 12 |
+
<td>{{loraData.fileName}}</td>
|
| 13 |
+
<template v-if="loraData.downloadUrl != ''">
|
| 14 |
+
<td><button @click="setUrlData(loraData.downloadUrl, loraData.fileName)">Download</button></td>
|
| 15 |
+
</template>
|
| 16 |
+
<template v-else>
|
| 17 |
+
<td>Not Found OTL</td>
|
| 18 |
+
</template>
|
| 19 |
+
</tr>
|
| 20 |
+
</template>
|
| 21 |
+
|
| 22 |
+
</tbody>
|
| 23 |
+
</table>
|
| 24 |
+
</div>
|
sd_feed/html/potd.html
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<div>
|
| 2 |
+
<div style="display: flex;justify-content: space-between;">
|
| 3 |
+
<div class="potd">
|
| 4 |
+
👑 POTD 👑
|
| 5 |
+
</div>
|
| 6 |
+
<div>
|
| 7 |
+
<label class="toggle-btn">
|
| 8 |
+
<span class="toggle-letter">Filter NSFW</span>
|
| 9 |
+
<input type="checkbox" v-model="filterNsfw" @change="fetchBests">
|
| 10 |
+
<span class="slider round"></span>
|
| 11 |
+
</label>
|
| 12 |
+
</div>
|
| 13 |
+
</div>
|
| 14 |
+
<div class="product-slider" v-if="bestFeeds.length > 0">
|
| 15 |
+
<div class="pinterest-gallery">
|
| 16 |
+
<template v-for="(imageData, j) in bestFeeds" :key="j">
|
| 17 |
+
<div class="pinterest-item">
|
| 18 |
+
<button @click="openModal(imageData)">
|
| 19 |
+
<img :src="imageData.url">
|
| 20 |
+
</button>
|
| 21 |
+
<div class="item-overlay">
|
| 22 |
+
<div style="display:flex;align-items: center;height:100%;">
|
| 23 |
+
<template v-if="!imageData.liked">
|
| 24 |
+
<div class="liked-button-div not-liked-div" @click="addToWishList(imageData)">
|
| 25 |
+
<button class="like-button">👍 {{formatNumber(imageData.likecount)}}</button>
|
| 26 |
+
</div>
|
| 27 |
+
</template>
|
| 28 |
+
<template v-else>
|
| 29 |
+
<div class="liked-button-div already-liked-div" @click="deleteWishList(imageData)">
|
| 30 |
+
<button class="like-button already-liked-button">👍 {{formatNumber(imageData.likecount)}}</button>
|
| 31 |
+
</div>
|
| 32 |
+
</template>
|
| 33 |
+
<div style="display: flex;justify-content: center;align-items: center;margin-left:5px;height:100%;">
|
| 34 |
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="12" zoomAndPan="magnify" viewBox="0 0 39 38.999999" height="12" preserveAspectRatio="xMidYMid meet" version="1.0"><defs><clipPath id="6d2be58645"><path d="M 2.515625 24 L 36.265625 24 L 36.265625 39 L 2.515625 39 Z M 2.515625 24 " clip-rule="nonzero"/></clipPath></defs><path fill="#ffffff" d="M 19.453125 0.21875 C 18.429688 0.21875 17.601562 1.054688 17.601562 2.085938 L 17.601562 22.101562 L 13.253906 17.730469 C 11.507812 16.023438 8.933594 18.601562 10.632812 20.367188 C 10.632812 20.367188 18.144531 27.925781 18.144531 27.925781 C 18.84375 28.65625 20.0625 28.632812 20.765625 27.925781 C 20.765625 27.925781 28.277344 20.367188 28.277344 20.367188 C 29.96875 18.605469 27.410156 16.023438 25.652344 17.730469 C 25.652344 17.730469 21.308594 22.101562 21.308594 22.101562 L 21.308594 2.085938 C 21.308594 1.054688 20.476562 0.21875 19.453125 0.21875 Z M 19.453125 0.21875 " fill-opacity="1" fill-rule="nonzero"/><g clip-path="url(#6d2be58645)"><path fill="#ffffff" d="M 4.433594 24.738281 C 3.410156 24.738281 2.578125 25.574219 2.578125 26.605469 L 2.578125 29.359375 C 2.578125 34.554688 6.78125 38.78125 11.945312 38.78125 L 26.964844 38.78125 C 32.128906 38.78125 36.328125 34.554688 36.328125 29.359375 L 36.328125 26.605469 C 36.328125 25.574219 35.5 24.738281 34.476562 24.738281 C 33.453125 24.738281 32.621094 25.574219 32.621094 26.605469 L 32.621094 29.359375 C 32.621094 32.496094 30.082031 35.050781 26.964844 35.050781 L 11.945312 35.050781 C 8.824219 35.050781 6.289062 32.496094 6.289062 29.359375 L 6.289062 26.605469 C 6.289062 25.574219 5.457031 24.738281 4.433594 24.738281 Z M 4.433594 24.738281 " fill-opacity="1" fill-rule="nonzero"/></g></svg>
|
| 35 |
+
</div>
|
| 36 |
+
<div style="display:flex;justify-content: center;align-items: center;color:white;">
|
| 37 |
+
{{formatNumber(imageData.total_sendto)}}
|
| 38 |
+
</div>
|
| 39 |
+
<div style="display: flex;justify-content: center;align-items: center;margin-left:5px;height:100%;">
|
| 40 |
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="20" zoomAndPan="magnify" viewBox="0 0 39 38.999999" height="20" preserveAspectRatio="xMidYMid meet" version="1.0"><defs><clipPath id="ae37d71e45"><path d="M 5.074219 5.542969 L 33.574219 5.542969 L 33.574219 33.292969 L 5.074219 33.292969 Z M 5.074219 5.542969 " clip-rule="nonzero"/></clipPath></defs><g clip-path="url(#ae37d71e45)"><path fill="#ffffff" d="M 11.796875 33.273438 C 11.722656 33.273438 11.648438 33.253906 11.582031 33.21875 C 11.4375 33.136719 11.347656 32.988281 11.347656 32.820312 L 11.347656 28.015625 L 9.152344 28.015625 C 6.902344 28.015625 5.074219 26.171875 5.074219 23.90625 L 5.074219 9.671875 C 5.074219 7.410156 6.902344 5.566406 9.152344 5.566406 L 29.492188 5.566406 C 31.742188 5.566406 33.570312 7.410156 33.570312 9.671875 L 33.570312 23.90625 C 33.570312 26.171875 31.742188 28.015625 29.492188 28.015625 L 20.226562 28.015625 C 17.496094 29.746094 14.765625 31.472656 12.035156 33.203125 C 11.964844 33.25 11.878906 33.273438 11.796875 33.273438 Z M 11.796875 33.273438 " fill-opacity="1" fill-rule="nonzero"/></g></svg>
|
| 41 |
+
</div>
|
| 42 |
+
<div style="display:flex;justify-content: center;align-items: center;color:white;">
|
| 43 |
+
{{formatNumber(imageData.total_comments)}}
|
| 44 |
+
</div>
|
| 45 |
+
</div>
|
| 46 |
+
<div style="display:flex;align-items:center;">
|
| 47 |
+
<a href="javascript:void(0);" target="_self" @click="(e)=>moveFeedProfileTab(e,imageData.nickname)" class="item-author">by {{imageData.nickname}}</a>
|
| 48 |
+
</div>
|
| 49 |
+
</div>
|
| 50 |
+
</div>
|
| 51 |
+
</template>
|
| 52 |
+
</div>
|
| 53 |
+
</div>
|
| 54 |
+
<div :class="{promptModal: showModal}" v-if="showModal">
|
| 55 |
+
<div class="prompt-modal-page">
|
| 56 |
+
<div class="prompt-modal-image" @click="closeOutsideModal">
|
| 57 |
+
<img :src="src" alt="Pretty Image" class="prompt-modal-image-tag"/>
|
| 58 |
+
</div>
|
| 59 |
+
<div class="prompt-modal-sidebar">
|
| 60 |
+
<div class="modal-sidebar-header">
|
| 61 |
+
<div style="display:flex;">
|
| 62 |
+
<div class="modal-like-wrapper">
|
| 63 |
+
<template v-if="!currentItem.liked">
|
| 64 |
+
<div class="big-liked-button-div not-liked-div" @click="addToWishList(currentItem)">
|
| 65 |
+
<button class="like-button">👍 {{formatNumber(currentItem.likecount)}}</button>
|
| 66 |
+
</div>
|
| 67 |
+
</template>
|
| 68 |
+
<template v-else>
|
| 69 |
+
<div class="big-liked-button-div already-liked-div" @click="deleteWishList(currentItem)">
|
| 70 |
+
<button class="like-button already-liked-button">👍 {{formatNumber(currentItem.likecount)}}</button>
|
| 71 |
+
</div>
|
| 72 |
+
</template>
|
| 73 |
+
</div>
|
| 74 |
+
<div class="modal-writer-wrappers">
|
| 75 |
+
<a class="modal-writer" href="javascript:void(0);" target="_self" @click="(e)=>moveFeedProfileTab(e,currentItem.nickname)">By {{currentItem.nickname}}</a>
|
| 76 |
+
<div class="modal-writer-time">{{currentItem.created_at}}</div>
|
| 77 |
+
</div>
|
| 78 |
+
</div>
|
| 79 |
+
<div class="modal-writer-wrapper-exit" @click="close()">
|
| 80 |
+
<div>
|
| 81 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="35" height="35" viewBox="0 0 35 35" fill="none">
|
| 82 |
+
<path d="M19.9037 17.8831L27.752 25.7314V27.7998H25.6837L17.8354 19.9514L9.98703 27.7998H7.9187V25.7314L15.767 17.8831L7.9187 10.0348V7.96643H9.98703L17.8354 15.8148L25.6837 7.96643H27.752V10.0348L19.9037 17.8831Z" fill="white"/>
|
| 83 |
+
<rect x="1.32679" y="1.37439" width="33.0173" height="33.0173" rx="4.50866" stroke="#0E0E0E" stroke-width="0.982675"/>
|
| 84 |
+
</svg>
|
| 85 |
+
</div>
|
| 86 |
+
</div>
|
| 87 |
+
</div>
|
| 88 |
+
<div class="modal-write-input-wrapper">
|
| 89 |
+
<div class="modal-write-input-div">
|
| 90 |
+
<textarea v-model="comment" @input="handleTextareaInput" id="modal-writer-type" class="modal-writer-type" @focus="makeSaveButtonVisible" placeholder="Type your comment"></textarea>
|
| 91 |
+
</div>
|
| 92 |
+
<div style="display:flex;justify-content:center;width:100%;">
|
| 93 |
+
<div v-if="showCommentWrite" class="write-row-button">
|
| 94 |
+
<button class="btn-write-row btn-cancel" @click="hideSaveButtonVisible">Cancel</button>
|
| 95 |
+
<button class="btn-write-row btn-save" @click="writeComment()">Comment</button>
|
| 96 |
+
/ </div>
|
| 97 |
+
</div>
|
| 98 |
+
</div>
|
| 99 |
+
<div style="margin-top:10px;border-bottom: 1px solid #AFB6BD;padding-bottom:17px;">
|
| 100 |
+
<template v-for="(commentData, j) in comments" :key="j">
|
| 101 |
+
<div style="margin-left:10px;margin-right:10px;">
|
| 102 |
+
<div style="display:flex;width:100%;margin-bottom:12px;color:white;">
|
| 103 |
+
<div style="margin-right:10px;color:white;font-size:17px;font-weight:700;">{{commentData.user.nickname}}</div>
|
| 104 |
+
<div style="color:white;font-size:12px;font-weight:300;">{{commentData.created_at}}</div>
|
| 105 |
+
</div>
|
| 106 |
+
<div style="display:flex;width:100%;color:white;">
|
| 107 |
+
<div style="color:white;font-size:13px;">{{commentData.text}}</div>
|
| 108 |
+
</div>
|
| 109 |
+
</div>
|
| 110 |
+
</template>
|
| 111 |
+
</div>
|
| 112 |
+
<div class="prompt-send-to">
|
| 113 |
+
<button class="btn-send-to btn-send-to-text" @click="this.sendToTextToImage()">Send to t2i</button>
|
| 114 |
+
<button class="btn-send-to btn-send-to-img" @click="this.sendToImageToImage()">Send to i2i</button>
|
| 115 |
+
</div>
|
| 116 |
+
<div style="margin-top:12px;">
|
| 117 |
+
<div style="margin-left: 10px;margin-right: 10px;">
|
| 118 |
+
<div style="color:white;margin-bottom:12px;">Generation Data</div>
|
| 119 |
+
<div style="box-sizing: border-box;display: flex;flex-direction: column;justify-content: center;align-items: flex-start;padding-left:20px;padding-right:20px;padding-top:10px;padding-bottom:10px;border: 1px solid #AFB6BD;border-radius: 5px;color:white;">
|
| 120 |
+
<template v-for="(value, key) in metadata">
|
| 121 |
+
<template v-if="/^[A-Z]/.test(key)">
|
| 122 |
+
{{key}}:{{value}},
|
| 123 |
+
</template>
|
| 124 |
+
</template>
|
| 125 |
+
</div>
|
| 126 |
+
<div style="display:flex;justify-content:center;margin-top:20px;">
|
| 127 |
+
<button @click="copyClipboard" style="text-align:center;box-sizing: border-box;display: flex;flex-direction: column;justify-content: center;align-items: flex-start;padding-top:10px;padding-bottom:10px;border: 1px solid #AFB6BD;border-radius: 5px;color:white;width:100%;">
|
| 128 |
+
<div style="color:white;margin:auto;">Copy Generation Data</div></button>
|
| 129 |
+
</div>
|
| 130 |
+
</div>
|
| 131 |
+
</div>
|
| 132 |
+
</div>
|
| 133 |
+
</div>
|
| 134 |
+
</div>
|
| 135 |
+
</div>
|
sd_feed/html/profile.html
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<template v-if="!editMode">
|
| 2 |
+
<div style="display:flex;align-items:center;">
|
| 3 |
+
<div style="padding: 10px; border-radius: 5px; display:flex;align-items:center;">
|
| 4 |
+
<p style="line-height:normal;line-height:0;font-size: 25px;font-weight: 800;margin-right: 10px;">By.</p>
|
| 5 |
+
<p style="line-height: 0;font-size: 20px;margin-right: 10p;">{{nickname}}</p>
|
| 6 |
+
</div>
|
| 7 |
+
<div style="padding: 10px; border-radius: 5px; display:flex;align-items:center;">
|
| 8 |
+
<p style="line-height: 0;font-size: 20px;margin-right: 10p;">{{profile}}</p>
|
| 9 |
+
</div>
|
| 10 |
+
<button @click="setEditMode" style="width:24px;height:24px;">
|
| 11 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather feather-edit-2"><path d="M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"></path></svg>
|
| 12 |
+
</button>
|
| 13 |
+
</div>
|
| 14 |
+
</template>
|
| 15 |
+
<template v-else>
|
| 16 |
+
<input style="padding: 10px; border-radius: 5px; border: 1px solid #ccc; flex-grow: 1;" type="text" v-model="nickname">
|
| 17 |
+
<button style="width:24px;height:24px;margin-right:15px;margin-left:15px;" @click="saveNickname">💾</button>
|
| 18 |
+
<button style="width:24px;height:24px;" @click="setEditMode">
|
| 19 |
+
✖️
|
| 20 |
+
</button>
|
| 21 |
+
</template>
|
sd_feed/install.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import launch
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
if not launch.is_installed("browsercookie"):
|
| 5 |
+
launch.run_pip("install browsercookie", "requirements for Browser Cookie")
|
sd_feed/javascript/axios.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).axios=t()}(this,(function(){"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function r(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function o(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==n)return;var r,o,i=[],a=!0,s=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){s=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(s)throw o}}return i}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return i(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function a(e,t){return function(){return e.apply(t,arguments)}}var s,u=Object.prototype.toString,c=Object.getPrototypeOf,f=(s=Object.create(null),function(e){var t=u.call(e);return s[t]||(s[t]=t.slice(8,-1).toLowerCase())}),l=function(e){return e=e.toLowerCase(),function(t){return f(t)===e}},d=function(t){return function(n){return e(n)===t}},p=Array.isArray,h=d("undefined");var m=l("ArrayBuffer");var y=d("string"),v=d("function"),b=d("number"),g=function(t){return null!==t&&"object"===e(t)},w=function(e){if("object"!==f(e))return!1;var t=c(e);return!(null!==t&&t!==Object.prototype&&null!==Object.getPrototypeOf(t)||Symbol.toStringTag in e||Symbol.iterator in e)},E=l("Date"),O=l("File"),S=l("Blob"),R=l("FileList"),A=l("URLSearchParams");function T(t,n){var r,o,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=i.allOwnKeys,s=void 0!==a&&a;if(null!=t)if("object"!==e(t)&&(t=[t]),p(t))for(r=0,o=t.length;r<o;r++)n.call(null,t[r],r,t);else{var u,c=s?Object.getOwnPropertyNames(t):Object.keys(t),f=c.length;for(r=0;r<f;r++)u=c[r],n.call(null,t[u],u,t)}}function j(e,t){t=t.toLowerCase();for(var n,r=Object.keys(e),o=r.length;o-- >0;)if(t===(n=r[o]).toLowerCase())return n;return null}var N="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:global,x=function(e){return!h(e)&&e!==N};var C,P=(C="undefined"!=typeof Uint8Array&&c(Uint8Array),function(e){return C&&e instanceof C}),k=l("HTMLFormElement"),U=function(e){var t=Object.prototype.hasOwnProperty;return function(e,n){return t.call(e,n)}}(),_=l("RegExp"),F=function(e,t){var n=Object.getOwnPropertyDescriptors(e),r={};T(n,(function(n,o){!1!==t(n,o,e)&&(r[o]=n)})),Object.defineProperties(e,r)},B="abcdefghijklmnopqrstuvwxyz",L="0123456789",D={DIGIT:L,ALPHA:B,ALPHA_DIGIT:B+B.toUpperCase()+L};var I={isArray:p,isArrayBuffer:m,isBuffer:function(e){return null!==e&&!h(e)&&null!==e.constructor&&!h(e.constructor)&&v(e.constructor.isBuffer)&&e.constructor.isBuffer(e)},isFormData:function(e){var t="[object FormData]";return e&&("function"==typeof FormData&&e instanceof FormData||u.call(e)===t||v(e.toString)&&e.toString()===t)},isArrayBufferView:function(e){return"undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&m(e.buffer)},isString:y,isNumber:b,isBoolean:function(e){return!0===e||!1===e},isObject:g,isPlainObject:w,isUndefined:h,isDate:E,isFile:O,isBlob:S,isRegExp:_,isFunction:v,isStream:function(e){return g(e)&&v(e.pipe)},isURLSearchParams:A,isTypedArray:P,isFileList:R,forEach:T,merge:function e(){for(var t=x(this)&&this||{},n=t.caseless,r={},o=function(t,o){var i=n&&j(r,o)||o;w(r[i])&&w(t)?r[i]=e(r[i],t):w(t)?r[i]=e({},t):p(t)?r[i]=t.slice():r[i]=t},i=0,a=arguments.length;i<a;i++)arguments[i]&&T(arguments[i],o);return r},extend:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=r.allOwnKeys;return T(t,(function(t,r){n&&v(t)?e[r]=a(t,n):e[r]=t}),{allOwnKeys:o}),e},trim:function(e){return e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")},stripBOM:function(e){return 65279===e.charCodeAt(0)&&(e=e.slice(1)),e},inherits:function(e,t,n,r){e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},toFlatObject:function(e,t,n,r){var o,i,a,s={};if(t=t||{},null==e)return t;do{for(i=(o=Object.getOwnPropertyNames(e)).length;i-- >0;)a=o[i],r&&!r(a,e,t)||s[a]||(t[a]=e[a],s[a]=!0);e=!1!==n&&c(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},kindOf:f,kindOfTest:l,endsWith:function(e,t,n){e=String(e),(void 0===n||n>e.length)&&(n=e.length),n-=t.length;var r=e.indexOf(t,n);return-1!==r&&r===n},toArray:function(e){if(!e)return null;if(p(e))return e;var t=e.length;if(!b(t))return null;for(var n=new Array(t);t-- >0;)n[t]=e[t];return n},forEachEntry:function(e,t){for(var n,r=(e&&e[Symbol.iterator]).call(e);(n=r.next())&&!n.done;){var o=n.value;t.call(e,o[0],o[1])}},matchAll:function(e,t){for(var n,r=[];null!==(n=e.exec(t));)r.push(n);return r},isHTMLForm:k,hasOwnProperty:U,hasOwnProp:U,reduceDescriptors:F,freezeMethods:function(e){F(e,(function(t,n){if(v(e)&&-1!==["arguments","caller","callee"].indexOf(n))return!1;var r=e[n];v(r)&&(t.enumerable=!1,"writable"in t?t.writable=!1:t.set||(t.set=function(){throw Error("Can not rewrite read-only method '"+n+"'")}))}))},toObjectSet:function(e,t){var n={},r=function(e){e.forEach((function(e){n[e]=!0}))};return p(e)?r(e):r(String(e).split(t)),n},toCamelCase:function(e){return e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,(function(e,t,n){return t.toUpperCase()+n}))},noop:function(){},toFiniteNumber:function(e,t){return e=+e,Number.isFinite(e)?e:t},findKey:j,global:N,isContextDefined:x,ALPHABET:D,generateString:function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:16,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:D.ALPHA_DIGIT,n="",r=t.length;e--;)n+=t[Math.random()*r|0];return n},isSpecCompliantForm:function(e){return!!(e&&v(e.append)&&"FormData"===e[Symbol.toStringTag]&&e[Symbol.iterator])},toJSONObject:function(e){var t=new Array(10);return function e(n,r){if(g(n)){if(t.indexOf(n)>=0)return;if(!("toJSON"in n)){t[r]=n;var o=p(n)?[]:{};return T(n,(function(t,n){var i=e(t,r+1);!h(i)&&(o[n]=i)})),t[r]=void 0,o}}return n}(e,0)}};function q(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=(new Error).stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o)}I.inherits(q,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:I.toJSONObject(this.config),code:this.code,status:this.response&&this.response.status?this.response.status:null}}});var M=q.prototype,z={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach((function(e){z[e]={value:e}})),Object.defineProperties(q,z),Object.defineProperty(M,"isAxiosError",{value:!0}),q.from=function(e,t,n,r,o,i){var a=Object.create(M);return I.toFlatObject(e,a,(function(e){return e!==Error.prototype}),(function(e){return"isAxiosError"!==e})),q.call(a,e.message,t,n,r,o),a.cause=e,a.name=e.name,i&&Object.assign(a,i),a};function H(e){return I.isPlainObject(e)||I.isArray(e)}function J(e){return I.endsWith(e,"[]")?e.slice(0,-2):e}function W(e,t,n){return e?e.concat(t).map((function(e,t){return e=J(e),!n&&t?"["+e+"]":e})).join(n?".":""):t}var K=I.toFlatObject(I,{},null,(function(e){return/^is[A-Z]/.test(e)}));function V(t,n,r){if(!I.isObject(t))throw new TypeError("target must be an object");n=n||new FormData;var o=(r=I.toFlatObject(r,{metaTokens:!0,dots:!1,indexes:!1},!1,(function(e,t){return!I.isUndefined(t[e])}))).metaTokens,i=r.visitor||f,a=r.dots,s=r.indexes,u=(r.Blob||"undefined"!=typeof Blob&&Blob)&&I.isSpecCompliantForm(n);if(!I.isFunction(i))throw new TypeError("visitor must be a function");function c(e){if(null===e)return"";if(I.isDate(e))return e.toISOString();if(!u&&I.isBlob(e))throw new q("Blob is not supported. Use a Buffer instead.");return I.isArrayBuffer(e)||I.isTypedArray(e)?u&&"function"==typeof Blob?new Blob([e]):Buffer.from(e):e}function f(t,r,i){var u=t;if(t&&!i&&"object"===e(t))if(I.endsWith(r,"{}"))r=o?r:r.slice(0,-2),t=JSON.stringify(t);else if(I.isArray(t)&&function(e){return I.isArray(e)&&!e.some(H)}(t)||(I.isFileList(t)||I.endsWith(r,"[]"))&&(u=I.toArray(t)))return r=J(r),u.forEach((function(e,t){!I.isUndefined(e)&&null!==e&&n.append(!0===s?W([r],t,a):null===s?r:r+"[]",c(e))})),!1;return!!H(t)||(n.append(W(i,r,a),c(t)),!1)}var l=[],d=Object.assign(K,{defaultVisitor:f,convertValue:c,isVisitable:H});if(!I.isObject(t))throw new TypeError("data must be an object");return function e(t,r){if(!I.isUndefined(t)){if(-1!==l.indexOf(t))throw Error("Circular reference detected in "+r.join("."));l.push(t),I.forEach(t,(function(t,o){!0===(!(I.isUndefined(t)||null===t)&&i.call(n,t,I.isString(o)?o.trim():o,r,d))&&e(t,r?r.concat(o):[o])})),l.pop()}}(t),n}function G(e){var t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,(function(e){return t[e]}))}function $(e,t){this._pairs=[],e&&V(e,this,t)}var X=$.prototype;function Q(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function Z(e,t,n){if(!t)return e;var r,o=n&&n.encode||Q,i=n&&n.serialize;if(r=i?i(t,n):I.isURLSearchParams(t)?t.toString():new $(t,n).toString(o)){var a=e.indexOf("#");-1!==a&&(e=e.slice(0,a)),e+=(-1===e.indexOf("?")?"?":"&")+r}return e}X.append=function(e,t){this._pairs.push([e,t])},X.toString=function(e){var t=e?function(t){return e.call(this,t,G)}:G;return this._pairs.map((function(e){return t(e[0])+"="+t(e[1])}),"").join("&")};var Y,ee=function(){function e(){t(this,e),this.handlers=[]}return r(e,[{key:"use",value:function(e,t,n){return this.handlers.push({fulfilled:e,rejected:t,synchronous:!!n&&n.synchronous,runWhen:n?n.runWhen:null}),this.handlers.length-1}},{key:"eject",value:function(e){this.handlers[e]&&(this.handlers[e]=null)}},{key:"clear",value:function(){this.handlers&&(this.handlers=[])}},{key:"forEach",value:function(e){I.forEach(this.handlers,(function(t){null!==t&&e(t)}))}}]),e}(),te={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},ne={isBrowser:!0,classes:{URLSearchParams:"undefined"!=typeof URLSearchParams?URLSearchParams:$,FormData:"undefined"!=typeof FormData?FormData:null,Blob:"undefined"!=typeof Blob?Blob:null},isStandardBrowserEnv:("undefined"==typeof navigator||"ReactNative"!==(Y=navigator.product)&&"NativeScript"!==Y&&"NS"!==Y)&&"undefined"!=typeof window&&"undefined"!=typeof document,isStandardBrowserWebWorkerEnv:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope&&"function"==typeof self.importScripts,protocols:["http","https","file","blob","url","data"]};function re(e){function t(e,n,r,o){var i=e[o++],a=Number.isFinite(+i),s=o>=e.length;return i=!i&&I.isArray(r)?r.length:i,s?(I.hasOwnProp(r,i)?r[i]=[r[i],n]:r[i]=n,!a):(r[i]&&I.isObject(r[i])||(r[i]=[]),t(e,n,r[i],o)&&I.isArray(r[i])&&(r[i]=function(e){var t,n,r={},o=Object.keys(e),i=o.length;for(t=0;t<i;t++)r[n=o[t]]=e[n];return r}(r[i])),!a)}if(I.isFormData(e)&&I.isFunction(e.entries)){var n={};return I.forEachEntry(e,(function(e,r){t(function(e){return I.matchAll(/\w+|\[(\w*)]/g,e).map((function(e){return"[]"===e[0]?"":e[1]||e[0]}))}(e),r,n,0)})),n}return null}var oe={"Content-Type":void 0};var ie={transitional:te,adapter:["xhr","http"],transformRequest:[function(e,t){var n,r=t.getContentType()||"",o=r.indexOf("application/json")>-1,i=I.isObject(e);if(i&&I.isHTMLForm(e)&&(e=new FormData(e)),I.isFormData(e))return o&&o?JSON.stringify(re(e)):e;if(I.isArrayBuffer(e)||I.isBuffer(e)||I.isStream(e)||I.isFile(e)||I.isBlob(e))return e;if(I.isArrayBufferView(e))return e.buffer;if(I.isURLSearchParams(e))return t.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),e.toString();if(i){if(r.indexOf("application/x-www-form-urlencoded")>-1)return function(e,t){return V(e,new ne.classes.URLSearchParams,Object.assign({visitor:function(e,t,n,r){return ne.isNode&&I.isBuffer(e)?(this.append(t,e.toString("base64")),!1):r.defaultVisitor.apply(this,arguments)}},t))}(e,this.formSerializer).toString();if((n=I.isFileList(e))||r.indexOf("multipart/form-data")>-1){var a=this.env&&this.env.FormData;return V(n?{"files[]":e}:e,a&&new a,this.formSerializer)}}return i||o?(t.setContentType("application/json",!1),function(e,t,n){if(I.isString(e))try{return(t||JSON.parse)(e),I.trim(e)}catch(e){if("SyntaxError"!==e.name)throw e}return(n||JSON.stringify)(e)}(e)):e}],transformResponse:[function(e){var t=this.transitional||ie.transitional,n=t&&t.forcedJSONParsing,r="json"===this.responseType;if(e&&I.isString(e)&&(n&&!this.responseType||r)){var o=!(t&&t.silentJSONParsing)&&r;try{return JSON.parse(e)}catch(e){if(o){if("SyntaxError"===e.name)throw q.from(e,q.ERR_BAD_RESPONSE,this,null,this.response);throw e}}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:ne.classes.FormData,Blob:ne.classes.Blob},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*"}}};I.forEach(["delete","get","head"],(function(e){ie.headers[e]={}})),I.forEach(["post","put","patch"],(function(e){ie.headers[e]=I.merge(oe)}));var ae=ie,se=I.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),ue=Symbol("internals");function ce(e){return e&&String(e).trim().toLowerCase()}function fe(e){return!1===e||null==e?e:I.isArray(e)?e.map(fe):String(e)}function le(e,t,n,r,o){return I.isFunction(r)?r.call(this,t,n):(o&&(t=n),I.isString(t)?I.isString(r)?-1!==t.indexOf(r):I.isRegExp(r)?r.test(t):void 0:void 0)}var de=function(e,n){function i(e){t(this,i),e&&this.set(e)}return r(i,[{key:"set",value:function(e,t,n){var r=this;function o(e,t,n){var o=ce(t);if(!o)throw new Error("header name must be a non-empty string");var i=I.findKey(r,o);(!i||void 0===r[i]||!0===n||void 0===n&&!1!==r[i])&&(r[i||t]=fe(e))}var i,a,s,u,c,f=function(e,t){return I.forEach(e,(function(e,n){return o(e,n,t)}))};return I.isPlainObject(e)||e instanceof this.constructor?f(e,t):I.isString(e)&&(e=e.trim())&&!/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim())?f((c={},(i=e)&&i.split("\n").forEach((function(e){u=e.indexOf(":"),a=e.substring(0,u).trim().toLowerCase(),s=e.substring(u+1).trim(),!a||c[a]&&se[a]||("set-cookie"===a?c[a]?c[a].push(s):c[a]=[s]:c[a]=c[a]?c[a]+", "+s:s)})),c),t):null!=e&&o(t,e,n),this}},{key:"get",value:function(e,t){if(e=ce(e)){var n=I.findKey(this,e);if(n){var r=this[n];if(!t)return r;if(!0===t)return function(e){for(var t,n=Object.create(null),r=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;t=r.exec(e);)n[t[1]]=t[2];return n}(r);if(I.isFunction(t))return t.call(this,r,n);if(I.isRegExp(t))return t.exec(r);throw new TypeError("parser must be boolean|regexp|function")}}}},{key:"has",value:function(e,t){if(e=ce(e)){var n=I.findKey(this,e);return!(!n||void 0===this[n]||t&&!le(0,this[n],n,t))}return!1}},{key:"delete",value:function(e,t){var n=this,r=!1;function o(e){if(e=ce(e)){var o=I.findKey(n,e);!o||t&&!le(0,n[o],o,t)||(delete n[o],r=!0)}}return I.isArray(e)?e.forEach(o):o(e),r}},{key:"clear",value:function(e){for(var t=Object.keys(this),n=t.length,r=!1;n--;){var o=t[n];e&&!le(0,this[o],o,e,!0)||(delete this[o],r=!0)}return r}},{key:"normalize",value:function(e){var t=this,n={};return I.forEach(this,(function(r,o){var i=I.findKey(n,o);if(i)return t[i]=fe(r),void delete t[o];var a=e?function(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(function(e,t,n){return t.toUpperCase()+n}))}(o):String(o).trim();a!==o&&delete t[o],t[a]=fe(r),n[a]=!0})),this}},{key:"concat",value:function(){for(var e,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return(e=this.constructor).concat.apply(e,[this].concat(n))}},{key:"toJSON",value:function(e){var t=Object.create(null);return I.forEach(this,(function(n,r){null!=n&&!1!==n&&(t[r]=e&&I.isArray(n)?n.join(", "):n)})),t}},{key:Symbol.iterator,value:function(){return Object.entries(this.toJSON())[Symbol.iterator]()}},{key:"toString",value:function(){return Object.entries(this.toJSON()).map((function(e){var t=o(e,2);return t[0]+": "+t[1]})).join("\n")}},{key:Symbol.toStringTag,get:function(){return"AxiosHeaders"}}],[{key:"from",value:function(e){return e instanceof this?e:new this(e)}},{key:"concat",value:function(e){for(var t=new this(e),n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return r.forEach((function(e){return t.set(e)})),t}},{key:"accessor",value:function(e){var t=(this[ue]=this[ue]={accessors:{}}).accessors,n=this.prototype;function r(e){var r=ce(e);t[r]||(!function(e,t){var n=I.toCamelCase(" "+t);["get","set","has"].forEach((function(r){Object.defineProperty(e,r+n,{value:function(e,n,o){return this[r].call(this,t,e,n,o)},configurable:!0})}))}(n,e),t[r]=!0)}return I.isArray(e)?e.forEach(r):r(e),this}}]),i}();de.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),I.freezeMethods(de.prototype),I.freezeMethods(de);var pe=de;function he(e,t){var n=this||ae,r=t||n,o=pe.from(r.headers),i=r.data;return I.forEach(e,(function(e){i=e.call(n,i,o.normalize(),t?t.status:void 0)})),o.normalize(),i}function me(e){return!(!e||!e.__CANCEL__)}function ye(e,t,n){q.call(this,null==e?"canceled":e,q.ERR_CANCELED,t,n),this.name="CanceledError"}I.inherits(ye,q,{__CANCEL__:!0});var ve=ne.isStandardBrowserEnv?{write:function(e,t,n,r,o,i){var a=[];a.push(e+"="+encodeURIComponent(t)),I.isNumber(n)&&a.push("expires="+new Date(n).toGMTString()),I.isString(r)&&a.push("path="+r),I.isString(o)&&a.push("domain="+o),!0===i&&a.push("secure"),document.cookie=a.join("; ")},read:function(e){var t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove:function(e){this.write(e,"",Date.now()-864e5)}}:{write:function(){},read:function(){return null},remove:function(){}};function be(e,t){return e&&!/^([a-z][a-z\d+\-.]*:)?\/\//i.test(t)?function(e,t){return t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e}(e,t):t}var ge=ne.isStandardBrowserEnv?function(){var e,t=/(msie|trident)/i.test(navigator.userAgent),n=document.createElement("a");function r(e){var r=e;return t&&(n.setAttribute("href",r),r=n.href),n.setAttribute("href",r),{href:n.href,protocol:n.protocol?n.protocol.replace(/:$/,""):"",host:n.host,search:n.search?n.search.replace(/^\?/,""):"",hash:n.hash?n.hash.replace(/^#/,""):"",hostname:n.hostname,port:n.port,pathname:"/"===n.pathname.charAt(0)?n.pathname:"/"+n.pathname}}return e=r(window.location.href),function(t){var n=I.isString(t)?r(t):t;return n.protocol===e.protocol&&n.host===e.host}}():function(){return!0};function we(e,t){var n=0,r=function(e,t){e=e||10;var n,r=new Array(e),o=new Array(e),i=0,a=0;return t=void 0!==t?t:1e3,function(s){var u=Date.now(),c=o[a];n||(n=u),r[i]=s,o[i]=u;for(var f=a,l=0;f!==i;)l+=r[f++],f%=e;if((i=(i+1)%e)===a&&(a=(a+1)%e),!(u-n<t)){var d=c&&u-c;return d?Math.round(1e3*l/d):void 0}}}(50,250);return function(o){var i=o.loaded,a=o.lengthComputable?o.total:void 0,s=i-n,u=r(s);n=i;var c={loaded:i,total:a,progress:a?i/a:void 0,bytes:s,rate:u||void 0,estimated:u&&a&&i<=a?(a-i)/u:void 0,event:o};c[t?"download":"upload"]=!0,e(c)}}var Ee={http:null,xhr:"undefined"!=typeof XMLHttpRequest&&function(e){return new Promise((function(t,n){var r,o=e.data,i=pe.from(e.headers).normalize(),a=e.responseType;function s(){e.cancelToken&&e.cancelToken.unsubscribe(r),e.signal&&e.signal.removeEventListener("abort",r)}I.isFormData(o)&&(ne.isStandardBrowserEnv||ne.isStandardBrowserWebWorkerEnv)&&i.setContentType(!1);var u=new XMLHttpRequest;if(e.auth){var c=e.auth.username||"",f=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";i.set("Authorization","Basic "+btoa(c+":"+f))}var l=be(e.baseURL,e.url);function d(){if(u){var r=pe.from("getAllResponseHeaders"in u&&u.getAllResponseHeaders());!function(e,t,n){var r=n.config.validateStatus;n.status&&r&&!r(n.status)?t(new q("Request failed with status code "+n.status,[q.ERR_BAD_REQUEST,q.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n)):e(n)}((function(e){t(e),s()}),(function(e){n(e),s()}),{data:a&&"text"!==a&&"json"!==a?u.response:u.responseText,status:u.status,statusText:u.statusText,headers:r,config:e,request:u}),u=null}}if(u.open(e.method.toUpperCase(),Z(l,e.params,e.paramsSerializer),!0),u.timeout=e.timeout,"onloadend"in u?u.onloadend=d:u.onreadystatechange=function(){u&&4===u.readyState&&(0!==u.status||u.responseURL&&0===u.responseURL.indexOf("file:"))&&setTimeout(d)},u.onabort=function(){u&&(n(new q("Request aborted",q.ECONNABORTED,e,u)),u=null)},u.onerror=function(){n(new q("Network Error",q.ERR_NETWORK,e,u)),u=null},u.ontimeout=function(){var t=e.timeout?"timeout of "+e.timeout+"ms exceeded":"timeout exceeded",r=e.transitional||te;e.timeoutErrorMessage&&(t=e.timeoutErrorMessage),n(new q(t,r.clarifyTimeoutError?q.ETIMEDOUT:q.ECONNABORTED,e,u)),u=null},ne.isStandardBrowserEnv){var p=(e.withCredentials||ge(l))&&e.xsrfCookieName&&ve.read(e.xsrfCookieName);p&&i.set(e.xsrfHeaderName,p)}void 0===o&&i.setContentType(null),"setRequestHeader"in u&&I.forEach(i.toJSON(),(function(e,t){u.setRequestHeader(t,e)})),I.isUndefined(e.withCredentials)||(u.withCredentials=!!e.withCredentials),a&&"json"!==a&&(u.responseType=e.responseType),"function"==typeof e.onDownloadProgress&&u.addEventListener("progress",we(e.onDownloadProgress,!0)),"function"==typeof e.onUploadProgress&&u.upload&&u.upload.addEventListener("progress",we(e.onUploadProgress)),(e.cancelToken||e.signal)&&(r=function(t){u&&(n(!t||t.type?new ye(null,e,u):t),u.abort(),u=null)},e.cancelToken&&e.cancelToken.subscribe(r),e.signal&&(e.signal.aborted?r():e.signal.addEventListener("abort",r)));var h,m=(h=/^([-+\w]{1,25})(:?\/\/|:)/.exec(l))&&h[1]||"";m&&-1===ne.protocols.indexOf(m)?n(new q("Unsupported protocol "+m+":",q.ERR_BAD_REQUEST,e)):u.send(o||null)}))}};I.forEach(Ee,(function(e,t){if(e){try{Object.defineProperty(e,"name",{value:t})}catch(e){}Object.defineProperty(e,"adapterName",{value:t})}}));var Oe=function(e){for(var t,n,r=(e=I.isArray(e)?e:[e]).length,o=0;o<r&&(t=e[o],!(n=I.isString(t)?Ee[t.toLowerCase()]:t));o++);if(!n){if(!1===n)throw new q("Adapter ".concat(t," is not supported by the environment"),"ERR_NOT_SUPPORT");throw new Error(I.hasOwnProp(Ee,t)?"Adapter '".concat(t,"' is not available in the build"):"Unknown adapter '".concat(t,"'"))}if(!I.isFunction(n))throw new TypeError("adapter is not a function");return n};function Se(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new ye(null,e)}function Re(e){return Se(e),e.headers=pe.from(e.headers),e.data=he.call(e,e.transformRequest),-1!==["post","put","patch"].indexOf(e.method)&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Oe(e.adapter||ae.adapter)(e).then((function(t){return Se(e),t.data=he.call(e,e.transformResponse,t),t.headers=pe.from(t.headers),t}),(function(t){return me(t)||(Se(e),t&&t.response&&(t.response.data=he.call(e,e.transformResponse,t.response),t.response.headers=pe.from(t.response.headers))),Promise.reject(t)}))}var Ae=function(e){return e instanceof pe?e.toJSON():e};function Te(e,t){t=t||{};var n={};function r(e,t,n){return I.isPlainObject(e)&&I.isPlainObject(t)?I.merge.call({caseless:n},e,t):I.isPlainObject(t)?I.merge({},t):I.isArray(t)?t.slice():t}function o(e,t,n){return I.isUndefined(t)?I.isUndefined(e)?void 0:r(void 0,e,n):r(e,t,n)}function i(e,t){if(!I.isUndefined(t))return r(void 0,t)}function a(e,t){return I.isUndefined(t)?I.isUndefined(e)?void 0:r(void 0,e):r(void 0,t)}function s(n,o,i){return i in t?r(n,o):i in e?r(void 0,n):void 0}var u={url:i,method:i,data:i,baseURL:a,transformRequest:a,transformResponse:a,paramsSerializer:a,timeout:a,timeoutMessage:a,withCredentials:a,adapter:a,responseType:a,xsrfCookieName:a,xsrfHeaderName:a,onUploadProgress:a,onDownloadProgress:a,decompress:a,maxContentLength:a,maxBodyLength:a,beforeRedirect:a,transport:a,httpAgent:a,httpsAgent:a,cancelToken:a,socketPath:a,responseEncoding:a,validateStatus:s,headers:function(e,t){return o(Ae(e),Ae(t),!0)}};return I.forEach(Object.keys(e).concat(Object.keys(t)),(function(r){var i=u[r]||o,a=i(e[r],t[r],r);I.isUndefined(a)&&i!==s||(n[r]=a)})),n}var je="1.3.5",Ne={};["object","boolean","number","function","string","symbol"].forEach((function(t,n){Ne[t]=function(r){return e(r)===t||"a"+(n<1?"n ":" ")+t}}));var xe={};Ne.transitional=function(e,t,n){function r(e,t){return"[Axios v1.3.5] Transitional option '"+e+"'"+t+(n?". "+n:"")}return function(n,o,i){if(!1===e)throw new q(r(o," has been removed"+(t?" in "+t:"")),q.ERR_DEPRECATED);return t&&!xe[o]&&(xe[o]=!0,console.warn(r(o," has been deprecated since v"+t+" and will be removed in the near future"))),!e||e(n,o,i)}};var Ce={assertOptions:function(t,n,r){if("object"!==e(t))throw new q("options must be an object",q.ERR_BAD_OPTION_VALUE);for(var o=Object.keys(t),i=o.length;i-- >0;){var a=o[i],s=n[a];if(s){var u=t[a],c=void 0===u||s(u,a,t);if(!0!==c)throw new q("option "+a+" must be "+c,q.ERR_BAD_OPTION_VALUE)}else if(!0!==r)throw new q("Unknown option "+a,q.ERR_BAD_OPTION)}},validators:Ne},Pe=Ce.validators,ke=function(){function e(n){t(this,e),this.defaults=n,this.interceptors={request:new ee,response:new ee}}return r(e,[{key:"request",value:function(e,t){"string"==typeof e?(t=t||{}).url=e:t=e||{};var n,r=t=Te(this.defaults,t),o=r.transitional,i=r.paramsSerializer,a=r.headers;void 0!==o&&Ce.assertOptions(o,{silentJSONParsing:Pe.transitional(Pe.boolean),forcedJSONParsing:Pe.transitional(Pe.boolean),clarifyTimeoutError:Pe.transitional(Pe.boolean)},!1),null!=i&&(I.isFunction(i)?t.paramsSerializer={serialize:i}:Ce.assertOptions(i,{encode:Pe.function,serialize:Pe.function},!0)),t.method=(t.method||this.defaults.method||"get").toLowerCase(),(n=a&&I.merge(a.common,a[t.method]))&&I.forEach(["delete","get","head","post","put","patch","common"],(function(e){delete a[e]})),t.headers=pe.concat(n,a);var s=[],u=!0;this.interceptors.request.forEach((function(e){"function"==typeof e.runWhen&&!1===e.runWhen(t)||(u=u&&e.synchronous,s.unshift(e.fulfilled,e.rejected))}));var c,f=[];this.interceptors.response.forEach((function(e){f.push(e.fulfilled,e.rejected)}));var l,d=0;if(!u){var p=[Re.bind(this),void 0];for(p.unshift.apply(p,s),p.push.apply(p,f),l=p.length,c=Promise.resolve(t);d<l;)c=c.then(p[d++],p[d++]);return c}l=s.length;var h=t;for(d=0;d<l;){var m=s[d++],y=s[d++];try{h=m(h)}catch(e){y.call(this,e);break}}try{c=Re.call(this,h)}catch(e){return Promise.reject(e)}for(d=0,l=f.length;d<l;)c=c.then(f[d++],f[d++]);return c}},{key:"getUri",value:function(e){return Z(be((e=Te(this.defaults,e)).baseURL,e.url),e.params,e.paramsSerializer)}}]),e}();I.forEach(["delete","get","head","options"],(function(e){ke.prototype[e]=function(t,n){return this.request(Te(n||{},{method:e,url:t,data:(n||{}).data}))}})),I.forEach(["post","put","patch"],(function(e){function t(t){return function(n,r,o){return this.request(Te(o||{},{method:e,headers:t?{"Content-Type":"multipart/form-data"}:{},url:n,data:r}))}}ke.prototype[e]=t(),ke.prototype[e+"Form"]=t(!0)}));var Ue=ke,_e=function(){function e(n){if(t(this,e),"function"!=typeof n)throw new TypeError("executor must be a function.");var r;this.promise=new Promise((function(e){r=e}));var o=this;this.promise.then((function(e){if(o._listeners){for(var t=o._listeners.length;t-- >0;)o._listeners[t](e);o._listeners=null}})),this.promise.then=function(e){var t,n=new Promise((function(e){o.subscribe(e),t=e})).then(e);return n.cancel=function(){o.unsubscribe(t)},n},n((function(e,t,n){o.reason||(o.reason=new ye(e,t,n),r(o.reason))}))}return r(e,[{key:"throwIfRequested",value:function(){if(this.reason)throw this.reason}},{key:"subscribe",value:function(e){this.reason?e(this.reason):this._listeners?this._listeners.push(e):this._listeners=[e]}},{key:"unsubscribe",value:function(e){if(this._listeners){var t=this._listeners.indexOf(e);-1!==t&&this._listeners.splice(t,1)}}}],[{key:"source",value:function(){var t;return{token:new e((function(e){t=e})),cancel:t}}}]),e}();var Fe={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Fe).forEach((function(e){var t=o(e,2),n=t[0],r=t[1];Fe[r]=n}));var Be=Fe;var Le=function e(t){var n=new Ue(t),r=a(Ue.prototype.request,n);return I.extend(r,Ue.prototype,n,{allOwnKeys:!0}),I.extend(r,n,null,{allOwnKeys:!0}),r.create=function(n){return e(Te(t,n))},r}(ae);return Le.Axios=Ue,Le.CanceledError=ye,Le.CancelToken=_e,Le.isCancel=me,Le.VERSION=je,Le.toFormData=V,Le.AxiosError=q,Le.Cancel=Le.CanceledError,Le.all=function(e){return Promise.all(e)},Le.spread=function(e){return function(t){return e.apply(null,t)}},Le.isAxiosError=function(e){return I.isObject(e)&&!0===e.isAxiosError},Le.mergeConfig=Te,Le.AxiosHeaders=pe,Le.formToJSON=function(e){return re(I.isHTMLForm(e)?new FormData(e):e)},Le.HttpStatusCode=Be,Le.default=Le,Le}));
|
| 2 |
+
// # sourceMappingURL=axios.min.js.map
|
sd_feed/javascript/best_feed.js
ADDED
|
@@ -0,0 +1,638 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
function waitForElementToDisplay2(selector, callback, checkFrequencyInMs, timeoutInMs) {
|
| 3 |
+
(function loopSearch() {
|
| 4 |
+
if (document.querySelector(selector) != null && window.localStorage.getItem("userId")) {
|
| 5 |
+
callback();
|
| 6 |
+
return;
|
| 7 |
+
}
|
| 8 |
+
else if(document.getElementsByTagName("gradio-app").length > 0 &&
|
| 9 |
+
document.getElementsByTagName("gradio-app")[0].shadowRoot){
|
| 10 |
+
callback();
|
| 11 |
+
return;
|
| 12 |
+
}
|
| 13 |
+
else {
|
| 14 |
+
setTimeout(function () {
|
| 15 |
+
loopSearch();
|
| 16 |
+
}, checkFrequencyInMs);
|
| 17 |
+
}
|
| 18 |
+
})();
|
| 19 |
+
}
|
| 20 |
+
waitForElementToDisplay2(
|
| 21 |
+
"#html_id",
|
| 22 |
+
function(){
|
| 23 |
+
async function copyToClipboard(textToCopy) {
|
| 24 |
+
// Navigator clipboard api needs a secure context (https)
|
| 25 |
+
if (navigator.clipboard && window.isSecureContext) {
|
| 26 |
+
await navigator.clipboard.writeText(textToCopy);
|
| 27 |
+
} else {
|
| 28 |
+
// Use the 'out of viewport hidden text area' trick
|
| 29 |
+
const textArea = document.createElement("textarea");
|
| 30 |
+
textArea.value = textToCopy;
|
| 31 |
+
|
| 32 |
+
// Move textarea out of the viewport so it's not visible
|
| 33 |
+
textArea.style.position = "absolute";
|
| 34 |
+
textArea.style.left = "-999999px";
|
| 35 |
+
|
| 36 |
+
document.body.prepend(textArea);
|
| 37 |
+
textArea.select();
|
| 38 |
+
|
| 39 |
+
try {
|
| 40 |
+
document.execCommand('copy');
|
| 41 |
+
} catch (error) {
|
| 42 |
+
console.error(error);
|
| 43 |
+
} finally {
|
| 44 |
+
textArea.remove();
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
};
|
| 48 |
+
const userModel = {
|
| 49 |
+
data() {
|
| 50 |
+
return {
|
| 51 |
+
bestFeeds: [],
|
| 52 |
+
comments: [],
|
| 53 |
+
userId: '',
|
| 54 |
+
showCommentWrite: false,
|
| 55 |
+
comment: '',
|
| 56 |
+
src: '',
|
| 57 |
+
imageId: "",
|
| 58 |
+
metadata: {},
|
| 59 |
+
currentItem: {},
|
| 60 |
+
filterNsfw: false,
|
| 61 |
+
showModal:false,
|
| 62 |
+
|
| 63 |
+
}
|
| 64 |
+
},
|
| 65 |
+
watch: {
|
| 66 |
+
showModal() {
|
| 67 |
+
if (this.showModal === false) {
|
| 68 |
+
window.removeEventListener("keyup", this.onEscapeKey);
|
| 69 |
+
} else {
|
| 70 |
+
window.addEventListener("keyup", this.onEscapeKey);
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
},
|
| 74 |
+
methods: {
|
| 75 |
+
close() {
|
| 76 |
+
this.$emit('close');
|
| 77 |
+
this.showModal=false;
|
| 78 |
+
this.imageId = "";
|
| 79 |
+
this.src = "";
|
| 80 |
+
this.comment = '';
|
| 81 |
+
this.comments = [];
|
| 82 |
+
},
|
| 83 |
+
moveFeedProfileTab(event, nickname){
|
| 84 |
+
event.preventDefault();
|
| 85 |
+
if(nickname){
|
| 86 |
+
this.close();
|
| 87 |
+
const buttonList = gradioApp().querySelector('#tabs').querySelectorAll('button');
|
| 88 |
+
for (step = 0; step < buttonList.length; step++) {
|
| 89 |
+
// Runs 5 times, with values of step 0 through 4.
|
| 90 |
+
if(buttonList[step].textContent.trim() == 'Feed'){
|
| 91 |
+
buttonList[step].click();
|
| 92 |
+
break;
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
try{
|
| 96 |
+
const feedUserButton = gradioApp().querySelector('#feed-user-tab');
|
| 97 |
+
feedUserButton.setAttribute("data-value", nickname);
|
| 98 |
+
feedUserButton.innerHTML = nickname;
|
| 99 |
+
feedUserButton.click();
|
| 100 |
+
|
| 101 |
+
}catch(e){
|
| 102 |
+
console.log(e);
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
},
|
| 108 |
+
closeOutsideModal(event) {
|
| 109 |
+
if(!event.target.closest('.prompt-modal-image-tag')){
|
| 110 |
+
this.$emit('close');
|
| 111 |
+
this.showModal=false;
|
| 112 |
+
this.imageId = "";
|
| 113 |
+
this.src = "";
|
| 114 |
+
this.comment = '';
|
| 115 |
+
this.comments = [];
|
| 116 |
+
}
|
| 117 |
+
},
|
| 118 |
+
onEscapeKey(event) {
|
| 119 |
+
if (event.keyCode === 27 || event.key === 'Escape') {
|
| 120 |
+
// Perform action when "Esc" key is pressed
|
| 121 |
+
this.close();
|
| 122 |
+
}
|
| 123 |
+
// Perform action when "Esc" key is pressed
|
| 124 |
+
},
|
| 125 |
+
fetchBests(){
|
| 126 |
+
const token = localStorage.getItem("token");
|
| 127 |
+
const userId = localStorage.getItem("userId");
|
| 128 |
+
const headers={"Authorization":"Token " + token};
|
| 129 |
+
const params = {
|
| 130 |
+
filter_nsfw: this.filterNsfw,
|
| 131 |
+
};
|
| 132 |
+
axios.get(
|
| 133 |
+
`https://newtypev3-server-vjiloyvjvq-an.a.run.app/image/best/${userId}`,
|
| 134 |
+
{
|
| 135 |
+
headers,
|
| 136 |
+
params
|
| 137 |
+
}
|
| 138 |
+
)
|
| 139 |
+
.then(response => {
|
| 140 |
+
const dataObject = response.data;
|
| 141 |
+
this.bestFeeds = dataObject.slice(0, 4);
|
| 142 |
+
}).catch(error => {
|
| 143 |
+
this.loading = false;
|
| 144 |
+
console.log(error)
|
| 145 |
+
});
|
| 146 |
+
},
|
| 147 |
+
formatNumber(num) {
|
| 148 |
+
if (num >= 1000000) {
|
| 149 |
+
return (num / 1000000).toFixed(1) + 'm';
|
| 150 |
+
} else if (num >= 1000) {
|
| 151 |
+
return (num / 1000).toFixed(1) + 'k';
|
| 152 |
+
} else {
|
| 153 |
+
return num.toString();
|
| 154 |
+
}
|
| 155 |
+
},
|
| 156 |
+
openModal(item){
|
| 157 |
+
this.showModal = true;
|
| 158 |
+
this.$forceUpdate();
|
| 159 |
+
this.currentItem = item;
|
| 160 |
+
this.metadata = item.metadata;
|
| 161 |
+
this.src = item.url;
|
| 162 |
+
this.imageId = item.id;
|
| 163 |
+
item.total_clicks += 1;
|
| 164 |
+
this.addImageClick();
|
| 165 |
+
this.fetchComments();
|
| 166 |
+
},
|
| 167 |
+
openModalSecond(event){
|
| 168 |
+
console.log(event);
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
},
|
| 172 |
+
addImageClick(){
|
| 173 |
+
const userId = localStorage.getItem("userId");
|
| 174 |
+
const imageId = this.imageId;
|
| 175 |
+
const token = localStorage.getItem("token");
|
| 176 |
+
const headers={"Authorization":"Token " + token};
|
| 177 |
+
axios.post(
|
| 178 |
+
'https://newtypev3-server-vjiloyvjvq-an.a.run.app/image/click',
|
| 179 |
+
{
|
| 180 |
+
userId,
|
| 181 |
+
imageId,
|
| 182 |
+
},
|
| 183 |
+
{
|
| 184 |
+
headers
|
| 185 |
+
}
|
| 186 |
+
)
|
| 187 |
+
.then(response => {
|
| 188 |
+
this.showModal = true;
|
| 189 |
+
}).catch(error => {
|
| 190 |
+
this.loading = false;
|
| 191 |
+
console.log(error)
|
| 192 |
+
})
|
| 193 |
+
},
|
| 194 |
+
sendToTextToImage(){
|
| 195 |
+
const userId = localStorage.getItem("userId");
|
| 196 |
+
const token = localStorage.getItem("token");
|
| 197 |
+
const headers={"Authorization":"Token " + token};
|
| 198 |
+
|
| 199 |
+
const imageId = this.imageId;
|
| 200 |
+
this.currentItem.total_sendto = this.currentItem.total_sendto + 1;
|
| 201 |
+
axios.post(
|
| 202 |
+
'https://newtypev3-server-vjiloyvjvq-an.a.run.app/image/send_to',
|
| 203 |
+
{
|
| 204 |
+
userId,
|
| 205 |
+
imageId,
|
| 206 |
+
sendType: "SEND_TO_TEXT",
|
| 207 |
+
},
|
| 208 |
+
{
|
| 209 |
+
headers
|
| 210 |
+
}
|
| 211 |
+
)
|
| 212 |
+
.then(response => {
|
| 213 |
+
this.sendToTextProcess();
|
| 214 |
+
}).catch(error => {
|
| 215 |
+
this.loading = false;
|
| 216 |
+
console.log(error)
|
| 217 |
+
})
|
| 218 |
+
},
|
| 219 |
+
|
| 220 |
+
copyClipboard(){
|
| 221 |
+
const userId = localStorage.getItem("userId");
|
| 222 |
+
const imageId = this.imageId;
|
| 223 |
+
const token = localStorage.getItem("token");
|
| 224 |
+
const headers={"Authorization":"Token " + token};
|
| 225 |
+
axios.post(
|
| 226 |
+
'https://newtypev3-server-vjiloyvjvq-an.a.run.app/image/send_to',
|
| 227 |
+
{
|
| 228 |
+
userId,
|
| 229 |
+
imageId,
|
| 230 |
+
sendType: "COPY_TO_CLIPBOARD",
|
| 231 |
+
},
|
| 232 |
+
{
|
| 233 |
+
headers
|
| 234 |
+
}
|
| 235 |
+
)
|
| 236 |
+
.then(response => {
|
| 237 |
+
let filteredObject = '';
|
| 238 |
+
for (const [k, v] of Object.entries(this.metadata)) {
|
| 239 |
+
if (/^[A-Z]/.test(k)) {
|
| 240 |
+
filteredObject += `${k}:${v},`;
|
| 241 |
+
}
|
| 242 |
+
}
|
| 243 |
+
this.currentItem.total_sendto = this.currentItem.total_sendto + 1;
|
| 244 |
+
copyToClipboard(filteredObject);
|
| 245 |
+
}).catch(error => {
|
| 246 |
+
this.loading = false;
|
| 247 |
+
console.log(error)
|
| 248 |
+
});
|
| 249 |
+
|
| 250 |
+
},
|
| 251 |
+
sendToTextProcess(){
|
| 252 |
+
const textPrompt = gradioApp().querySelector('#txt2img_prompt').getElementsByTagName( 'textarea' );
|
| 253 |
+
if(textPrompt&&textPrompt.length> 0){
|
| 254 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_prompt')[0].props.value = this.metadata.prompt;
|
| 255 |
+
textPrompt[0].value = this.metadata.prompt;
|
| 256 |
+
}
|
| 257 |
+
const negativePrompt = gradioApp().querySelector('#txt2img_neg_prompt').getElementsByTagName( 'textarea' );
|
| 258 |
+
if(negativePrompt&&negativePrompt.length> 0){
|
| 259 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_neg_prompt')[0].props.value = this.metadata.negative_prompt;
|
| 260 |
+
negativePrompt[0].value = this.metadata.negative_prompt;
|
| 261 |
+
}
|
| 262 |
+
try{
|
| 263 |
+
const samplerList = gradioApp().querySelector( '#txt2img_sampling' ).getElementsByTagName('span');
|
| 264 |
+
if(samplerList&&samplerList.length> 1){
|
| 265 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_sampling')[0].props.value = this.metadata.sampler;
|
| 266 |
+
samplerList[1].textContent = this.metadata.sampler;
|
| 267 |
+
}
|
| 268 |
+
}catch(e){
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
try{
|
| 272 |
+
const textImageStepsList = gradioApp().querySelector( '#txt2img_steps' ).getElementsByTagName('input');
|
| 273 |
+
if(textImageStepsList&&textImageStepsList.length> 1){
|
| 274 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_steps')[0].props.value = parseInt(this.metadata.n_iter);
|
| 275 |
+
textImageStepsList[0].value = this.metadata.n_iter;
|
| 276 |
+
textImageStepsList[1].value = this.metadata.n_iter;
|
| 277 |
+
}
|
| 278 |
+
}catch(e){
|
| 279 |
+
}
|
| 280 |
+
try{
|
| 281 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_width')[0].props.value = parseInt(this.metadata['Size-1']);
|
| 282 |
+
const textWidthList = gradioApp().querySelector( '#txt2img_width' ).getElementsByTagName('input');
|
| 283 |
+
if(textWidthList&&textWidthList.length> 1){
|
| 284 |
+
textWidthList[0].value = this.metadata['Size-1'];
|
| 285 |
+
textWidthList[1].value = this.metadata['Size-1'];
|
| 286 |
+
}
|
| 287 |
+
}catch(e){
|
| 288 |
+
}
|
| 289 |
+
try{
|
| 290 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_height')[0].props.value = parseInt(this.metadata['Size-2']);
|
| 291 |
+
const textWidthList = gradioApp().querySelector( '#txt2img_height' ).getElementsByTagName('input');
|
| 292 |
+
if(textWidthList&&textWidthList.length> 1){
|
| 293 |
+
textWidthList[0].value = this.metadata['Size-2'];
|
| 294 |
+
textWidthList[1].value = this.metadata['Size-2'];
|
| 295 |
+
}
|
| 296 |
+
}catch(e){
|
| 297 |
+
}
|
| 298 |
+
try{
|
| 299 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_cfg_scale')[0].props.value = parseFloat(this.metadata['cfg_scale']);
|
| 300 |
+
const cfgScaleList = gradioApp().querySelector( '#txt2img_cfg_scale' ).getElementsByTagName('input');
|
| 301 |
+
if(cfgScaleList&&cfgScaleList.length> 1){
|
| 302 |
+
cfgScaleList[0].value = this.metadata['cfg_scale'];
|
| 303 |
+
cfgScaleList[1].value = this.metadata['cfg_scale'];
|
| 304 |
+
}
|
| 305 |
+
}catch(e){
|
| 306 |
+
}
|
| 307 |
+
try{
|
| 308 |
+
const steps = this.metadata['Hires upscaler'];
|
| 309 |
+
if(steps){
|
| 310 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_enable_hr')[0].props.value = true;
|
| 311 |
+
gradioApp().querySelector( '#txt2img_enable_hr' ).getElementsByTagName('input')[0].checked = true;
|
| 312 |
+
try{
|
| 313 |
+
const originalHires = gradioApp().querySelector( '#txt2img_hires_fix' );
|
| 314 |
+
originalHires.classList.remove('hidden');
|
| 315 |
+
}catch(e){
|
| 316 |
+
|
| 317 |
+
}
|
| 318 |
+
const scalerMethod = this.metadata['Hires upscaler'];
|
| 319 |
+
const containUpscaler = window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_hr_upscaler')[0].props.choices.includes(scalerMethod);
|
| 320 |
+
if(containUpscaler){
|
| 321 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_hr_upscaler')[0].props.value = this.metadata['Hires upscaler'];
|
| 322 |
+
const hr_span = gradioApp().querySelector( '#txt2img_hr_upscaler' ).getElementsByTagName('span');
|
| 323 |
+
hr_span[0].textContent = this.metadata['Hires upscaler'];
|
| 324 |
+
|
| 325 |
+
const cfgScaleList = gradioApp().querySelector( '#txt2img_enable_hr' ).getElementsByTagName('input');
|
| 326 |
+
if(cfgScaleList&&cfgScaleList.length> 1){
|
| 327 |
+
cfgScaleList[0].value = this.metadata['cfg_scale'];
|
| 328 |
+
cfgScaleList[1].value = this.metadata['cfg_scale'];
|
| 329 |
+
}
|
| 330 |
+
}
|
| 331 |
+
try{
|
| 332 |
+
try{
|
| 333 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_hires_steps')[0].props.value = parseInt(this.metadata['Hires steps']);
|
| 334 |
+
}catch(e){
|
| 335 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_hires_steps')[0].props.value = 0;
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
const cfgScaleList = gradioApp().querySelector( '#txt2img_hires_steps' ).getElementsByTagName('input');
|
| 339 |
+
if(cfgScaleList&&cfgScaleList.length> 1){
|
| 340 |
+
cfgScaleList[0].value = this.metadata['Hires steps'];
|
| 341 |
+
cfgScaleList[1].value = this.metadata['Hires steps'];
|
| 342 |
+
}
|
| 343 |
+
}catch(e){
|
| 344 |
+
console.log(e);
|
| 345 |
+
console.log('errorhr0');
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
try{
|
| 349 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_hr_scale')[0].props.value = this.metadata['Hires upscale'];
|
| 350 |
+
const cfgScaleList = gradioApp().querySelector( '#txt2img_hr_scale' ).getElementsByTagName('input');
|
| 351 |
+
if(cfgScaleList&&cfgScaleList.length> 1){
|
| 352 |
+
cfgScaleList[0].value = this.metadata['Hires upscale'];
|
| 353 |
+
cfgScaleList[1].value = this.metadata['Hires upscale'];
|
| 354 |
+
}
|
| 355 |
+
}catch(e){
|
| 356 |
+
console.log(e);
|
| 357 |
+
console.log('errorhr');
|
| 358 |
+
}
|
| 359 |
+
try{
|
| 360 |
+
let hiresValue = parseInt(this.metadata['Hires resize-1']);
|
| 361 |
+
if(hiresValue == 0){
|
| 362 |
+
hiresValue = parseInt(this.metadata['Size-1']);
|
| 363 |
+
}
|
| 364 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_hr_resize_x')[0].props.value = hiresValue;
|
| 365 |
+
const cfgScaleList = gradioApp().querySelector( '#txt2img_hr_resize_x' ).getElementsByTagName('input');
|
| 366 |
+
if(cfgScaleList&&cfgScaleList.length> 1){
|
| 367 |
+
cfgScaleList[0].value = this.metadata['Hires resize-1'];
|
| 368 |
+
cfgScaleList[1].value = this.metadata['Hires resize-1'];
|
| 369 |
+
}
|
| 370 |
+
}catch(e){
|
| 371 |
+
console.log(e);
|
| 372 |
+
console.log('errorhr2');
|
| 373 |
+
}
|
| 374 |
+
try{
|
| 375 |
+
let hiresValueSecond = parseInt(this.metadata['Hires resize-2']);
|
| 376 |
+
if(hiresValueSecond == 0){
|
| 377 |
+
hiresValueSecond = parseInt(this.metadata['Size-2']);
|
| 378 |
+
}
|
| 379 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_hr_resize_y')[0].props.value = hiresValueSecond;
|
| 380 |
+
const cfgScaleList = gradioApp().querySelector( '#txt2img_hr_resize_y' ).getElementsByTagName('input');
|
| 381 |
+
if(cfgScaleList&&cfgScaleList.length> 1){
|
| 382 |
+
cfgScaleList[0].value = this.metadata['Hires resize-2'];
|
| 383 |
+
cfgScaleList[1].value = this.metadata['Hires resize-2'];
|
| 384 |
+
}
|
| 385 |
+
}catch(e){
|
| 386 |
+
console.log(e);
|
| 387 |
+
console.log('errorhr3');
|
| 388 |
+
}
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
}catch(e){
|
| 393 |
+
console.log(e);
|
| 394 |
+
console.log('errorhr4');
|
| 395 |
+
}
|
| 396 |
+
this.close();
|
| 397 |
+
},
|
| 398 |
+
sendToImageToImage(){
|
| 399 |
+
const userId = localStorage.getItem("userId");
|
| 400 |
+
const imageId = this.imageId;
|
| 401 |
+
const token = localStorage.getItem("token");
|
| 402 |
+
const headers={"Authorization":"Token " + token};
|
| 403 |
+
axios.post(
|
| 404 |
+
'https://newtypev3-server-vjiloyvjvq-an.a.run.app/image/send_to',
|
| 405 |
+
{
|
| 406 |
+
userId,
|
| 407 |
+
imageId,
|
| 408 |
+
sendType: "SEND_TO_IMAGE",
|
| 409 |
+
},
|
| 410 |
+
{
|
| 411 |
+
headers
|
| 412 |
+
}
|
| 413 |
+
)
|
| 414 |
+
.then(response => {
|
| 415 |
+
var xhr = new XMLHttpRequest();
|
| 416 |
+
var self = this;
|
| 417 |
+
xhr.onload = function() {
|
| 418 |
+
var reader = new FileReader();
|
| 419 |
+
reader.onloadend = function() {
|
| 420 |
+
self.sendToImageToImageProcess(reader.result);
|
| 421 |
+
}
|
| 422 |
+
reader.readAsDataURL(xhr.response);
|
| 423 |
+
};
|
| 424 |
+
xhr.open('GET', this.src);
|
| 425 |
+
xhr.responseType = 'blob';
|
| 426 |
+
xhr.send();
|
| 427 |
+
this.currentItem.total_sendto = this.currentItem.total_sendto + 1;
|
| 428 |
+
|
| 429 |
+
}).catch(error => {
|
| 430 |
+
this.loading = false;
|
| 431 |
+
console.log(error)
|
| 432 |
+
})
|
| 433 |
+
},
|
| 434 |
+
sendToImageToImageProcess(date64Image){
|
| 435 |
+
try{
|
| 436 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='img2img_image')[0].props.value = date64Image;
|
| 437 |
+
}catch(e){
|
| 438 |
+
|
| 439 |
+
}
|
| 440 |
+
try{
|
| 441 |
+
const textPrompt = gradioApp().querySelector('#img2img_prompt').getElementsByTagName( 'textarea' );
|
| 442 |
+
if(textPrompt&&textPrompt.length> 0){
|
| 443 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='img2img_prompt')[0].props.value = this.metadata.prompt;
|
| 444 |
+
textPrompt[0].value = this.metadata.prompt;
|
| 445 |
+
}
|
| 446 |
+
}catch(e){
|
| 447 |
+
console.log('Error prompt img2img');
|
| 448 |
+
console.log(e);
|
| 449 |
+
|
| 450 |
+
}
|
| 451 |
+
try{
|
| 452 |
+
const negativePrompt = gradioApp().querySelector('#img2img_neg_prompt').getElementsByTagName( 'textarea' );
|
| 453 |
+
if(negativePrompt&&negativePrompt.length> 0){
|
| 454 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='img2img_neg_prompt')[0].props.value = this.metadata.negative_prompt;
|
| 455 |
+
negativePrompt[0].value = this.metadata.negative_prompt;
|
| 456 |
+
}
|
| 457 |
+
}catch(e){
|
| 458 |
+
console.log('Error neg img2img');
|
| 459 |
+
console.log(e);
|
| 460 |
+
|
| 461 |
+
}
|
| 462 |
+
|
| 463 |
+
|
| 464 |
+
try{
|
| 465 |
+
const samplerList = gradioApp().querySelector( '#img2img_sampling' ).getElementsByTagName('span');
|
| 466 |
+
if(samplerList&&samplerList.length> 1){
|
| 467 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='img2img_sampling')[0].props.value = this.metadata.sampler;
|
| 468 |
+
samplerList[1].textContent = this.metadata.sampler;
|
| 469 |
+
}
|
| 470 |
+
}catch(e){
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
try{
|
| 474 |
+
const textImageStepsList = gradioApp().querySelector( '#img2img_steps' ).getElementsByTagName('input');
|
| 475 |
+
if(textImageStepsList&&textImageStepsList.length> 1){
|
| 476 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='img2img_steps')[0].props.value = parseInt(this.metadata.n_iter);
|
| 477 |
+
textImageStepsList[0].value = this.metadata.n_iter;
|
| 478 |
+
textImageStepsList[1].value = this.metadata.n_iter;
|
| 479 |
+
}
|
| 480 |
+
}catch(e){
|
| 481 |
+
console.log('Error steps img2img');
|
| 482 |
+
console.log(e);
|
| 483 |
+
|
| 484 |
+
}
|
| 485 |
+
try{
|
| 486 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='img2img_width')[0].props.value = parseInt(this.metadata['Size-1']);
|
| 487 |
+
const textWidthList = gradioApp().querySelector( '#img2img_width' ).getElementsByTagName('input');
|
| 488 |
+
if(textWidthList&&textWidthList.length> 1){
|
| 489 |
+
textWidthList[0].value = this.metadata['Size-1'];
|
| 490 |
+
textWidthList[1].value = this.metadata['Size-1'];
|
| 491 |
+
}
|
| 492 |
+
}catch(e){
|
| 493 |
+
console.log('Error width img2img');
|
| 494 |
+
console.log(e);
|
| 495 |
+
}
|
| 496 |
+
try{
|
| 497 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='img2img_height')[0].props.value = parseInt(this.metadata['Size-2']);
|
| 498 |
+
const textWidthList = gradioApp().querySelector( '#img2img_height' ).getElementsByTagName('input');
|
| 499 |
+
if(textWidthList&&textWidthList.length> 1){
|
| 500 |
+
textWidthList[0].value = this.metadata['Size-2'];
|
| 501 |
+
textWidthList[1].value = this.metadata['Size-2'];
|
| 502 |
+
}
|
| 503 |
+
}catch(e){
|
| 504 |
+
console.log('Error width height2img');
|
| 505 |
+
console.log(e);
|
| 506 |
+
}
|
| 507 |
+
this.close();
|
| 508 |
+
switch_to_img2img();
|
| 509 |
+
},
|
| 510 |
+
addToWishList(item){
|
| 511 |
+
const userId = localStorage.getItem("userId");
|
| 512 |
+
const token = localStorage.getItem("token");
|
| 513 |
+
const headers={"Authorization":"Token " + token};
|
| 514 |
+
item.liked = true;
|
| 515 |
+
item.likecount = item.likecount + 1;
|
| 516 |
+
axios.post(
|
| 517 |
+
`https://newtypev3-server-vjiloyvjvq-an.a.run.app/image/like`,
|
| 518 |
+
{
|
| 519 |
+
userId,
|
| 520 |
+
imageId: item.id,
|
| 521 |
+
},
|
| 522 |
+
{
|
| 523 |
+
headers
|
| 524 |
+
}
|
| 525 |
+
)
|
| 526 |
+
},
|
| 527 |
+
handleTextareaInput(event) {
|
| 528 |
+
let textarea = event.target;
|
| 529 |
+
textarea.style.height = 'auto';
|
| 530 |
+
textarea.style.height = (textarea.scrollHeight) + 'px';
|
| 531 |
+
comment = event.target.text;
|
| 532 |
+
},
|
| 533 |
+
deleteWishList(item){
|
| 534 |
+
console.log('delete');
|
| 535 |
+
const userId = localStorage.getItem("userId");
|
| 536 |
+
item.liked = false;
|
| 537 |
+
item.likecount = item.likecount -1 ;
|
| 538 |
+
const token = localStorage.getItem("token");
|
| 539 |
+
const headers={"Authorization":"Token " + token};
|
| 540 |
+
axios.delete(
|
| 541 |
+
`https://newtypev3-server-vjiloyvjvq-an.a.run.app/image/like`,
|
| 542 |
+
{
|
| 543 |
+
data: {
|
| 544 |
+
userId,
|
| 545 |
+
imageId: item.id,
|
| 546 |
+
},
|
| 547 |
+
headers
|
| 548 |
+
},
|
| 549 |
+
)
|
| 550 |
+
},
|
| 551 |
+
makeSaveButtonVisible(){
|
| 552 |
+
this.showCommentWrite = true;
|
| 553 |
+
},
|
| 554 |
+
hideSaveButtonVisible(){
|
| 555 |
+
this.comment = '';
|
| 556 |
+
this.showCommentWrite = false;
|
| 557 |
+
const textArea = gradioApp().querySelector("#modal-writer-type");
|
| 558 |
+
textArea.style.height = 'auto';
|
| 559 |
+
textArea.style.height = (textarea.scrollHeight) + 'px';
|
| 560 |
+
},
|
| 561 |
+
writeComment(){
|
| 562 |
+
if(this.comment.length > 0){
|
| 563 |
+
const userId = localStorage.getItem("userId");
|
| 564 |
+
const token = localStorage.getItem("token");
|
| 565 |
+
const headers={"Authorization":"Token " + token};
|
| 566 |
+
axios.post(
|
| 567 |
+
`https://newtypev3-server-vjiloyvjvq-an.a.run.app/image/comment`,
|
| 568 |
+
{
|
| 569 |
+
userId,
|
| 570 |
+
imageId: this.currentItem.id,
|
| 571 |
+
text: this.comment,
|
| 572 |
+
},
|
| 573 |
+
{
|
| 574 |
+
headers
|
| 575 |
+
}
|
| 576 |
+
).then((res)=>{
|
| 577 |
+
this.fetchComments();
|
| 578 |
+
this.showCommentWrite = false;
|
| 579 |
+
this.comment = '';
|
| 580 |
+
this.currentItem.total_comments = this.currentItem.total_comments + 1;
|
| 581 |
+
}).catch((e)=>{
|
| 582 |
+
console.log(e);
|
| 583 |
+
});
|
| 584 |
+
|
| 585 |
+
}else{
|
| 586 |
+
return false;
|
| 587 |
+
}
|
| 588 |
+
},
|
| 589 |
+
fetchComments(){
|
| 590 |
+
var self = this;
|
| 591 |
+
const token = localStorage.getItem("token");
|
| 592 |
+
const headers={"Authorization":"Token " + token};
|
| 593 |
+
axios.get(
|
| 594 |
+
`https://newtypev3-server-vjiloyvjvq-an.a.run.app/image/comments/${this.currentItem.id}`,
|
| 595 |
+
{
|
| 596 |
+
headers
|
| 597 |
+
}
|
| 598 |
+
).then((res)=>{
|
| 599 |
+
self.comments = res.data;
|
| 600 |
+
}).catch((e)=>{
|
| 601 |
+
console.log(e);
|
| 602 |
+
})
|
| 603 |
+
},
|
| 604 |
+
},
|
| 605 |
+
computed:{
|
| 606 |
+
isModalOpen(){
|
| 607 |
+
return this.showModal;
|
| 608 |
+
},
|
| 609 |
+
},
|
| 610 |
+
created() {
|
| 611 |
+
const userId = localStorage.getItem("userId");
|
| 612 |
+
const token = localStorage.getItem("token");
|
| 613 |
+
const headers={"Authorization":"Token " + token};
|
| 614 |
+
axios.get(
|
| 615 |
+
`https://newtypev3-server-vjiloyvjvq-an.a.run.app/image/best/${userId}`,
|
| 616 |
+
{
|
| 617 |
+
headers
|
| 618 |
+
}
|
| 619 |
+
)
|
| 620 |
+
.then(response => {
|
| 621 |
+
const dataObject = response.data;
|
| 622 |
+
this.userId = userId;
|
| 623 |
+
this.bestFeeds = dataObject.slice(0, 4);
|
| 624 |
+
}).catch(error => {
|
| 625 |
+
this.loading = false;
|
| 626 |
+
console.log(error)
|
| 627 |
+
})
|
| 628 |
+
},
|
| 629 |
+
};
|
| 630 |
+
const fetchApp = Vue.createApp(userModel);
|
| 631 |
+
if (document.querySelector("#best-product-tab") != null) {
|
| 632 |
+
fetchApp.mount('#best-product-tab');
|
| 633 |
+
}else{
|
| 634 |
+
fetchApp.mount(document.getElementsByTagName("gradio-app")[0].shadowRoot.getElementById("best-product-tab"));
|
| 635 |
+
}
|
| 636 |
+
console.log('mount success');
|
| 637 |
+
},1000,9000);
|
| 638 |
+
|
sd_feed/javascript/goosviewmodel.js
ADDED
|
@@ -0,0 +1,860 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
var installLoaded = {};
|
| 2 |
+
function addScript(url) {
|
| 3 |
+
if (!installLoaded[url]) {
|
| 4 |
+
var s = document.createElement('script');
|
| 5 |
+
s.src = url;
|
| 6 |
+
document.head.appendChild(s);
|
| 7 |
+
installLoaded[url] = true;
|
| 8 |
+
}
|
| 9 |
+
}
|
| 10 |
+
function waitForElementToDisplay(selector, callback, checkFrequencyInMs, timeoutInMs) {
|
| 11 |
+
(function loopSearch() {
|
| 12 |
+
if (document.querySelector(selector) != null&& window.localStorage.getItem("userId")) {
|
| 13 |
+
callback();
|
| 14 |
+
return;
|
| 15 |
+
}
|
| 16 |
+
else if(document.getElementsByTagName("gradio-app").length > 0 &&
|
| 17 |
+
document.getElementsByTagName("gradio-app")[0].shadowRoot){
|
| 18 |
+
callback();
|
| 19 |
+
return;
|
| 20 |
+
}
|
| 21 |
+
else {
|
| 22 |
+
setTimeout(function () {
|
| 23 |
+
loopSearch();
|
| 24 |
+
}, checkFrequencyInMs);
|
| 25 |
+
}
|
| 26 |
+
})();
|
| 27 |
+
}
|
| 28 |
+
const reorderData=(arr, columns)=>{
|
| 29 |
+
const cols = columns;
|
| 30 |
+
const out = [];
|
| 31 |
+
let col = 0;
|
| 32 |
+
while(col < cols) {
|
| 33 |
+
for(let i = 0; i < arr.length; i += cols) {
|
| 34 |
+
let _val = arr[i + col];
|
| 35 |
+
if (_val !== undefined)
|
| 36 |
+
out.push(_val);
|
| 37 |
+
}
|
| 38 |
+
col++;
|
| 39 |
+
}
|
| 40 |
+
return out;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
// addScript('https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js');
|
| 44 |
+
// addScript('https://unpkg.com/vue@3.2.6/dist/vue.global.prod.js');
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
waitForElementToDisplay(
|
| 48 |
+
"#html_id",
|
| 49 |
+
function(){
|
| 50 |
+
async function copyToClipboard(textToCopy) {
|
| 51 |
+
// Navigator clipboard api needs a secure context (https)
|
| 52 |
+
if (navigator.clipboard && window.isSecureContext) {
|
| 53 |
+
await navigator.clipboard.writeText(textToCopy);
|
| 54 |
+
} else {
|
| 55 |
+
// Use the 'out of viewport hidden text area' trick
|
| 56 |
+
const textArea = document.createElement("textarea");
|
| 57 |
+
textArea.value = textToCopy;
|
| 58 |
+
|
| 59 |
+
// Move textarea out of the viewport so it's not visible
|
| 60 |
+
textArea.style.position = "absolute";
|
| 61 |
+
textArea.style.left = "-999999px";
|
| 62 |
+
|
| 63 |
+
document.body.prepend(textArea);
|
| 64 |
+
textArea.select();
|
| 65 |
+
|
| 66 |
+
try {
|
| 67 |
+
document.execCommand('copy');
|
| 68 |
+
} catch (error) {
|
| 69 |
+
console.error(error);
|
| 70 |
+
} finally {
|
| 71 |
+
textArea.remove();
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
};
|
| 75 |
+
const imageModel = {
|
| 76 |
+
data() {
|
| 77 |
+
return {
|
| 78 |
+
page: 1,
|
| 79 |
+
loading: false,
|
| 80 |
+
uploadLoading: false,
|
| 81 |
+
imageList: [],
|
| 82 |
+
sortedDataList: [],
|
| 83 |
+
carouselBtnTop: 150,
|
| 84 |
+
showCommentWrite: false,
|
| 85 |
+
modeSelectList: [
|
| 86 |
+
{ name: "Newest", value: "latest" },
|
| 87 |
+
{ name: "Popular", value: "likes" },
|
| 88 |
+
{ name: "Favorite", value: "favorite" },
|
| 89 |
+
{ name: "My Feed", value: "private" },
|
| 90 |
+
],
|
| 91 |
+
mode: "latest",
|
| 92 |
+
prompt: "",
|
| 93 |
+
showModal: false,
|
| 94 |
+
metadata: {},
|
| 95 |
+
filterNsfw: false,
|
| 96 |
+
animeTag: false,
|
| 97 |
+
realTag: false,
|
| 98 |
+
nickname: '',
|
| 99 |
+
profile: '',
|
| 100 |
+
editMode: false,
|
| 101 |
+
userId: '',
|
| 102 |
+
searchNickname: "",
|
| 103 |
+
searchProfile: "",
|
| 104 |
+
}
|
| 105 |
+
},
|
| 106 |
+
computed: {
|
| 107 |
+
parsedProfile(){
|
| 108 |
+
if(!this.profile){
|
| 109 |
+
return this.profile;
|
| 110 |
+
}
|
| 111 |
+
return this.profile.replaceAll("\n", "<br/>");
|
| 112 |
+
},
|
| 113 |
+
parsedSearchProfile(){
|
| 114 |
+
if(!this.searchProfile){
|
| 115 |
+
return '';
|
| 116 |
+
}
|
| 117 |
+
return this.searchProfile.replaceAll("\n", "<br/>");
|
| 118 |
+
}
|
| 119 |
+
},
|
| 120 |
+
watch: {
|
| 121 |
+
showModal() {
|
| 122 |
+
if (this.showModal === false) {
|
| 123 |
+
window.removeEventListener("keyup", this.onEscapeKey);
|
| 124 |
+
} else {
|
| 125 |
+
window.addEventListener("keyup", this.onEscapeKey);
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
},
|
| 129 |
+
methods: {
|
| 130 |
+
setEditMode(){
|
| 131 |
+
this.editMode = !this.editMode;
|
| 132 |
+
},
|
| 133 |
+
setNicknameSearch(){
|
| 134 |
+
this.mode = 'nicknameSearch';
|
| 135 |
+
const feedUserButton = gradioApp().querySelector('#feed-user-tab');
|
| 136 |
+
const nickname = feedUserButton.getAttribute("data-value");
|
| 137 |
+
this.searchNickname = nickname;
|
| 138 |
+
this.fetchSearchProfile();
|
| 139 |
+
this.fetchNewImage();
|
| 140 |
+
},
|
| 141 |
+
moveFeedProfileTab(nickname){
|
| 142 |
+
if(nickname){
|
| 143 |
+
this.close();
|
| 144 |
+
const buttonList = gradioApp().querySelector('#tabs').querySelectorAll('button');
|
| 145 |
+
for (step = 0; step < buttonList.length; step++) {
|
| 146 |
+
// Runs 5 times, with values of step 0 through 4.
|
| 147 |
+
if(buttonList[step].textContent.trim() == 'Feed'){
|
| 148 |
+
buttonList[step].click();
|
| 149 |
+
break;
|
| 150 |
+
}
|
| 151 |
+
}
|
| 152 |
+
try{
|
| 153 |
+
const feedUserButton = gradioApp().querySelector('#feed-user-tab');
|
| 154 |
+
feedUserButton.setAttribute("data-value", nickname);
|
| 155 |
+
feedUserButton.innerHTML = nickname;
|
| 156 |
+
feedUserButton.click();
|
| 157 |
+
|
| 158 |
+
}catch(e){
|
| 159 |
+
console.log(e);
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
},
|
| 165 |
+
saveNickname(){
|
| 166 |
+
const userId = localStorage.getItem("userId");
|
| 167 |
+
const token = localStorage.getItem("token");
|
| 168 |
+
const headers={"Authorization":"Token " + token};
|
| 169 |
+
axios.post(
|
| 170 |
+
`https://newtypev3-server-vjiloyvjvq-an.a.run.app/user/profile`,
|
| 171 |
+
{
|
| 172 |
+
userId,
|
| 173 |
+
nickname: this.nickname,
|
| 174 |
+
profile: this.profile,
|
| 175 |
+
},
|
| 176 |
+
{
|
| 177 |
+
headers
|
| 178 |
+
}
|
| 179 |
+
)
|
| 180 |
+
.then(response => {
|
| 181 |
+
this.editMode = false;
|
| 182 |
+
})
|
| 183 |
+
.catch(error => {
|
| 184 |
+
this.loading = false;
|
| 185 |
+
alert(error.response.data.detail);
|
| 186 |
+
})
|
| 187 |
+
},
|
| 188 |
+
selectAnimeTag(){
|
| 189 |
+
if(this.animeTag == false){
|
| 190 |
+
this.animeTag = true;
|
| 191 |
+
this.realTag = false;
|
| 192 |
+
}else{
|
| 193 |
+
this.animeTag = false;
|
| 194 |
+
this.realTag = false;
|
| 195 |
+
}
|
| 196 |
+
this.fetchNewImage();
|
| 197 |
+
},
|
| 198 |
+
selectRealTag(){
|
| 199 |
+
if(this.realTag == false){
|
| 200 |
+
this.realTag = true;
|
| 201 |
+
this.animeTag = false;
|
| 202 |
+
}else{
|
| 203 |
+
this.realTag = false;
|
| 204 |
+
this.animeTag = false;
|
| 205 |
+
}
|
| 206 |
+
this.fetchNewImage();
|
| 207 |
+
},
|
| 208 |
+
async uploadImage(event){
|
| 209 |
+
this.uploadLoading = true;
|
| 210 |
+
const files = event.target.files;
|
| 211 |
+
const userId = localStorage.getItem("userId");
|
| 212 |
+
for (let i=0; i<files.length; i++) {
|
| 213 |
+
if(!files[i].type.match(/^image\//)){
|
| 214 |
+
alert('이미지 파일만 업로드할 수 있습니다.');
|
| 215 |
+
} else if(files[i].size > 50000000) {
|
| 216 |
+
alert('You cannot upload file larger than 50MB');
|
| 217 |
+
} else {
|
| 218 |
+
var body = new FormData();
|
| 219 |
+
body.append('upload_file',files[i]);
|
| 220 |
+
body.append('userId', userId);
|
| 221 |
+
body.append('extractMetadata', true);
|
| 222 |
+
const token = localStorage.getItem("token");
|
| 223 |
+
const headers={"Authorization":"Token " + token};
|
| 224 |
+
try{
|
| 225 |
+
await axios({
|
| 226 |
+
url: 'https://newtypev3-server-vjiloyvjvq-an.a.run.app/image/image',
|
| 227 |
+
method: 'post',
|
| 228 |
+
withCredentials:true,
|
| 229 |
+
data: body,
|
| 230 |
+
headers
|
| 231 |
+
});
|
| 232 |
+
}catch(e){
|
| 233 |
+
console.log(e);
|
| 234 |
+
}
|
| 235 |
+
}
|
| 236 |
+
}
|
| 237 |
+
this.setMode('private');
|
| 238 |
+
this.uploadLoading = false;
|
| 239 |
+
},
|
| 240 |
+
close() {
|
| 241 |
+
this.$emit('close');
|
| 242 |
+
this.showModal=false;
|
| 243 |
+
this.imageId = "";
|
| 244 |
+
this.src = "";
|
| 245 |
+
this.comment = '';
|
| 246 |
+
this.comments = [];
|
| 247 |
+
},
|
| 248 |
+
closeOutsideModal(event) {
|
| 249 |
+
if(!event.target.closest('.prompt-modal-image-tag')){
|
| 250 |
+
this.$emit('close');
|
| 251 |
+
this.showModal=false;
|
| 252 |
+
this.imageId = "";
|
| 253 |
+
this.src = "";
|
| 254 |
+
this.comment = '';
|
| 255 |
+
this.comments = [];
|
| 256 |
+
}
|
| 257 |
+
},
|
| 258 |
+
onEscapeKey(event) {
|
| 259 |
+
if (event.keyCode === 27 || event.key === 'Escape') {
|
| 260 |
+
// Perform action when "Esc" key is pressed
|
| 261 |
+
this.close();
|
| 262 |
+
}
|
| 263 |
+
// Perform action when "Esc" key is pressed
|
| 264 |
+
},
|
| 265 |
+
formatNumber(num) {
|
| 266 |
+
if (num >= 1000000) {
|
| 267 |
+
return (num / 1000000).toFixed(1) + 'm';
|
| 268 |
+
} else if (num >= 1000) {
|
| 269 |
+
return (num / 1000).toFixed(1) + 'k';
|
| 270 |
+
} else {
|
| 271 |
+
return num.toString();
|
| 272 |
+
}
|
| 273 |
+
},
|
| 274 |
+
openModal(item){
|
| 275 |
+
this.showModal = true;
|
| 276 |
+
this.currentItem = item;
|
| 277 |
+
this.metadata = item.metadata;
|
| 278 |
+
this.src = item.url;
|
| 279 |
+
this.imageId = item.id;
|
| 280 |
+
item.total_clicks += 1;
|
| 281 |
+
this.addImageClick();
|
| 282 |
+
this.fetchComments();
|
| 283 |
+
},
|
| 284 |
+
addImageClick(){
|
| 285 |
+
const userId = localStorage.getItem("userId");
|
| 286 |
+
const imageId = this.imageId;
|
| 287 |
+
const token = localStorage.getItem("token");
|
| 288 |
+
const headers={"Authorization":"Token " + token};
|
| 289 |
+
axios.post(
|
| 290 |
+
'https://newtypev3-server-vjiloyvjvq-an.a.run.app/image/click',
|
| 291 |
+
{
|
| 292 |
+
userId,
|
| 293 |
+
imageId,
|
| 294 |
+
},
|
| 295 |
+
{
|
| 296 |
+
headers
|
| 297 |
+
}
|
| 298 |
+
)
|
| 299 |
+
.then(response => {
|
| 300 |
+
|
| 301 |
+
}).catch(error => {
|
| 302 |
+
this.loading = false;
|
| 303 |
+
console.log(error)
|
| 304 |
+
})
|
| 305 |
+
},
|
| 306 |
+
sendToTextToImage(){
|
| 307 |
+
const userId = localStorage.getItem("userId");
|
| 308 |
+
const imageId = this.imageId;
|
| 309 |
+
const token = localStorage.getItem("token");
|
| 310 |
+
const headers={"Authorization":"Token " + token};
|
| 311 |
+
this.currentItem.total_sendto = this.currentItem.total_sendto + 1;
|
| 312 |
+
axios.post(
|
| 313 |
+
'https://newtypev3-server-vjiloyvjvq-an.a.run.app/image/send_to',
|
| 314 |
+
{
|
| 315 |
+
userId,
|
| 316 |
+
imageId,
|
| 317 |
+
sendType: "SEND_TO_TEXT",
|
| 318 |
+
},{
|
| 319 |
+
headers
|
| 320 |
+
}
|
| 321 |
+
)
|
| 322 |
+
.then(response => {
|
| 323 |
+
this.sendToTextProcess();
|
| 324 |
+
}).catch(error => {
|
| 325 |
+
this.loading = false;
|
| 326 |
+
console.log(error)
|
| 327 |
+
})
|
| 328 |
+
},
|
| 329 |
+
copyClipboard(){
|
| 330 |
+
const userId = localStorage.getItem("userId");
|
| 331 |
+
const imageId = this.imageId;
|
| 332 |
+
const token = localStorage.getItem("token");
|
| 333 |
+
const headers={"Authorization":"Token " + token};
|
| 334 |
+
axios.post(
|
| 335 |
+
'https://newtypev3-server-vjiloyvjvq-an.a.run.app/image/send_to',
|
| 336 |
+
{
|
| 337 |
+
userId,
|
| 338 |
+
imageId,
|
| 339 |
+
sendType: "COPY_TO_CLIPBOARD",
|
| 340 |
+
},{
|
| 341 |
+
headers
|
| 342 |
+
}
|
| 343 |
+
)
|
| 344 |
+
.then(response => {
|
| 345 |
+
let filteredObject = '';
|
| 346 |
+
for (const [k, v] of Object.entries(this.metadata)) {
|
| 347 |
+
if (/^[A-Z]/.test(k)) {
|
| 348 |
+
filteredObject += `${k}:${v},`;
|
| 349 |
+
}
|
| 350 |
+
}
|
| 351 |
+
this.currentItem.total_sendto = this.currentItem.total_sendto + 1;
|
| 352 |
+
copyToClipboard(filteredObject);
|
| 353 |
+
}).catch(error => {
|
| 354 |
+
this.loading = false;
|
| 355 |
+
console.log(error)
|
| 356 |
+
});
|
| 357 |
+
|
| 358 |
+
},
|
| 359 |
+
sendToTextProcess(){
|
| 360 |
+
const textPrompt = gradioApp().querySelector('#txt2img_prompt').getElementsByTagName( 'textarea' );
|
| 361 |
+
if(textPrompt&&textPrompt.length> 0){
|
| 362 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_prompt')[0].props.value = this.metadata.prompt;
|
| 363 |
+
textPrompt[0].value = this.metadata.prompt;
|
| 364 |
+
}
|
| 365 |
+
const negativePrompt = gradioApp().querySelector('#txt2img_neg_prompt').getElementsByTagName( 'textarea' );
|
| 366 |
+
if(negativePrompt&&negativePrompt.length> 0){
|
| 367 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_neg_prompt')[0].props.value = this.metadata.negative_prompt;
|
| 368 |
+
negativePrompt[0].value = this.metadata.negative_prompt;
|
| 369 |
+
}
|
| 370 |
+
try{
|
| 371 |
+
const samplerList = gradioApp().querySelector( '#txt2img_sampling' ).getElementsByTagName('span');
|
| 372 |
+
if(samplerList&&samplerList.length> 1){
|
| 373 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_sampling')[0].props.value = this.metadata.sampler;
|
| 374 |
+
samplerList[1].textContent = this.metadata.sampler;
|
| 375 |
+
}
|
| 376 |
+
}catch(e){
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
try{
|
| 380 |
+
const textImageStepsList = gradioApp().querySelector( '#txt2img_steps' ).getElementsByTagName('input');
|
| 381 |
+
if(textImageStepsList&&textImageStepsList.length> 1){
|
| 382 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_steps')[0].props.value = parseInt(this.metadata.n_iter);
|
| 383 |
+
textImageStepsList[0].value = this.metadata.n_iter;
|
| 384 |
+
textImageStepsList[1].value = this.metadata.n_iter;
|
| 385 |
+
}
|
| 386 |
+
}catch(e){
|
| 387 |
+
}
|
| 388 |
+
try{
|
| 389 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_width')[0].props.value = parseFloat(this.metadata['Size-1']);
|
| 390 |
+
const textWidthList = gradioApp().querySelector( '#txt2img_width' ).getElementsByTagName('input');
|
| 391 |
+
if(textWidthList&&textWidthList.length> 1){
|
| 392 |
+
textWidthList[0].value = this.metadata['Size-1'];
|
| 393 |
+
textWidthList[1].value = this.metadata['Size-1'];
|
| 394 |
+
}
|
| 395 |
+
}catch(e){
|
| 396 |
+
}
|
| 397 |
+
try{
|
| 398 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_height')[0].props.value = parseFloat(this.metadata['Size-2']);
|
| 399 |
+
const textWidthList = gradioApp().querySelector( '#txt2img_height' ).getElementsByTagName('input');
|
| 400 |
+
if(textWidthList&&textWidthList.length> 1){
|
| 401 |
+
textWidthList[0].value = this.metadata['Size-2'];
|
| 402 |
+
textWidthList[1].value = this.metadata['Size-2'];
|
| 403 |
+
}
|
| 404 |
+
}catch(e){
|
| 405 |
+
}
|
| 406 |
+
try{
|
| 407 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_cfg_scale')[0].props.value = parseFloat(this.metadata['cfg_scale']);
|
| 408 |
+
const cfgScaleList = gradioApp().querySelector( '#txt2img_cfg_scale' ).getElementsByTagName('input');
|
| 409 |
+
if(cfgScaleList&&cfgScaleList.length> 1){
|
| 410 |
+
cfgScaleList[0].value = this.metadata['cfg_scale'];
|
| 411 |
+
cfgScaleList[1].value = this.metadata['cfg_scale'];
|
| 412 |
+
}
|
| 413 |
+
}catch(e){
|
| 414 |
+
}
|
| 415 |
+
try{
|
| 416 |
+
const steps = this.metadata['Hires upscaler'];
|
| 417 |
+
if(steps){
|
| 418 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_enable_hr')[0].props.value = true;
|
| 419 |
+
gradioApp().querySelector( '#txt2img_enable_hr' ).getElementsByTagName('input')[0].checked = true;
|
| 420 |
+
try{
|
| 421 |
+
const originalHires = gradioApp().querySelector( '#txt2img_hires_fix' );
|
| 422 |
+
originalHires.classList.remove('hidden');
|
| 423 |
+
}catch(e){
|
| 424 |
+
|
| 425 |
+
}
|
| 426 |
+
const scalerMethod = this.metadata['Hires upscaler'];
|
| 427 |
+
const containUpscaler = window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_hr_upscaler')[0].props.choices.includes(scalerMethod);
|
| 428 |
+
if(containUpscaler){
|
| 429 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_hr_upscaler')[0].props.value = this.metadata['Hires upscaler'];
|
| 430 |
+
const hr_span = gradioApp().querySelector( '#txt2img_hr_upscaler' ).getElementsByTagName('span');
|
| 431 |
+
hr_span[0].textContent = this.metadata['Hires upscaler'];
|
| 432 |
+
|
| 433 |
+
const cfgScaleList = gradioApp().querySelector( '#txt2img_enable_hr' ).getElementsByTagName('input');
|
| 434 |
+
if(cfgScaleList&&cfgScaleList.length> 1){
|
| 435 |
+
cfgScaleList[0].value = this.metadata['cfg_scale'];
|
| 436 |
+
cfgScaleList[1].value = this.metadata['cfg_scale'];
|
| 437 |
+
}
|
| 438 |
+
}
|
| 439 |
+
try{
|
| 440 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_hires_steps')[0].props.value = parseInt(this.metadata['Hires steps']);
|
| 441 |
+
const cfgScaleList = gradioApp().querySelector( '#txt2img_hires_steps' ).getElementsByTagName('input');
|
| 442 |
+
if(cfgScaleList&&cfgScaleList.length> 1){
|
| 443 |
+
cfgScaleList[0].value = this.metadata['Hires steps'];
|
| 444 |
+
cfgScaleList[1].value = this.metadata['Hires steps'];
|
| 445 |
+
}
|
| 446 |
+
}catch(e){
|
| 447 |
+
console.log(e);
|
| 448 |
+
console.log('errorhr0');
|
| 449 |
+
}
|
| 450 |
+
try{
|
| 451 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_hr_scale')[0].props.value = parseFloat(this.metadata['Hires upscale']);
|
| 452 |
+
const cfgScaleList = gradioApp().querySelector( '#txt2img_hr_scale' ).getElementsByTagName('input');
|
| 453 |
+
if(cfgScaleList&&cfgScaleList.length> 1){
|
| 454 |
+
cfgScaleList[0].value = this.metadata['Hires upscale'];
|
| 455 |
+
cfgScaleList[1].value = this.metadata['Hires upscale'];
|
| 456 |
+
}
|
| 457 |
+
}catch(e){
|
| 458 |
+
console.log(e);
|
| 459 |
+
console.log('errorhr');
|
| 460 |
+
}
|
| 461 |
+
try{
|
| 462 |
+
const hiresValue1 = parseInt(this.metadata['Hires resize-1']);
|
| 463 |
+
console.log(hiresValue1);
|
| 464 |
+
if(hiresValue1 && hiresValue1 > 0){
|
| 465 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_hr_resize_x')[0].props.value = parseInt(this.metadata['Hires resize-1']);
|
| 466 |
+
const cfgScaleList = gradioApp().querySelector( '#txt2img_hr_resize_x' ).getElementsByTagName('input');
|
| 467 |
+
if(cfgScaleList&&cfgScaleList.length> 1){
|
| 468 |
+
cfgScaleList[0].value = this.metadata['Hires resize-1'];
|
| 469 |
+
cfgScaleList[1].value = this.metadata['Hires resize-1'];
|
| 470 |
+
}
|
| 471 |
+
}
|
| 472 |
+
}catch(e){
|
| 473 |
+
console.log(e);
|
| 474 |
+
console.log('errorhr2');
|
| 475 |
+
}
|
| 476 |
+
try{
|
| 477 |
+
const hiresValue2 = parseInt(this.metadata['Hires resize-2']);
|
| 478 |
+
console.log(hiresValue2);
|
| 479 |
+
if(hiresValue2 > 0){
|
| 480 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='txt2img_hr_resize_y')[0].props.value = parseInt(this.metadata['Hires resize-2']);
|
| 481 |
+
const cfgScaleList = gradioApp().querySelector( '#txt2img_hr_resize_y' ).getElementsByTagName('input');
|
| 482 |
+
if(cfgScaleList&&cfgScaleList.length> 1){
|
| 483 |
+
cfgScaleList[0].value = this.metadata['Hires resize-2'];
|
| 484 |
+
cfgScaleList[1].value = this.metadata['Hires resize-2'];
|
| 485 |
+
}
|
| 486 |
+
}
|
| 487 |
+
}catch(e){
|
| 488 |
+
console.log(e);
|
| 489 |
+
console.log('errorhr3');
|
| 490 |
+
}
|
| 491 |
+
}
|
| 492 |
+
|
| 493 |
+
|
| 494 |
+
|
| 495 |
+
}catch(e){
|
| 496 |
+
console.log(e);
|
| 497 |
+
console.log('errorhr4');
|
| 498 |
+
}
|
| 499 |
+
this.close();
|
| 500 |
+
switch_to_txt2img();
|
| 501 |
+
},
|
| 502 |
+
sendToImageToImage(){
|
| 503 |
+
const userId = localStorage.getItem("userId");
|
| 504 |
+
const imageId = this.imageId;
|
| 505 |
+
const token = localStorage.getItem("token");
|
| 506 |
+
const headers={"Authorization":"Token " + token};
|
| 507 |
+
axios.post(
|
| 508 |
+
'https://newtypev3-server-vjiloyvjvq-an.a.run.app/image/send_to',
|
| 509 |
+
{
|
| 510 |
+
userId,
|
| 511 |
+
imageId,
|
| 512 |
+
sendType: "SEND_TO_IMAGE",
|
| 513 |
+
},{
|
| 514 |
+
headers
|
| 515 |
+
}
|
| 516 |
+
)
|
| 517 |
+
.then(response => {
|
| 518 |
+
var xhr = new XMLHttpRequest();
|
| 519 |
+
var self = this;
|
| 520 |
+
xhr.onload = function() {
|
| 521 |
+
var reader = new FileReader();
|
| 522 |
+
reader.onloadend = function() {
|
| 523 |
+
self.sendToImageToImageProcess(reader.result);
|
| 524 |
+
}
|
| 525 |
+
reader.readAsDataURL(xhr.response);
|
| 526 |
+
};
|
| 527 |
+
xhr.open('GET', this.src);
|
| 528 |
+
xhr.responseType = 'blob';
|
| 529 |
+
xhr.send();
|
| 530 |
+
this.currentItem.total_sendto = this.currentItem.total_sendto + 1;
|
| 531 |
+
|
| 532 |
+
}).catch(error => {
|
| 533 |
+
this.loading = false;
|
| 534 |
+
console.log(error)
|
| 535 |
+
})
|
| 536 |
+
},
|
| 537 |
+
sendToImageToImageProcess(date64Image){
|
| 538 |
+
try{
|
| 539 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='img2img_image')[0].props.value = date64Image;
|
| 540 |
+
}catch(e){
|
| 541 |
+
|
| 542 |
+
}
|
| 543 |
+
try{
|
| 544 |
+
const textPrompt = gradioApp().querySelector('#img2img_prompt').getElementsByTagName( 'textarea' );
|
| 545 |
+
if(textPrompt&&textPrompt.length> 0){
|
| 546 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='img2img_prompt')[0].props.value = this.metadata.prompt;
|
| 547 |
+
textPrompt[0].value = this.metadata.prompt;
|
| 548 |
+
}
|
| 549 |
+
}catch(e){
|
| 550 |
+
console.log('Error prompt img2img');
|
| 551 |
+
console.log(e);
|
| 552 |
+
|
| 553 |
+
}
|
| 554 |
+
try{
|
| 555 |
+
const negativePrompt = gradioApp().querySelector('#img2img_neg_prompt').getElementsByTagName( 'textarea' );
|
| 556 |
+
if(negativePrompt&&negativePrompt.length> 0){
|
| 557 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='img2img_neg_prompt')[0].props.value = this.metadata.negative_prompt;
|
| 558 |
+
negativePrompt[0].value = this.metadata.negative_prompt;
|
| 559 |
+
}
|
| 560 |
+
}catch(e){
|
| 561 |
+
console.log('Error neg img2img');
|
| 562 |
+
console.log(e);
|
| 563 |
+
|
| 564 |
+
}
|
| 565 |
+
|
| 566 |
+
|
| 567 |
+
try{
|
| 568 |
+
const samplerList = gradioApp().querySelector( '#img2img_sampling' ).getElementsByTagName('span');
|
| 569 |
+
if(samplerList&&samplerList.length> 1){
|
| 570 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='img2img_sampling')[0].props.value = this.metadata.sampler;
|
| 571 |
+
samplerList[1].textContent = this.metadata.sampler;
|
| 572 |
+
}
|
| 573 |
+
}catch(e){
|
| 574 |
+
}
|
| 575 |
+
|
| 576 |
+
try{
|
| 577 |
+
const textImageStepsList = gradioApp().querySelector( '#img2img_steps' ).getElementsByTagName('input');
|
| 578 |
+
if(textImageStepsList&&textImageStepsList.length> 1){
|
| 579 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='img2img_steps')[0].props.value = parseInt(this.metadata.n_iter);
|
| 580 |
+
textImageStepsList[0].value = this.metadata.n_iter;
|
| 581 |
+
textImageStepsList[1].value = this.metadata.n_iter;
|
| 582 |
+
}
|
| 583 |
+
}catch(e){
|
| 584 |
+
console.log('Error steps img2img');
|
| 585 |
+
console.log(e);
|
| 586 |
+
|
| 587 |
+
}
|
| 588 |
+
try{
|
| 589 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='img2img_width')[0].props.value = parseInt(this.metadata['Size-1']);
|
| 590 |
+
const textWidthList = gradioApp().querySelector( '#img2img_width' ).getElementsByTagName('input');
|
| 591 |
+
if(textWidthList&&textWidthList.length> 1){
|
| 592 |
+
textWidthList[0].value = this.metadata['Size-1'];
|
| 593 |
+
textWidthList[1].value = this.metadata['Size-1'];
|
| 594 |
+
}
|
| 595 |
+
}catch(e){
|
| 596 |
+
console.log('Error width img2img');
|
| 597 |
+
console.log(e);
|
| 598 |
+
}
|
| 599 |
+
try{
|
| 600 |
+
window.gradio_config.components.filter(el=>el.props.elem_id=='img2img_height')[0].props.value = parseInt(this.metadata['Size-2']);
|
| 601 |
+
const textWidthList = gradioApp().querySelector( '#img2img_height' ).getElementsByTagName('input');
|
| 602 |
+
if(textWidthList&&textWidthList.length> 1){
|
| 603 |
+
textWidthList[0].value = this.metadata['Size-2'];
|
| 604 |
+
textWidthList[1].value = this.metadata['Size-2'];
|
| 605 |
+
}
|
| 606 |
+
}catch(e){
|
| 607 |
+
console.log('Error width height2img');
|
| 608 |
+
console.log(e);
|
| 609 |
+
}
|
| 610 |
+
this.close();
|
| 611 |
+
switch_to_img2img();
|
| 612 |
+
},
|
| 613 |
+
addToWishList(item){
|
| 614 |
+
const userId = localStorage.getItem("userId");
|
| 615 |
+
const token = localStorage.getItem("token");
|
| 616 |
+
const headers={"Authorization":"Token " + token};
|
| 617 |
+
item.liked = true;
|
| 618 |
+
item.likecount = item.likecount + 1;
|
| 619 |
+
axios.post(
|
| 620 |
+
`https://newtypev3-server-vjiloyvjvq-an.a.run.app/image/like`,
|
| 621 |
+
{
|
| 622 |
+
userId,
|
| 623 |
+
imageId: item.id,
|
| 624 |
+
},
|
| 625 |
+
{
|
| 626 |
+
headers
|
| 627 |
+
}
|
| 628 |
+
)
|
| 629 |
+
},
|
| 630 |
+
handleTextareaInput(event) {
|
| 631 |
+
let textarea = event.target;
|
| 632 |
+
textarea.style.height = 'auto';
|
| 633 |
+
textarea.style.height = (textarea.scrollHeight) + 'px';
|
| 634 |
+
comment = event.target.text;
|
| 635 |
+
},
|
| 636 |
+
deleteWishList(item){
|
| 637 |
+
const userId = localStorage.getItem("userId");
|
| 638 |
+
item.liked = false;
|
| 639 |
+
item.likecount = item.likecount -1 ;
|
| 640 |
+
const token = localStorage.getItem("token");
|
| 641 |
+
const headers={"Authorization":"Token " + token};
|
| 642 |
+
axios.delete(
|
| 643 |
+
`https://newtypev3-server-vjiloyvjvq-an.a.run.app/image/like`,
|
| 644 |
+
{data: {
|
| 645 |
+
userId,
|
| 646 |
+
imageId: item.id,
|
| 647 |
+
},
|
| 648 |
+
headers
|
| 649 |
+
},
|
| 650 |
+
)
|
| 651 |
+
},
|
| 652 |
+
makeSaveButtonVisible(){
|
| 653 |
+
this.showCommentWrite = true;
|
| 654 |
+
},
|
| 655 |
+
hideSaveButtonVisible(){
|
| 656 |
+
this.comment = '';
|
| 657 |
+
this.showCommentWrite = false;
|
| 658 |
+
const textArea = gradioApp().querySelector("#modal-writer-type");
|
| 659 |
+
textArea.style.height = 'auto';
|
| 660 |
+
textArea.style.height = (textarea.scrollHeight) + 'px';
|
| 661 |
+
},
|
| 662 |
+
writeComment(){
|
| 663 |
+
if(this.comment.length > 0){
|
| 664 |
+
const userId = localStorage.getItem("userId");
|
| 665 |
+
const token = localStorage.getItem("token");
|
| 666 |
+
const headers={"Authorization":"Token " + token};
|
| 667 |
+
axios.post(
|
| 668 |
+
`https://newtypev3-server-vjiloyvjvq-an.a.run.app/image/comment`,
|
| 669 |
+
{
|
| 670 |
+
userId,
|
| 671 |
+
imageId: this.currentItem.id,
|
| 672 |
+
text: this.comment,
|
| 673 |
+
},{
|
| 674 |
+
headers
|
| 675 |
+
}
|
| 676 |
+
).then((res)=>{
|
| 677 |
+
this.fetchComments();
|
| 678 |
+
this.showCommentWrite = false;
|
| 679 |
+
this.comment = '';
|
| 680 |
+
this.currentItem.total_comments = this.currentItem.total_comments + 1;
|
| 681 |
+
}).catch((e)=>{
|
| 682 |
+
console.log(e);
|
| 683 |
+
});
|
| 684 |
+
|
| 685 |
+
}else{
|
| 686 |
+
return false;
|
| 687 |
+
}
|
| 688 |
+
},
|
| 689 |
+
fetchComments(){
|
| 690 |
+
const token = localStorage.getItem("token");
|
| 691 |
+
const headers={"Authorization":"Token " + token};
|
| 692 |
+
axios.get(
|
| 693 |
+
`https://newtypev3-server-vjiloyvjvq-an.a.run.app/image/comments/${this.currentItem.id}`,
|
| 694 |
+
{
|
| 695 |
+
headers
|
| 696 |
+
}
|
| 697 |
+
).then((res)=>{
|
| 698 |
+
this.comments = res.data;
|
| 699 |
+
this.$forceUpdate();
|
| 700 |
+
}).catch((e)=>{
|
| 701 |
+
console.log(e);
|
| 702 |
+
})
|
| 703 |
+
},
|
| 704 |
+
setOrder(event){
|
| 705 |
+
this.page = 1;
|
| 706 |
+
this.order = event.target.value;
|
| 707 |
+
this.fetchImages();
|
| 708 |
+
},
|
| 709 |
+
setPublic(event){
|
| 710 |
+
this.page = 1;
|
| 711 |
+
this.mode = event.target.value;
|
| 712 |
+
this.fetchImages();
|
| 713 |
+
},
|
| 714 |
+
setMode(mode){
|
| 715 |
+
this.page = 1;
|
| 716 |
+
this.mode = mode;
|
| 717 |
+
this.fetchImages();
|
| 718 |
+
},
|
| 719 |
+
fetchSearchProfile(){
|
| 720 |
+
const params = {
|
| 721 |
+
nickname: this.searchNickname,
|
| 722 |
+
};
|
| 723 |
+
axios.get(
|
| 724 |
+
`https://newtypev3-server-vjiloyvjvq-an.a.run.app/user/profile_nickname`,
|
| 725 |
+
{
|
| 726 |
+
params
|
| 727 |
+
}
|
| 728 |
+
).then((res)=>{
|
| 729 |
+
this.searchProfile = res.data.profile;
|
| 730 |
+
this.$forceUpdate();
|
| 731 |
+
}).catch((e)=>{
|
| 732 |
+
console.log(e);
|
| 733 |
+
})
|
| 734 |
+
},
|
| 735 |
+
fetchNewImage(){
|
| 736 |
+
this.page = 1;
|
| 737 |
+
this.fetchImages();
|
| 738 |
+
},
|
| 739 |
+
fetchImages(){
|
| 740 |
+
this.loading = true;
|
| 741 |
+
if(this.page == -1){
|
| 742 |
+
this.loading = false;
|
| 743 |
+
return false;
|
| 744 |
+
}
|
| 745 |
+
const userId = localStorage.getItem("userId");
|
| 746 |
+
const defaultParams = {
|
| 747 |
+
page: this.page,
|
| 748 |
+
batch_size: 100,
|
| 749 |
+
prompt: this.prompt,
|
| 750 |
+
filter_nsfw: this.filterNsfw,
|
| 751 |
+
};
|
| 752 |
+
if(this.mode == 'latest'){
|
| 753 |
+
defaultParams['order'] = 'created_at';
|
| 754 |
+
}
|
| 755 |
+
if(this.mode == 'nicknameSearch'){
|
| 756 |
+
defaultParams['nickname'] = this.searchNickname;
|
| 757 |
+
defaultParams['order'] = 'created_at';
|
| 758 |
+
}
|
| 759 |
+
if(this.animeTag){
|
| 760 |
+
defaultParams['image_tag'] = 'ANIME';
|
| 761 |
+
}
|
| 762 |
+
if(this.realTag){
|
| 763 |
+
defaultParams['image_tag'] = 'REAL';
|
| 764 |
+
}
|
| 765 |
+
if(this.mode == 'likes'){
|
| 766 |
+
defaultParams['order'] = 'likes';
|
| 767 |
+
}
|
| 768 |
+
if(this.mode == 'favorite'){
|
| 769 |
+
defaultParams['only_liked_pictures'] = true;
|
| 770 |
+
defaultParams['order'] = 'likes_created';
|
| 771 |
+
}
|
| 772 |
+
if(this.mode == 'private'){
|
| 773 |
+
defaultParams['only_my_pictures'] = true;
|
| 774 |
+
defaultParams['order'] = 'created_at';
|
| 775 |
+
}
|
| 776 |
+
const token = localStorage.getItem("token");
|
| 777 |
+
const headers={"Authorization":"Token " + token};
|
| 778 |
+
|
| 779 |
+
axios.get(
|
| 780 |
+
`https://newtypev3-server-vjiloyvjvq-an.a.run.app/image/images/${userId}`,
|
| 781 |
+
{params: defaultParams, headers},
|
| 782 |
+
)
|
| 783 |
+
.then(response => {
|
| 784 |
+
if(this.page == 1){
|
| 785 |
+
this.imageList = response.data;
|
| 786 |
+
}else{
|
| 787 |
+
this.imageList = [...this.imageList, ...response.data];
|
| 788 |
+
}
|
| 789 |
+
this.sortedDataList = reorderData(this.imageList, 4);
|
| 790 |
+
if(response.data.length < 100){
|
| 791 |
+
this.page = -1;
|
| 792 |
+
}
|
| 793 |
+
this.loading = false;
|
| 794 |
+
})
|
| 795 |
+
.catch(error => {
|
| 796 |
+
this.loading = false;
|
| 797 |
+
console.log(error)
|
| 798 |
+
})
|
| 799 |
+
|
| 800 |
+
}
|
| 801 |
+
},
|
| 802 |
+
mounted(){
|
| 803 |
+
var self = this;
|
| 804 |
+
waitForElementToDisplay('#feed-header', function(){
|
| 805 |
+
window.addEventListener('scroll', e => {
|
| 806 |
+
const listElem = gradioApp().querySelector("#columns");
|
| 807 |
+
const tabElem = gradioApp().querySelector("#tab_newtype_tab");
|
| 808 |
+
const tabNotVisible = tabElem && tabElem.style && tabElem.style.display && tabElem.style.display == 'none';
|
| 809 |
+
if(listElem&&listElem.clientHeight * 0.8 <= window.scrollY && self.loading == false && self.page > 0 && !tabNotVisible) {
|
| 810 |
+
self.page = self.page + 1;
|
| 811 |
+
self.fetchImages();
|
| 812 |
+
}
|
| 813 |
+
}, false);
|
| 814 |
+
},1000,9000);
|
| 815 |
+
|
| 816 |
+
},
|
| 817 |
+
beforeDestroy(){
|
| 818 |
+
|
| 819 |
+
},
|
| 820 |
+
created() {
|
| 821 |
+
this.fetchImages();
|
| 822 |
+
const userId = localStorage.getItem("userId");
|
| 823 |
+
const token = localStorage.getItem("token");
|
| 824 |
+
const headers={"Authorization":"Token " + token};
|
| 825 |
+
axios.get(
|
| 826 |
+
`https://newtypev3-server-vjiloyvjvq-an.a.run.app/user/profile/${userId}`,
|
| 827 |
+
{
|
| 828 |
+
headers
|
| 829 |
+
}
|
| 830 |
+
)
|
| 831 |
+
.then(response => {
|
| 832 |
+
const dataObject = response.data;;
|
| 833 |
+
this.likeCount = dataObject.likecount;
|
| 834 |
+
this.nickname = dataObject.nickname;
|
| 835 |
+
this.profile = dataObject.profile;
|
| 836 |
+
this.userId = userId;
|
| 837 |
+
}).catch(error => {
|
| 838 |
+
this.loading = false;
|
| 839 |
+
console.log(error)
|
| 840 |
+
})
|
| 841 |
+
},
|
| 842 |
+
};
|
| 843 |
+
const fetchApp = Vue.createApp(imageModel);
|
| 844 |
+
if (document.querySelector("#vue-elem") != null) {
|
| 845 |
+
fetchApp.mount('#vue-elem');
|
| 846 |
+
}else{
|
| 847 |
+
fetchApp.mount(document.getElementsByTagName("gradio-app")[0].shadowRoot.getElementById("vue-elem"));
|
| 848 |
+
}
|
| 849 |
+
// const fileInput = gradioApp().querySelector('#feed-image-upload');
|
| 850 |
+
// fileInput.addEventListener("change", function() {
|
| 851 |
+
// fileInput.dispatchEvent(new CustomEvent("on_file_upload"));
|
| 852 |
+
// setTimeout(() =>{
|
| 853 |
+
// const el = gradioApp().querySelector(
|
| 854 |
+
// '#feed-search-btn'
|
| 855 |
+
// );
|
| 856 |
+
// el.click();
|
| 857 |
+
// }, 2000);
|
| 858 |
+
// });
|
| 859 |
+
console.log("mount success");
|
| 860 |
+
},1000,9000);
|
sd_feed/javascript/loradownload.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
waitForElementToDisplay(
|
| 3 |
+
"#lora-search-table",
|
| 4 |
+
function(){
|
| 5 |
+
const loraModel = {
|
| 6 |
+
data() {
|
| 7 |
+
return {
|
| 8 |
+
loraList: [],
|
| 9 |
+
loraString: '',
|
| 10 |
+
}
|
| 11 |
+
},
|
| 12 |
+
methods: {
|
| 13 |
+
setUrlData(url, fname){
|
| 14 |
+
const textArea = gradioApp().querySelector("#lora-download-url")
|
| 15 |
+
textArea.value = url;
|
| 16 |
+
const fnameInput = gradioApp().querySelector("#lora-filename")
|
| 17 |
+
fnameInput.value = fname;
|
| 18 |
+
const downloadBtn = gradioApp().querySelector('#lora_download_btn');
|
| 19 |
+
downloadBtn.click();
|
| 20 |
+
}
|
| 21 |
+
},
|
| 22 |
+
mounted(){
|
| 23 |
+
var self = this;
|
| 24 |
+
const textArea = gradioApp().querySelector("#table-data").querySelector('textarea');
|
| 25 |
+
const searchLoraBtn = gradioApp().querySelector("#lora_search_button");
|
| 26 |
+
const tableArea = gradioApp().querySelector("#table-data");
|
| 27 |
+
searchLoraBtn.addEventListener('click', (e)=>{
|
| 28 |
+
|
| 29 |
+
const interval = 500; // 1 second
|
| 30 |
+
const duration = 15000; // 15 seconds
|
| 31 |
+
let count = 0;
|
| 32 |
+
const timer = setInterval(() => {
|
| 33 |
+
// Perform your desired actions here
|
| 34 |
+
count += interval;
|
| 35 |
+
const textArea = gradioApp().querySelector("#table-data").querySelector('textarea');
|
| 36 |
+
const textAreaValue = textArea.value;
|
| 37 |
+
let newJson;
|
| 38 |
+
try{
|
| 39 |
+
newJson = JSON.parse(textAreaValue.replace('(','[').replace(',)', ')').replace(')',']').replaceAll("'", '"'));
|
| 40 |
+
}catch(e){
|
| 41 |
+
console.log(e);
|
| 42 |
+
newJson = [];
|
| 43 |
+
}
|
| 44 |
+
if (textAreaValue !== self.loraString||count >= duration) {
|
| 45 |
+
self.loraString = textAreaValue;
|
| 46 |
+
self.loraList = newJson;
|
| 47 |
+
clearInterval(timer);
|
| 48 |
+
}
|
| 49 |
+
}, interval);
|
| 50 |
+
});
|
| 51 |
+
},
|
| 52 |
+
};
|
| 53 |
+
const loraApp = Vue.createApp(loraModel);
|
| 54 |
+
loraApp.mount(gradioApp().querySelector("#lora-search-table"));
|
| 55 |
+
},1000,9000);
|
sd_feed/javascript/userprofile.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
waitForElementToDisplay(
|
| 2 |
+
"#feed-profile-tab",
|
| 3 |
+
function(){
|
| 4 |
+
const userModel = {
|
| 5 |
+
data() {
|
| 6 |
+
return {
|
| 7 |
+
userId: '',
|
| 8 |
+
nickname: '',
|
| 9 |
+
likeCount: 0,
|
| 10 |
+
editMode: false,
|
| 11 |
+
loading: false,
|
| 12 |
+
}
|
| 13 |
+
},
|
| 14 |
+
methods: {
|
| 15 |
+
close() {},
|
| 16 |
+
mounted(){},
|
| 17 |
+
beforeDestroy(){},
|
| 18 |
+
setEditMode(){
|
| 19 |
+
this.editMode = !this.editMode;
|
| 20 |
+
},
|
| 21 |
+
saveNickname(){
|
| 22 |
+
const userId = localStorage.getItem("userId");
|
| 23 |
+
const token = localStorage.getItem("token");
|
| 24 |
+
const headers={"Authorization":"Token " + token};
|
| 25 |
+
axios.post(
|
| 26 |
+
`https://newtypev3-server-vjiloyvjvq-an.a.run.app/user/profile`,
|
| 27 |
+
{
|
| 28 |
+
userId,
|
| 29 |
+
nickname: this.nickname,
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
headers
|
| 33 |
+
}
|
| 34 |
+
)
|
| 35 |
+
.then(response => {
|
| 36 |
+
this.editMode = false;
|
| 37 |
+
})
|
| 38 |
+
.catch(error => {
|
| 39 |
+
this.loading = false;
|
| 40 |
+
alert(error.response.data.detail);
|
| 41 |
+
})
|
| 42 |
+
},
|
| 43 |
+
|
| 44 |
+
},
|
| 45 |
+
created() {
|
| 46 |
+
const userId = localStorage.getItem("userId");
|
| 47 |
+
const token = localStorage.getItem("token");
|
| 48 |
+
const headers={"Authorization":"Token " + token};
|
| 49 |
+
axios.get(
|
| 50 |
+
`https://newtypev3-server-vjiloyvjvq-an.a.run.app/user/profile/${userId}`,
|
| 51 |
+
{
|
| 52 |
+
headers
|
| 53 |
+
}
|
| 54 |
+
)
|
| 55 |
+
.then(response => {
|
| 56 |
+
const dataObject = response.data;;
|
| 57 |
+
this.likeCount = dataObject.likecount;
|
| 58 |
+
this.nickname = dataObject.nickname;
|
| 59 |
+
this.userId = userId;
|
| 60 |
+
}).catch(error => {
|
| 61 |
+
this.loading = false;
|
| 62 |
+
console.log(error)
|
| 63 |
+
})
|
| 64 |
+
},
|
| 65 |
+
};
|
| 66 |
+
const fetchApp = Vue.createApp(userModel);
|
| 67 |
+
if (document.querySelector("#feed-profile-tab") != null) {
|
| 68 |
+
fetchApp.mount('#feed-profile-tab');
|
| 69 |
+
}else{
|
| 70 |
+
fetchApp.mount(document.getElementsByTagName("gradio-app")[0].shadowRoot.getElementById("feed-profile-tab"));
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
console.log("mount success");
|
| 74 |
+
},1000,9000);
|
sd_feed/javascript/vue.global.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
sd_feed/newtype_v3/__init__.py
ADDED
|
File without changes
|
sd_feed/newtype_v3/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (158 Bytes). View file
|
|
|
sd_feed/newtype_v3/__pycache__/images.cpython-310.pyc
ADDED
|
Binary file (6.46 kB). View file
|
|
|
sd_feed/newtype_v3/__pycache__/locs.cpython-310.pyc
ADDED
|
Binary file (514 Bytes). View file
|
|
|
sd_feed/newtype_v3/__pycache__/lora.cpython-310.pyc
ADDED
|
Binary file (1.1 kB). View file
|
|
|
sd_feed/newtype_v3/__pycache__/lora_types.cpython-310.pyc
ADDED
|
Binary file (313 Bytes). View file
|
|
|
sd_feed/newtype_v3/__pycache__/newtype_v3.cpython-310.pyc
ADDED
|
Binary file (8.64 kB). View file
|
|
|
sd_feed/newtype_v3/__pycache__/users.cpython-310.pyc
ADDED
|
Binary file (1.31 kB). View file
|
|
|
sd_feed/newtype_v3/images.py
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
from typing import Dict, List, Optional
|
| 4 |
+
import re
|
| 5 |
+
import base64
|
| 6 |
+
from io import BytesIO
|
| 7 |
+
from tempfile import _TemporaryFileWrapper
|
| 8 |
+
import traceback
|
| 9 |
+
|
| 10 |
+
from modules.images import read_info_from_image
|
| 11 |
+
from newtype_v3.users import create_user
|
| 12 |
+
from newtype_v3.utils.string_utils import return_string_dict
|
| 13 |
+
from newtype_v3.locs import DEFAULT_LOC
|
| 14 |
+
|
| 15 |
+
from PIL import Image
|
| 16 |
+
from modules.processing import StableDiffusionProcessing
|
| 17 |
+
import requests
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def dumper(obj):
|
| 21 |
+
try:
|
| 22 |
+
return obj.toJSON()
|
| 23 |
+
except Exception:
|
| 24 |
+
try:
|
| 25 |
+
return obj.__dict__
|
| 26 |
+
except Exception:
|
| 27 |
+
return str(obj)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def create_image(img: Image, user_id: str, process: StableDiffusionProcessing, info: Optional[str] = None, token: str = ''):
|
| 31 |
+
try:
|
| 32 |
+
if info:
|
| 33 |
+
data_dict = return_string_dict(info)
|
| 34 |
+
else:
|
| 35 |
+
applied_to_hires = (
|
| 36 |
+
getattr(process, 'applied_old_hires_behavior_to')
|
| 37 |
+
if hasattr(process, 'applied_old_hires_behavior_to')
|
| 38 |
+
else None
|
| 39 |
+
)
|
| 40 |
+
enable_hr = (
|
| 41 |
+
getattr(process, 'enable_hr')
|
| 42 |
+
if hasattr(process, 'enable_hr')
|
| 43 |
+
else None
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
data_dict = {
|
| 47 |
+
'all_negative_prompts': process.all_negative_prompts,
|
| 48 |
+
'all_prompts': process.all_prompts,
|
| 49 |
+
'all_seeds': process.all_seeds,
|
| 50 |
+
'all_subseeds': process.all_subseeds,
|
| 51 |
+
'applied_old_hires_behavior_to': applied_to_hires,
|
| 52 |
+
'batch_size': process.batch_size,
|
| 53 |
+
'cfg_scale': process.cfg_scale,
|
| 54 |
+
'color_corrections': process.color_corrections,
|
| 55 |
+
'ddim_discretize': process.ddim_discretize,
|
| 56 |
+
'denoising_strength': process.denoising_strength,
|
| 57 |
+
'disable_extra_networks': process.disable_extra_networks,
|
| 58 |
+
'do_not_reload_embeddings': process.do_not_reload_embeddings,
|
| 59 |
+
'do_not_save_grid': process.do_not_save_grid,
|
| 60 |
+
'do_not_save_samples': process.do_not_save_samples,
|
| 61 |
+
'enable_hr': enable_hr,
|
| 62 |
+
'eta': process.eta,
|
| 63 |
+
'extra_generation_params': process.extra_generation_params,
|
| 64 |
+
'height': process.height,
|
| 65 |
+
'iteration': process.iteration,
|
| 66 |
+
'n_iter': process.n_iter,
|
| 67 |
+
'negative_prompt': process.negative_prompt,
|
| 68 |
+
'outpath_grids': process.outpath_grids,
|
| 69 |
+
'outpath_samples': process.outpath_samples,
|
| 70 |
+
'overlay_images': process.overlay_images,
|
| 71 |
+
'override_settings': process.override_settings,
|
| 72 |
+
'override_settings_restore_afterwards':
|
| 73 |
+
process.override_settings_restore_afterwards,
|
| 74 |
+
'process': process.paste_to,
|
| 75 |
+
'prompt': process.prompt,
|
| 76 |
+
'prompt_for_display': process.prompt_for_display,
|
| 77 |
+
'restore_faces': process.restore_faces,
|
| 78 |
+
's_churn': process.s_churn,
|
| 79 |
+
's_noise': process.s_noise,
|
| 80 |
+
's_tmax': process.s_tmax,
|
| 81 |
+
's_tmin': process.s_tmin,
|
| 82 |
+
'sampler_name': process.sampler_name,
|
| 83 |
+
'sampler_noise_scheduler_override':
|
| 84 |
+
process.sampler_noise_scheduler_override,
|
| 85 |
+
'script_args': process.script_args,
|
| 86 |
+
'scripts': [x.title() for x in process.scripts.scripts],
|
| 87 |
+
'sd_model': process.sd_model.sd_checkpoint_info.title,
|
| 88 |
+
'seed': process.seed,
|
| 89 |
+
'seed_resize_from_h': process.seed_resize_from_h,
|
| 90 |
+
'seed_resize_from_w': process.seed_resize_from_w,
|
| 91 |
+
'steps': process.steps,
|
| 92 |
+
'styles': process.styles,
|
| 93 |
+
'subseed': process.subseed,
|
| 94 |
+
'subseed_strength': process.subseed_strength,
|
| 95 |
+
}
|
| 96 |
+
for row in [
|
| 97 |
+
'hr_resize_x',
|
| 98 |
+
'hr_resize_y',
|
| 99 |
+
'hr_scale',
|
| 100 |
+
'hr_second_pass_steps',
|
| 101 |
+
'hr_upscale_to_x',
|
| 102 |
+
'hr_upscale_to_y',
|
| 103 |
+
'hr_upscaler',
|
| 104 |
+
'tiling',
|
| 105 |
+
'truncate_x',
|
| 106 |
+
'truncate_y',
|
| 107 |
+
'width'
|
| 108 |
+
]:
|
| 109 |
+
value = (
|
| 110 |
+
getattr(process, row)
|
| 111 |
+
if hasattr(process, row)
|
| 112 |
+
else None
|
| 113 |
+
)
|
| 114 |
+
data_dict[row] = value
|
| 115 |
+
img.save(f'{DEFAULT_LOC}/temp.png', "PNG", optimize=True)
|
| 116 |
+
img.seek(0)
|
| 117 |
+
_ = requests.post(
|
| 118 |
+
'https://newtypev3-server-vjiloyvjvq-an.a.run.app/image/image',
|
| 119 |
+
data={
|
| 120 |
+
'userId': user_id,
|
| 121 |
+
'metadata': json.dumps(data_dict, default=dumper)
|
| 122 |
+
},
|
| 123 |
+
files={
|
| 124 |
+
'upload_file': open(f'{DEFAULT_LOC}/temp.png', 'rb')
|
| 125 |
+
},
|
| 126 |
+
stream=True,
|
| 127 |
+
headers={
|
| 128 |
+
'Authorization': f'Token {token}'
|
| 129 |
+
}
|
| 130 |
+
)
|
| 131 |
+
os.remove(f'{DEFAULT_LOC}/temp.png')
|
| 132 |
+
except Exception as e:
|
| 133 |
+
print(e)
|
| 134 |
+
pass
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
def create_image_from_string(img_string: str, user_id: str, token: str = ''):
|
| 138 |
+
try:
|
| 139 |
+
remove_image = False
|
| 140 |
+
if img_string.startswith("http") or img_string.startswith("file="):
|
| 141 |
+
file_loc = (
|
| 142 |
+
re.search(r'file=(.*)', img_string).group(1)
|
| 143 |
+
.replace("%20", ' ')
|
| 144 |
+
)
|
| 145 |
+
img = Image.open(file_loc)
|
| 146 |
+
text_info, extra_items = read_info_from_image(img)
|
| 147 |
+
data_dict = return_string_dict(text_info)
|
| 148 |
+
data_dict.update(extra_items)
|
| 149 |
+
else:
|
| 150 |
+
file_loc = f'{DEFAULT_LOC}/temp.png'
|
| 151 |
+
img_string = img_string.split(",")[1]
|
| 152 |
+
img = Image.open(BytesIO(base64.b64decode(img_string)))
|
| 153 |
+
img.save(file_loc, "PNG", optimize=True)
|
| 154 |
+
img.seek(0)
|
| 155 |
+
remove_image = True
|
| 156 |
+
|
| 157 |
+
_ = requests.post(
|
| 158 |
+
'https://newtypev3-server-vjiloyvjvq-an.a.run.app/image/image',
|
| 159 |
+
data={
|
| 160 |
+
'userId': user_id,
|
| 161 |
+
'metadata': json.dumps(data_dict, default=dumper)
|
| 162 |
+
},
|
| 163 |
+
files={
|
| 164 |
+
'upload_file': open(file_loc, 'rb')
|
| 165 |
+
},
|
| 166 |
+
stream=True,
|
| 167 |
+
headers={
|
| 168 |
+
'Authorization': f'Token {token}'
|
| 169 |
+
}
|
| 170 |
+
)
|
| 171 |
+
try:
|
| 172 |
+
if remove_image:
|
| 173 |
+
os.remove(file_loc)
|
| 174 |
+
except Exception:
|
| 175 |
+
pass
|
| 176 |
+
return True
|
| 177 |
+
except Exception as e:
|
| 178 |
+
print(e, traceback.format_exc())
|
| 179 |
+
return False
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
def create_image_to_image_file(
|
| 183 |
+
img_string: str, original_img_string: str, user_id: str,
|
| 184 |
+
token: str = ''
|
| 185 |
+
):
|
| 186 |
+
try:
|
| 187 |
+
remove_image = False
|
| 188 |
+
if img_string.startswith("http") or img_string.startswith("file="):
|
| 189 |
+
file_loc = (
|
| 190 |
+
re.search(r'file=(.*)', img_string).group(1)
|
| 191 |
+
.replace("%20", ' ')
|
| 192 |
+
)
|
| 193 |
+
img = Image.open(file_loc)
|
| 194 |
+
text_info, extra_items = read_info_from_image(img)
|
| 195 |
+
data_dict = return_string_dict(text_info)
|
| 196 |
+
data_dict.update(extra_items)
|
| 197 |
+
else:
|
| 198 |
+
file_loc = f'{DEFAULT_LOC}/temp.png'
|
| 199 |
+
img_string = img_string.split(",")[1]
|
| 200 |
+
img = Image.open(BytesIO(base64.b64decode(img_string)))
|
| 201 |
+
img.save(file_loc, "PNG", optimize=True)
|
| 202 |
+
img.seek(0)
|
| 203 |
+
remove_image = True
|
| 204 |
+
origin_loc = f'{DEFAULT_LOC}/temp2.png'
|
| 205 |
+
original_img_string = original_img_string.split(',')[1]
|
| 206 |
+
img = Image.open(BytesIO(base64.b64decode(original_img_string)))
|
| 207 |
+
img.save(origin_loc, "PNG", optimize=True)
|
| 208 |
+
_ = requests.post(
|
| 209 |
+
'https://newtypev3-server-vjiloyvjvq-an.a.run.app/image/image',
|
| 210 |
+
data={
|
| 211 |
+
'userId': user_id,
|
| 212 |
+
'metadata': json.dumps(data_dict, default=dumper)
|
| 213 |
+
},
|
| 214 |
+
files={
|
| 215 |
+
'upload_file': open(file_loc, 'rb'),
|
| 216 |
+
'img_to_img_file': open(origin_loc, 'rb')
|
| 217 |
+
},
|
| 218 |
+
stream=True,
|
| 219 |
+
headers={
|
| 220 |
+
'Authorization': f'Token {token}'
|
| 221 |
+
}
|
| 222 |
+
)
|
| 223 |
+
try:
|
| 224 |
+
if remove_image:
|
| 225 |
+
os.remove(file_loc)
|
| 226 |
+
os.remove(origin_loc)
|
| 227 |
+
except Exception:
|
| 228 |
+
pass
|
| 229 |
+
return True
|
| 230 |
+
except Exception as e:
|
| 231 |
+
print('Image to image save error', e)
|
| 232 |
+
return False
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
def create_image_from_img(img: Image, user_id: str, data_dict: Dict, token: str = ''):
|
| 236 |
+
try:
|
| 237 |
+
file_loc = f'{DEFAULT_LOC}/temp.png'
|
| 238 |
+
img.save(file_loc, "PNG", optimize=True)
|
| 239 |
+
img.seek(0)
|
| 240 |
+
_ = requests.post(
|
| 241 |
+
'https://newtypev3-server-vjiloyvjvq-an.a.run.app/image/image',
|
| 242 |
+
data={
|
| 243 |
+
'userId': user_id,
|
| 244 |
+
'metadata': json.dumps(data_dict, default=dumper)
|
| 245 |
+
},
|
| 246 |
+
files={
|
| 247 |
+
'upload_file': open(file_loc, 'rb')
|
| 248 |
+
},
|
| 249 |
+
stream=True,
|
| 250 |
+
headers={
|
| 251 |
+
'Authorization': f'Token {token}'
|
| 252 |
+
}
|
| 253 |
+
)
|
| 254 |
+
os.remove(file_loc)
|
| 255 |
+
except Exception as e:
|
| 256 |
+
print(e)
|
| 257 |
+
pass
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
def create_multiple_file_uploads(
|
| 261 |
+
data: List[_TemporaryFileWrapper]
|
| 262 |
+
):
|
| 263 |
+
user_dict = create_user()
|
| 264 |
+
user_id = user_dict.get('userId')
|
| 265 |
+
for d in data:
|
| 266 |
+
try:
|
| 267 |
+
image = Image.open(BytesIO(d))
|
| 268 |
+
textinfo, items = read_info_from_image(image)
|
| 269 |
+
if textinfo is not None:
|
| 270 |
+
data = return_string_dict(textinfo)
|
| 271 |
+
data.update(items)
|
| 272 |
+
else:
|
| 273 |
+
data = {}
|
| 274 |
+
create_image_from_img(image, user_id, data)
|
| 275 |
+
except Exception as e:
|
| 276 |
+
print(e)
|
| 277 |
+
pass
|
| 278 |
+
return []
|
| 279 |
+
|
sd_feed/newtype_v3/locs.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
is_exists = os.path.exists('/content/repository/extensions-builtin')
|
| 5 |
+
is_exists_seconds = os.path.exists('/content/drive/MyDrive/SD/extensions/sd_feed/javascript')
|
| 6 |
+
SD_ROOT = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
| 7 |
+
if is_exists and is_exists_seconds:
|
| 8 |
+
DEFAULT_LOC = '/content/drive/MyDrive/SD/extensions/sd_feed'
|
| 9 |
+
else:
|
| 10 |
+
DEFAULT_LOC = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
sd_feed/newtype_v3/lora.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
import traceback
|
| 3 |
+
from typing import List, Dict
|
| 4 |
+
import requests
|
| 5 |
+
from newtype_v3.users import create_user_headers
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def lora_string_list(prompt: str) -> List[str]:
|
| 9 |
+
data_list = []
|
| 10 |
+
for x in re.findall(r'\<lora\:.+?.\>', prompt):
|
| 11 |
+
data_list.append(x.split(':')[1])
|
| 12 |
+
return data_list
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def search_lora_list(lora_list: List[str]) -> List[Dict]:
|
| 16 |
+
try:
|
| 17 |
+
headers, user_dict = create_user_headers()
|
| 18 |
+
result_list = requests.post(
|
| 19 |
+
'https://newtypev3-server-vjiloyvjvq-an.a.run.app/lora/loras',
|
| 20 |
+
json={
|
| 21 |
+
'loraList': lora_list,
|
| 22 |
+
'userId': user_dict.get("userId")
|
| 23 |
+
},
|
| 24 |
+
headers=headers
|
| 25 |
+
)
|
| 26 |
+
result = result_list.json()
|
| 27 |
+
if type(result) is list:
|
| 28 |
+
return result
|
| 29 |
+
raise ValueError(result)
|
| 30 |
+
except Exception as e:
|
| 31 |
+
print(e, traceback.format_exc())
|
| 32 |
+
return False
|
sd_feed/newtype_v3/lora_types.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
SIMILAR: str = "SIMILAR"
|
| 4 |
+
SAME: str = "SAME"
|
| 5 |
+
NOT_FOUND: str = "NOT_FOUND"
|
| 6 |
+
ALREADY_EXISTS: str = "ALREADY_EXSITS"
|
| 7 |
+
|
sd_feed/newtype_v3/newtype_v3.py
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from typing import List, Tuple
|
| 4 |
+
import requests
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
import gradio as gr
|
| 8 |
+
|
| 9 |
+
from modules import call_queue
|
| 10 |
+
from modules import scripts, script_callbacks
|
| 11 |
+
from modules.script_callbacks import ImageSaveParams
|
| 12 |
+
from modules import shared
|
| 13 |
+
|
| 14 |
+
from newtype_v3.locs import DEFAULT_LOC
|
| 15 |
+
from newtype_v3.lora import search_lora_list, lora_string_list
|
| 16 |
+
from . import lora_types
|
| 17 |
+
from .users import create_user, create_user_headers
|
| 18 |
+
from .images import (
|
| 19 |
+
create_image, create_image_from_string, create_image_to_image_file
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
logger = logging.getLogger(__name__)
|
| 24 |
+
|
| 25 |
+
loaded_count = 0
|
| 26 |
+
|
| 27 |
+
base_dir = Path(scripts.basedir())
|
| 28 |
+
all_btns: List[Tuple[gr.Button, ...]] = []
|
| 29 |
+
share_image = False
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def search_lora(prompt: str) -> List[str]:
|
| 33 |
+
if type(prompt) is not str:
|
| 34 |
+
prompt = prompt[0]
|
| 35 |
+
search_list = lora_string_list(prompt)
|
| 36 |
+
try:
|
| 37 |
+
list_of_dict = search_lora_list(search_list)
|
| 38 |
+
except Exception:
|
| 39 |
+
list_of_dict = []
|
| 40 |
+
fname_list = os.listdir(shared.cmd_opts.lora_dir)
|
| 41 |
+
fname_text_list = [
|
| 42 |
+
x.replace(".safetensors", '').replace('.ckpt', '').replace(".pt", '')
|
| 43 |
+
for x in fname_list
|
| 44 |
+
]
|
| 45 |
+
searched_list = [
|
| 46 |
+
x.get('fileName').replace(".safetensors", '').replace('.ckpt', '').replace(".pt", '')
|
| 47 |
+
for x in list_of_dict
|
| 48 |
+
]
|
| 49 |
+
not_found_list = [{
|
| 50 |
+
'fileName': x,
|
| 51 |
+
'downloadUrl': '',
|
| 52 |
+
'status': lora_types.NOT_FOUND
|
| 53 |
+
} for x in search_list
|
| 54 |
+
if x.replace(".safetensor", '').replace('.ckpt', '').replace(".pt", '')
|
| 55 |
+
not in fname_text_list
|
| 56 |
+
and
|
| 57 |
+
x not in searched_list
|
| 58 |
+
]
|
| 59 |
+
list_of_dict = list(filter(lambda x: x.get('fileName') not in fname_list, list_of_dict))
|
| 60 |
+
list_of_dict = [
|
| 61 |
+
{
|
| 62 |
+
'fileName': x.get('fileName'), 'downloadUrl': x.get('downloadUrl'),
|
| 63 |
+
'status': lora_types.SAME,
|
| 64 |
+
}
|
| 65 |
+
for x in list_of_dict
|
| 66 |
+
]
|
| 67 |
+
return list_of_dict + not_found_list
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def set_share_image(x):
|
| 71 |
+
global share_image
|
| 72 |
+
share_image = x
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def save_files(image_file: str, outer_html) -> List[str]:
|
| 76 |
+
user_dict = create_user()
|
| 77 |
+
userId = user_dict.get('userId')
|
| 78 |
+
result = create_image_from_string(
|
| 79 |
+
image_file,
|
| 80 |
+
userId,
|
| 81 |
+
)
|
| 82 |
+
result_string = "Success" if result else "Failed"
|
| 83 |
+
return [
|
| 84 |
+
result_string
|
| 85 |
+
]
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def download_lora(link, fname):
|
| 89 |
+
# Code to handle file download
|
| 90 |
+
response = requests.get(link)
|
| 91 |
+
with open(f'{shared.cmd_opts.lora_dir}/{fname}', 'wb') as f:
|
| 92 |
+
f.write(response.content)
|
| 93 |
+
try:
|
| 94 |
+
headers, user_dict = create_user_headers()
|
| 95 |
+
_ = requests.post(
|
| 96 |
+
'https://newtypev3-server-vjiloyvjvq-an.a.run.app/lora/download',
|
| 97 |
+
json={
|
| 98 |
+
'userId': user_dict.get("userId")
|
| 99 |
+
},
|
| 100 |
+
headers=headers
|
| 101 |
+
)
|
| 102 |
+
except Exception:
|
| 103 |
+
pass
|
| 104 |
+
return ["Success"]
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def save_imgto_img_file(
|
| 108 |
+
image_file: str, original_img_string: str, outer_html: str
|
| 109 |
+
):
|
| 110 |
+
user_dict = create_user()
|
| 111 |
+
userId = user_dict.get('userId')
|
| 112 |
+
token = user_dict.get('token', '')
|
| 113 |
+
result = create_image_to_image_file(
|
| 114 |
+
image_file,
|
| 115 |
+
original_img_string,
|
| 116 |
+
userId,
|
| 117 |
+
token=token
|
| 118 |
+
)
|
| 119 |
+
result_string = "Success" if result else "Failed"
|
| 120 |
+
return [result_string]
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def register_png_posturl() -> None:
|
| 124 |
+
def on_img_save_url(image_save_params: ImageSaveParams) -> None:
|
| 125 |
+
try:
|
| 126 |
+
global share_image
|
| 127 |
+
if share_image:
|
| 128 |
+
user_dict = create_user()
|
| 129 |
+
userId = user_dict.get('userId')
|
| 130 |
+
create_image(
|
| 131 |
+
image_save_params.image,
|
| 132 |
+
userId,
|
| 133 |
+
image_save_params.p,
|
| 134 |
+
info=image_save_params.pnginfo.get("parameters") if image_save_params.pnginfo else None,
|
| 135 |
+
token=user_dict.get('token', ''),
|
| 136 |
+
)
|
| 137 |
+
except Exception:
|
| 138 |
+
logger.exception("Error save data")
|
| 139 |
+
script_callbacks.on_image_saved(on_img_save_url)
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
class Script(scripts.Script):
|
| 143 |
+
def __init__(self):
|
| 144 |
+
global loaded_count
|
| 145 |
+
|
| 146 |
+
loaded_count += 1
|
| 147 |
+
|
| 148 |
+
# This is a hack to make sure that the script is only loaded once
|
| 149 |
+
# Auto1111 calls the script twice, once for the txt2img and once for
|
| 150 |
+
# img2img
|
| 151 |
+
# These callbacks should only be registered once.
|
| 152 |
+
|
| 153 |
+
# When the Reload UI button in the settings tab is pressed, the script
|
| 154 |
+
# is loaded twice again
|
| 155 |
+
# Therefore we only register callbacks every second time the script is
|
| 156 |
+
# loaded
|
| 157 |
+
if loaded_count % 2 == 0:
|
| 158 |
+
return
|
| 159 |
+
register_png_posturl()
|
| 160 |
+
|
| 161 |
+
def title(self):
|
| 162 |
+
return "Feed"
|
| 163 |
+
|
| 164 |
+
def show(self, is_img2img):
|
| 165 |
+
return scripts.AlwaysVisible
|
| 166 |
+
|
| 167 |
+
def process(
|
| 168 |
+
self,
|
| 169 |
+
p,
|
| 170 |
+
*args,
|
| 171 |
+
**kwargs
|
| 172 |
+
):
|
| 173 |
+
return p
|
| 174 |
+
|
| 175 |
+
def after_component(self, component, **kwargs):
|
| 176 |
+
if isinstance(component, gr.HTML):
|
| 177 |
+
if component.elem_id in {'html_info_txt2img'}:
|
| 178 |
+
with open(f'{DEFAULT_LOC}/html/potd.html', encoding='utf-8') as f:
|
| 179 |
+
gr.HTML(
|
| 180 |
+
f.read(),
|
| 181 |
+
elem_id="best-product-tab",
|
| 182 |
+
)
|
| 183 |
+
|
| 184 |
+
if component.elem_id in {'txt2img_override_settings'}:
|
| 185 |
+
with gr.Accordion('Lora Downloads', open=True):
|
| 186 |
+
with gr.Column():
|
| 187 |
+
with gr.Row():
|
| 188 |
+
lora_save = gr.Button(
|
| 189 |
+
'Search Lora', elem_id='lora_search_button'
|
| 190 |
+
)
|
| 191 |
+
# JS에서 브라우저에있는데이터를 save_files함수로 전송
|
| 192 |
+
js_string = """(a)=>{
|
| 193 |
+
const container = gradioApp().querySelector('#txt2img_prompt');
|
| 194 |
+
const textArea = container.getElementsByTagName("textarea")[0];
|
| 195 |
+
return [textArea.value];
|
| 196 |
+
}"""
|
| 197 |
+
txtArea = gr.TextArea(
|
| 198 |
+
'',
|
| 199 |
+
elem_id="table-data",
|
| 200 |
+
visible=False
|
| 201 |
+
)
|
| 202 |
+
lora_download = gr.Button(
|
| 203 |
+
'', elem_id='lora_download_btn',
|
| 204 |
+
visible=False
|
| 205 |
+
)
|
| 206 |
+
download_results = gr.Textbox(
|
| 207 |
+
"",
|
| 208 |
+
label="",
|
| 209 |
+
visible=True
|
| 210 |
+
)
|
| 211 |
+
with open(f'{DEFAULT_LOC}/html/lora.html', encoding='utf-8') as f:
|
| 212 |
+
gr.HTML(f.read(), elem_id="lora-elem")
|
| 213 |
+
lora_save.click(
|
| 214 |
+
fn=call_queue.wrap_gradio_call(search_lora),
|
| 215 |
+
_js=js_string,
|
| 216 |
+
inputs=[lora_save],
|
| 217 |
+
outputs=txtArea,
|
| 218 |
+
show_progress=True,
|
| 219 |
+
)
|
| 220 |
+
download_js_string = """(a)=>{
|
| 221 |
+
const container = gradioApp().querySelector('#lora-download-url');
|
| 222 |
+
const lorafname = gradioApp().querySelector('#lora-filename');
|
| 223 |
+
return [container.value, lorafname.value];
|
| 224 |
+
}"""
|
| 225 |
+
lora_download.click(
|
| 226 |
+
fn=call_queue.wrap_gradio_call(download_lora),
|
| 227 |
+
_js=download_js_string,
|
| 228 |
+
inputs=[lora_download, lora_download],
|
| 229 |
+
outputs=[download_results],
|
| 230 |
+
show_progress=True,
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
if isinstance(component, gr.Gallery):
|
| 234 |
+
if component.elem_id in {'txt2img_gallery'}:
|
| 235 |
+
with gr.Accordion('Feed Settings', open=True):
|
| 236 |
+
with gr.Column():
|
| 237 |
+
with gr.Row():
|
| 238 |
+
save = gr.Button(
|
| 239 |
+
'Share', elem_id='save_txt2_image'
|
| 240 |
+
)
|
| 241 |
+
with open(f'{DEFAULT_LOC}/html/profile.html', encoding='utf-8') as f:
|
| 242 |
+
gr.HTML(f.read(), elem_id="feed-profile-tab")
|
| 243 |
+
# JS에서 브라우저에있는데이터를 save_files함수로 전송
|
| 244 |
+
js_string = """(a)=>{
|
| 245 |
+
const el = gradioApp().querySelector('#txt2img_gallery');
|
| 246 |
+
const imgList = el.getElementsByTagName('img');
|
| 247 |
+
const htmlInfoTxtImg = gradioApp().querySelector('#html_info_txt2img');
|
| 248 |
+
return [imgList[0]['src'], htmlInfoTxtImg.outerHTML];
|
| 249 |
+
}"""
|
| 250 |
+
txt_to_txt_result = gr.Textbox(
|
| 251 |
+
"",
|
| 252 |
+
label="",
|
| 253 |
+
visible=True
|
| 254 |
+
)
|
| 255 |
+
save.click(
|
| 256 |
+
fn=call_queue.wrap_gradio_call(save_files),
|
| 257 |
+
_js=js_string,
|
| 258 |
+
inputs=[save, save],
|
| 259 |
+
outputs=[txt_to_txt_result],
|
| 260 |
+
show_progress=True,
|
| 261 |
+
)
|
| 262 |
+
if component.elem_id in {'img2img_gallery'}:
|
| 263 |
+
with gr.Accordion('Feed Settings', open=True):
|
| 264 |
+
with gr.Column():
|
| 265 |
+
save = gr.Button('Share', elem_id='save_img2_image')
|
| 266 |
+
img_to_img_result = gr.Textbox(
|
| 267 |
+
"",
|
| 268 |
+
label="",
|
| 269 |
+
visible=True
|
| 270 |
+
)
|
| 271 |
+
# JS에서 브라우저에있는데이터를 save_files함수로 전송
|
| 272 |
+
js_string = """(a)=>{
|
| 273 |
+
const el = gradioApp().querySelector('#img2img_gallery');
|
| 274 |
+
const elOrigin = gradioApp().querySelector("#img2img_image");
|
| 275 |
+
const imgList = el.getElementsByTagName('img');
|
| 276 |
+
const originImgList = elOrigin.getElementsByTagName('img');
|
| 277 |
+
const htmlInfoTxtImg = gradioApp().querySelector('#html_info_img2img');
|
| 278 |
+
return [imgList[0]['src'], originImgList[0]['src'], htmlInfoTxtImg.outerHTML];
|
| 279 |
+
}"""
|
| 280 |
+
save.click(
|
| 281 |
+
fn=call_queue.wrap_gradio_call(
|
| 282 |
+
save_imgto_img_file
|
| 283 |
+
),
|
| 284 |
+
_js=js_string,
|
| 285 |
+
inputs=[save, save, save],
|
| 286 |
+
outputs=[
|
| 287 |
+
img_to_img_result
|
| 288 |
+
],
|
| 289 |
+
show_progress=True,
|
| 290 |
+
)
|
| 291 |
+
|
| 292 |
+
def ui(self, is_img2img):
|
| 293 |
+
return []
|
sd_feed/newtype_v3/tabs/__init__.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from . import feed
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
__all__ = [
|
| 5 |
+
feed,
|
| 6 |
+
]
|
sd_feed/newtype_v3/tabs/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (211 Bytes). View file
|
|
|
sd_feed/newtype_v3/tabs/__pycache__/feed.cpython-310.pyc
ADDED
|
Binary file (1.21 kB). View file
|
|
|
sd_feed/newtype_v3/tabs/feed.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
from newtype_v3.users import create_user
|
| 4 |
+
from newtype_v3.locs import DEFAULT_LOC
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def on_ui_tabs():
|
| 8 |
+
user_dict = create_user()
|
| 9 |
+
userId = user_dict.get("userId")
|
| 10 |
+
token = user_dict.get("token")
|
| 11 |
+
script_html = f"""
|
| 12 |
+
<script>window.localStorage.setItem("userId", "{userId}");</script>
|
| 13 |
+
<script>window.localStorage.setItem("token", "{token}");</script>
|
| 14 |
+
"""
|
| 15 |
+
iframe_html = (
|
| 16 |
+
f"""<iframe style="width: 100%; height: 0px" srcdoc='{script_html}'>
|
| 17 |
+
</iframe>"""
|
| 18 |
+
)
|
| 19 |
+
with gr.Blocks() as newtype_tab:
|
| 20 |
+
with gr.Group(elem_id="dynamic-prompting"):
|
| 21 |
+
with gr.Row():
|
| 22 |
+
with gr.Column():
|
| 23 |
+
gr.HTML(iframe_html, elem_id="html_id")
|
| 24 |
+
with open(f'{DEFAULT_LOC}/html/feedtab.html', encoding='utf-8') as f:
|
| 25 |
+
gr.HTML(f.read(), elem_id="vue-elem")
|
| 26 |
+
return (newtype_tab, "Feed", "newtype_tab"),
|
sd_feed/newtype_v3/users.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
from typing import Dict, Tuple
|
| 3 |
+
import uuid
|
| 4 |
+
import requests
|
| 5 |
+
from newtype_v3.locs import DEFAULT_LOC
|
| 6 |
+
|
| 7 |
+
def create_user() -> Dict:
|
| 8 |
+
try:
|
| 9 |
+
with open(f'{DEFAULT_LOC}/user.json') as f:
|
| 10 |
+
user_dict = json.load(f)
|
| 11 |
+
user_id = user_dict.get('userId')
|
| 12 |
+
if not user_dict.get("token"):
|
| 13 |
+
post_dict = {
|
| 14 |
+
'userId': user_id,
|
| 15 |
+
'useAuth': True,
|
| 16 |
+
}
|
| 17 |
+
response = requests.post(
|
| 18 |
+
'https://newtypev3-server-vjiloyvjvq-an.a.run.app/user/user',
|
| 19 |
+
json=post_dict
|
| 20 |
+
)
|
| 21 |
+
token = response.json().get('token')
|
| 22 |
+
user_dict['token'] = token
|
| 23 |
+
with open(f'{DEFAULT_LOC}/user.json', 'w') as f:
|
| 24 |
+
json.dump(user_dict, f, sort_keys=True, indent=4)
|
| 25 |
+
return user_dict
|
| 26 |
+
except Exception:
|
| 27 |
+
userId = str(uuid.uuid4())
|
| 28 |
+
user_dict = {
|
| 29 |
+
'userId': userId,
|
| 30 |
+
'useAuth': True,
|
| 31 |
+
}
|
| 32 |
+
response = requests.post(
|
| 33 |
+
'https://newtypev3-server-vjiloyvjvq-an.a.run.app/user/user',
|
| 34 |
+
json=user_dict
|
| 35 |
+
)
|
| 36 |
+
token = response.json().get('token')
|
| 37 |
+
user_dict['token'] = token
|
| 38 |
+
with open(f'{DEFAULT_LOC}/user.json', 'w') as f:
|
| 39 |
+
json.dump(user_dict, f, sort_keys=True, indent=4)
|
| 40 |
+
return user_dict
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def create_user_headers() -> Tuple[Dict, Dict]:
|
| 44 |
+
user_dict = create_user()
|
| 45 |
+
headers = {
|
| 46 |
+
"Authorization": f"Token {user_dict['token']}",
|
| 47 |
+
}
|
| 48 |
+
return headers, user_dict
|
sd_feed/newtype_v3/utils/__init__.py
ADDED
|
File without changes
|