mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-09-28 07:57:10 +02:00
cleanup
This commit is contained in:
@@ -1,29 +1,32 @@
|
||||
"""StableDiffusionXL Module
|
||||
"""
|
||||
import gc
|
||||
import sys
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
|
||||
from ssl import Options
|
||||
from nova_utils.interfaces.server_module import Processor
|
||||
from diffusers import StableDiffusionXLImg2ImgPipeline, StableDiffusionXLPipeline, logging
|
||||
from compel import Compel, ReturnedEmbeddingsType
|
||||
from nova_utils.utils.cache_utils import get_file
|
||||
import numpy as np
|
||||
|
||||
PYTORCH_ENABLE_MPS_FALLBACK = 1
|
||||
|
||||
import torch
|
||||
from PIL import Image
|
||||
from lora import build_lora_xl
|
||||
|
||||
logging.disable_progress_bar()
|
||||
logging.enable_explicit_format()
|
||||
# logging.set_verbosity_info()
|
||||
|
||||
|
||||
# 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,
|
||||
class StableDiffusionXL(Processor):
|
||||
@@ -34,7 +37,6 @@ class StableDiffusionXL(Processor):
|
||||
self.ds_iter = None
|
||||
self.current_session = None
|
||||
|
||||
|
||||
# IO shortcuts
|
||||
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"]
|
||||
@@ -86,14 +88,12 @@ class StableDiffusionXL(Processor):
|
||||
elif ratiown == ratiohn:
|
||||
width = height
|
||||
|
||||
|
||||
print("Processing Output width: " + str(width) + " Output height: " + str(height))
|
||||
|
||||
|
||||
|
||||
|
||||
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)
|
||||
|
||||
else:
|
||||
@@ -112,8 +112,9 @@ class StableDiffusionXL(Processor):
|
||||
|
||||
print(str(model_path))
|
||||
|
||||
|
||||
base = StableDiffusionXLPipeline.from_single_file(str(model_path), torch_dtype=self.torch_d_type, variant=self.variant, use_safetensors=True).to(self.device)
|
||||
base = StableDiffusionXLPipeline.from_single_file(str(model_path), torch_dtype=self.torch_d_type,
|
||||
variant=self.variant, use_safetensors=True).to(
|
||||
self.device)
|
||||
print("Loaded model: " + model)
|
||||
|
||||
if lora != "" and lora != "None":
|
||||
@@ -144,7 +145,6 @@ class StableDiffusionXL(Processor):
|
||||
variant=self.variant,
|
||||
)
|
||||
|
||||
|
||||
compel_base = Compel(
|
||||
tokenizer=[base.tokenizer, base.tokenizer_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_prompt)
|
||||
|
||||
|
||||
n_steps = int(self.options['n_steps'])
|
||||
high_noise_frac = float(self.options['high_noise_frac'])
|
||||
|
||||
|
||||
# base.unet = torch.compile(base.unet, mode="reduce-overhead", fullgraph=True)
|
||||
|
||||
|
||||
|
||||
img = base(
|
||||
prompt_embeds=conditioning,
|
||||
pooled_prompt_embeds=pooled,
|
||||
@@ -235,8 +231,6 @@ class StableDiffusionXL(Processor):
|
||||
|
||||
return x, y
|
||||
|
||||
|
||||
|
||||
def to_output(self, data: dict):
|
||||
self.current_session.output_data_templates['output_image'].data = data
|
||||
return self.current_session.output_data_templates
|
@@ -3,11 +3,10 @@ import json
|
||||
import math
|
||||
import os
|
||||
import signal
|
||||
import time
|
||||
from datetime import timedelta
|
||||
|
||||
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.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, \
|
||||
get_from_subscription_sql_table, update_subscription_sql_table, get_all_subscriptions_from_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:
|
||||
@@ -78,6 +77,7 @@ class Subscription:
|
||||
await self.client.subscribe([zap_filter, dvm_filter, cancel_subscription_filter], None)
|
||||
|
||||
create_subscription_sql_table(dvm_config.DB)
|
||||
|
||||
class NotificationHandler(HandleNotification):
|
||||
client = self.client
|
||||
dvm_config = self.dvm_config
|
||||
@@ -383,8 +383,6 @@ class Subscription:
|
||||
async def handle_subscription_renewal(subscription):
|
||||
zaps = json.loads(subscription.zaps)
|
||||
|
||||
|
||||
|
||||
success = await pay_zap_split(subscription.nwc, subscription.amount, zaps, subscription.tier,
|
||||
subscription.unit)
|
||||
if success:
|
||||
@@ -417,18 +415,15 @@ class Subscription:
|
||||
# await self.client.send_direct_msg(PublicKey.parse(subscription.subscriber), message, None)
|
||||
await self.client.send_private_msg(PublicKey.parse(subscription.subscriber), message, None)
|
||||
|
||||
|
||||
async def check_subscriptions():
|
||||
try:
|
||||
subscriptions = get_all_subscriptions_from_sql_table(dvm_config.DB)
|
||||
|
||||
for subscription in subscriptions:
|
||||
|
||||
|
||||
if subscription.nwc == "":
|
||||
delete_from_subscription_sql_table(dvm_config.DB, subscription.id)
|
||||
|
||||
|
||||
if subscription.active:
|
||||
if subscription.end < Timestamp.now().as_secs():
|
||||
# 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 threading import Thread
|
||||
|
||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, Kind, RelayOptions, \
|
||||
RelayLimits, Event
|
||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, Kind, RelayLimits
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
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.nip88_utils import NIP88Config
|
||||
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
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import json
|
||||
import os
|
||||
from io import BytesIO
|
||||
|
||||
import requests
|
||||
from PIL import Image
|
||||
from nostr_sdk import Kind
|
||||
|
@@ -47,7 +47,8 @@ async def admin_make_database_updates(adminconfig: AdminConfig = None, dvmconfig
|
||||
if not isinstance(adminconfig, AdminConfig):
|
||||
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 == []):
|
||||
return
|
||||
|
||||
@@ -82,8 +83,6 @@ async def admin_make_database_updates(adminconfig: AdminConfig = None, dvmconfig
|
||||
if adminconfig.DELETEUSER:
|
||||
delete_from_sql_table(db, publickey)
|
||||
|
||||
|
||||
|
||||
if adminconfig.ClEANDB:
|
||||
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)
|
||||
lud16 = adminconfig.LUD16
|
||||
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)
|
||||
|
||||
if adminconfig.REBROADCAST_NIP89:
|
||||
|
Reference in New Issue
Block a user