mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-09-29 09:03:13 +02:00
cleanup
This commit is contained in:
@@ -1,29 +1,32 @@
|
|||||||
"""StableDiffusionXL Module
|
"""StableDiffusionXL Module
|
||||||
"""
|
"""
|
||||||
import gc
|
import gc
|
||||||
import sys
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
sys.path.insert(0, os.path.dirname(__file__))
|
sys.path.insert(0, os.path.dirname(__file__))
|
||||||
|
|
||||||
from ssl import Options
|
|
||||||
from nova_utils.interfaces.server_module import Processor
|
from nova_utils.interfaces.server_module import Processor
|
||||||
from diffusers import StableDiffusionXLImg2ImgPipeline, StableDiffusionXLPipeline, logging
|
from diffusers import StableDiffusionXLImg2ImgPipeline, StableDiffusionXLPipeline, logging
|
||||||
from compel import Compel, ReturnedEmbeddingsType
|
from compel import Compel, ReturnedEmbeddingsType
|
||||||
from nova_utils.utils.cache_utils import get_file
|
from nova_utils.utils.cache_utils import get_file
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
PYTORCH_ENABLE_MPS_FALLBACK = 1
|
PYTORCH_ENABLE_MPS_FALLBACK = 1
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from lora import build_lora_xl
|
from lora import build_lora_xl
|
||||||
|
|
||||||
logging.disable_progress_bar()
|
logging.disable_progress_bar()
|
||||||
logging.enable_explicit_format()
|
logging.enable_explicit_format()
|
||||||
# logging.set_verbosity_info()
|
# logging.set_verbosity_info()
|
||||||
|
|
||||||
|
|
||||||
# Setting defaults
|
# Setting defaults
|
||||||
_default_options = {"model": "stabilityai/stable-diffusion-xl-base-1.0", "ratio": "1-1", "width": "", "height":"", "high_noise_frac" : "0.8", "n_steps" : "35", "lora" : "" }
|
_default_options = {"model": "stabilityai/stable-diffusion-xl-base-1.0", "ratio": "1-1", "width": "", "height": "",
|
||||||
|
"high_noise_frac": "0.8", "n_steps": "35", "lora": ""}
|
||||||
|
|
||||||
|
|
||||||
# TODO: add log infos,
|
# TODO: add log infos,
|
||||||
class StableDiffusionXL(Processor):
|
class StableDiffusionXL(Processor):
|
||||||
@@ -34,7 +37,6 @@ class StableDiffusionXL(Processor):
|
|||||||
self.ds_iter = None
|
self.ds_iter = None
|
||||||
self.current_session = None
|
self.current_session = None
|
||||||
|
|
||||||
|
|
||||||
# IO shortcuts
|
# IO shortcuts
|
||||||
self.input = [x for x in self.model_io if x.io_type == "input"]
|
self.input = [x for x in self.model_io if x.io_type == "input"]
|
||||||
self.output = [x for x in self.model_io if x.io_type == "output"]
|
self.output = [x for x in self.model_io if x.io_type == "output"]
|
||||||
@@ -86,14 +88,12 @@ class StableDiffusionXL(Processor):
|
|||||||
elif ratiown == ratiohn:
|
elif ratiown == ratiohn:
|
||||||
width = height
|
width = height
|
||||||
|
|
||||||
|
|
||||||
print("Processing Output width: " + str(width) + " Output height: " + str(height))
|
print("Processing Output width: " + str(width) + " Output height: " + str(height))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if model == "stabilityai/stable-diffusion-xl-base-1.0":
|
if model == "stabilityai/stable-diffusion-xl-base-1.0":
|
||||||
base = StableDiffusionXLPipeline.from_pretrained(model, torch_dtype=self.torch_d_type, variant=self.variant, use_safetensors=True).to(self.device)
|
base = StableDiffusionXLPipeline.from_pretrained(model, torch_dtype=self.torch_d_type,
|
||||||
|
variant=self.variant, use_safetensors=True).to(
|
||||||
|
self.device)
|
||||||
print("Loaded model: " + model)
|
print("Loaded model: " + model)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@@ -112,8 +112,9 @@ class StableDiffusionXL(Processor):
|
|||||||
|
|
||||||
print(str(model_path))
|
print(str(model_path))
|
||||||
|
|
||||||
|
base = StableDiffusionXLPipeline.from_single_file(str(model_path), torch_dtype=self.torch_d_type,
|
||||||
base = StableDiffusionXLPipeline.from_single_file(str(model_path), torch_dtype=self.torch_d_type, variant=self.variant, use_safetensors=True).to(self.device)
|
variant=self.variant, use_safetensors=True).to(
|
||||||
|
self.device)
|
||||||
print("Loaded model: " + model)
|
print("Loaded model: " + model)
|
||||||
|
|
||||||
if lora != "" and lora != "None":
|
if lora != "" and lora != "None":
|
||||||
@@ -144,7 +145,6 @@ class StableDiffusionXL(Processor):
|
|||||||
variant=self.variant,
|
variant=self.variant,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
compel_base = Compel(
|
compel_base = Compel(
|
||||||
tokenizer=[base.tokenizer, base.tokenizer_2],
|
tokenizer=[base.tokenizer, base.tokenizer_2],
|
||||||
text_encoder=[base.text_encoder, base.text_encoder_2],
|
text_encoder=[base.text_encoder, base.text_encoder_2],
|
||||||
@@ -165,15 +165,11 @@ class StableDiffusionXL(Processor):
|
|||||||
negative_conditioning_refiner, negative_pooled_refiner = compel_refiner(
|
negative_conditioning_refiner, negative_pooled_refiner = compel_refiner(
|
||||||
negative_prompt)
|
negative_prompt)
|
||||||
|
|
||||||
|
|
||||||
n_steps = int(self.options['n_steps'])
|
n_steps = int(self.options['n_steps'])
|
||||||
high_noise_frac = float(self.options['high_noise_frac'])
|
high_noise_frac = float(self.options['high_noise_frac'])
|
||||||
|
|
||||||
|
|
||||||
# base.unet = torch.compile(base.unet, mode="reduce-overhead", fullgraph=True)
|
# base.unet = torch.compile(base.unet, mode="reduce-overhead", fullgraph=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
img = base(
|
img = base(
|
||||||
prompt_embeds=conditioning,
|
prompt_embeds=conditioning,
|
||||||
pooled_prompt_embeds=pooled,
|
pooled_prompt_embeds=pooled,
|
||||||
@@ -235,8 +231,6 @@ class StableDiffusionXL(Processor):
|
|||||||
|
|
||||||
return x, y
|
return x, y
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def to_output(self, data: dict):
|
def to_output(self, data: dict):
|
||||||
self.current_session.output_data_templates['output_image'].data = data
|
self.current_session.output_data_templates['output_image'].data = data
|
||||||
return self.current_session.output_data_templates
|
return self.current_session.output_data_templates
|
@@ -3,11 +3,10 @@ import json
|
|||||||
import math
|
import math
|
||||||
import os
|
import os
|
||||||
import signal
|
import signal
|
||||||
import time
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from nostr_sdk import (Keys, Client, Timestamp, Filter, nip04_decrypt, HandleNotification, EventBuilder, PublicKey,
|
from nostr_sdk import (Keys, Client, Timestamp, Filter, nip04_decrypt, HandleNotification, EventBuilder, PublicKey,
|
||||||
Options, Tag, Event, nip04_encrypt, NostrSigner, EventId, Nip19Event, nip44_decrypt, Kind)
|
Options, Tag, Event, nip04_encrypt, NostrSigner, EventId)
|
||||||
|
|
||||||
from nostr_dvm.utils.database_utils import fetch_user_metadata
|
from nostr_dvm.utils.database_utils import fetch_user_metadata
|
||||||
from nostr_dvm.utils.definitions import EventDefinitions, relay_timeout
|
from nostr_dvm.utils.definitions import EventDefinitions, relay_timeout
|
||||||
@@ -19,7 +18,7 @@ from nostr_dvm.utils.nwc_tools import nwc_zap
|
|||||||
from nostr_dvm.utils.subscription_utils import create_subscription_sql_table, add_to_subscription_sql_table, \
|
from nostr_dvm.utils.subscription_utils import create_subscription_sql_table, add_to_subscription_sql_table, \
|
||||||
get_from_subscription_sql_table, update_subscription_sql_table, get_all_subscriptions_from_sql_table, \
|
get_from_subscription_sql_table, update_subscription_sql_table, get_all_subscriptions_from_sql_table, \
|
||||||
delete_from_subscription_sql_table
|
delete_from_subscription_sql_table
|
||||||
from nostr_dvm.utils.zap_utils import create_bolt11_lud16, zaprequest
|
from nostr_dvm.utils.zap_utils import zaprequest
|
||||||
|
|
||||||
|
|
||||||
class Subscription:
|
class Subscription:
|
||||||
@@ -78,6 +77,7 @@ class Subscription:
|
|||||||
await self.client.subscribe([zap_filter, dvm_filter, cancel_subscription_filter], None)
|
await self.client.subscribe([zap_filter, dvm_filter, cancel_subscription_filter], None)
|
||||||
|
|
||||||
create_subscription_sql_table(dvm_config.DB)
|
create_subscription_sql_table(dvm_config.DB)
|
||||||
|
|
||||||
class NotificationHandler(HandleNotification):
|
class NotificationHandler(HandleNotification):
|
||||||
client = self.client
|
client = self.client
|
||||||
dvm_config = self.dvm_config
|
dvm_config = self.dvm_config
|
||||||
@@ -383,8 +383,6 @@ class Subscription:
|
|||||||
async def handle_subscription_renewal(subscription):
|
async def handle_subscription_renewal(subscription):
|
||||||
zaps = json.loads(subscription.zaps)
|
zaps = json.loads(subscription.zaps)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
success = await pay_zap_split(subscription.nwc, subscription.amount, zaps, subscription.tier,
|
success = await pay_zap_split(subscription.nwc, subscription.amount, zaps, subscription.tier,
|
||||||
subscription.unit)
|
subscription.unit)
|
||||||
if success:
|
if success:
|
||||||
@@ -417,18 +415,15 @@ class Subscription:
|
|||||||
# await self.client.send_direct_msg(PublicKey.parse(subscription.subscriber), message, None)
|
# await self.client.send_direct_msg(PublicKey.parse(subscription.subscriber), message, None)
|
||||||
await self.client.send_private_msg(PublicKey.parse(subscription.subscriber), message, None)
|
await self.client.send_private_msg(PublicKey.parse(subscription.subscriber), message, None)
|
||||||
|
|
||||||
|
|
||||||
async def check_subscriptions():
|
async def check_subscriptions():
|
||||||
try:
|
try:
|
||||||
subscriptions = get_all_subscriptions_from_sql_table(dvm_config.DB)
|
subscriptions = get_all_subscriptions_from_sql_table(dvm_config.DB)
|
||||||
|
|
||||||
for subscription in subscriptions:
|
for subscription in subscriptions:
|
||||||
|
|
||||||
|
|
||||||
if subscription.nwc == "":
|
if subscription.nwc == "":
|
||||||
delete_from_subscription_sql_table(dvm_config.DB, subscription.id)
|
delete_from_subscription_sql_table(dvm_config.DB, subscription.id)
|
||||||
|
|
||||||
|
|
||||||
if subscription.active:
|
if subscription.active:
|
||||||
if subscription.end < Timestamp.now().as_secs():
|
if subscription.end < Timestamp.now().as_secs():
|
||||||
# We could directly zap, but let's make another check if our subscription expired
|
# We could directly zap, but let's make another check if our subscription expired
|
||||||
|
@@ -4,8 +4,7 @@ import os
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, Kind, RelayOptions, \
|
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, Kind, RelayLimits
|
||||||
RelayLimits, Event
|
|
||||||
|
|
||||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||||
@@ -13,7 +12,7 @@ from nostr_dvm.utils.definitions import EventDefinitions, relay_timeout_long, re
|
|||||||
from nostr_dvm.utils.dvmconfig import DVMConfig, build_default_config
|
from nostr_dvm.utils.dvmconfig import DVMConfig, build_default_config
|
||||||
from nostr_dvm.utils.nip88_utils import NIP88Config
|
from nostr_dvm.utils.nip88_utils import NIP88Config
|
||||||
from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag
|
from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag
|
||||||
from nostr_dvm.utils.output_utils import post_process_list_to_users, post_process_list_to_events
|
from nostr_dvm.utils.output_utils import post_process_list_to_events
|
||||||
|
|
||||||
"""
|
"""
|
||||||
This File contains a Module to find inactive follows for a user on nostr
|
This File contains a Module to find inactive follows for a user on nostr
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from nostr_sdk import Kind
|
from nostr_sdk import Kind
|
||||||
|
@@ -47,7 +47,8 @@ async def admin_make_database_updates(adminconfig: AdminConfig = None, dvmconfig
|
|||||||
if not isinstance(adminconfig, AdminConfig):
|
if not isinstance(adminconfig, AdminConfig):
|
||||||
return
|
return
|
||||||
|
|
||||||
if ((adminconfig.WHITELISTUSER is True or adminconfig.UNWHITELISTUSER is True or adminconfig.BLACKLISTUSER is True or adminconfig.DELETEUSER is True)
|
if ((
|
||||||
|
adminconfig.WHITELISTUSER is True or adminconfig.UNWHITELISTUSER is True or adminconfig.BLACKLISTUSER is True or adminconfig.DELETEUSER is True)
|
||||||
and adminconfig.USERNPUBS == []):
|
and adminconfig.USERNPUBS == []):
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -82,8 +83,6 @@ async def admin_make_database_updates(adminconfig: AdminConfig = None, dvmconfig
|
|||||||
if adminconfig.DELETEUSER:
|
if adminconfig.DELETEUSER:
|
||||||
delete_from_sql_table(db, publickey)
|
delete_from_sql_table(db, publickey)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if adminconfig.ClEANDB:
|
if adminconfig.ClEANDB:
|
||||||
clean_db(db)
|
clean_db(db)
|
||||||
|
|
||||||
@@ -96,7 +95,8 @@ async def admin_make_database_updates(adminconfig: AdminConfig = None, dvmconfig
|
|||||||
nut_wallet = await nutzap_wallet.get_nut_wallet(client, keys)
|
nut_wallet = await nutzap_wallet.get_nut_wallet(client, keys)
|
||||||
lud16 = adminconfig.LUD16
|
lud16 = adminconfig.LUD16
|
||||||
npub = keys.public_key().to_hex()
|
npub = keys.public_key().to_hex()
|
||||||
await nutzap_wallet.melt_cashu(nut_wallet, DVMConfig.NUZAP_MINTS[0], nut_wallet.balance, client, keys, lud16, npub)
|
await nutzap_wallet.melt_cashu(nut_wallet, DVMConfig.NUZAP_MINTS[0], nut_wallet.balance, client, keys, lud16,
|
||||||
|
npub)
|
||||||
await nutzap_wallet.get_nut_wallet(client, keys)
|
await nutzap_wallet.get_nut_wallet(client, keys)
|
||||||
|
|
||||||
if adminconfig.REBROADCAST_NIP89:
|
if adminconfig.REBROADCAST_NIP89:
|
||||||
|
Reference in New Issue
Block a user