ivanoctaviogaitansantos commited on
Commit
476db41
verified
1 Parent(s): 9d4a557

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -21,7 +21,7 @@ class AIImageGeneratorNSFW:
21
  if self.is_model_loaded:
22
  return True
23
  try:
24
- logger.info("Cargando modelo base NSFW con LoRA y optimizaci贸n GPU...")
25
  torch_dtype = torch.float16 if self.device == "cuda" else torch.float32
26
 
27
  tokenizer_1 = CLIPTokenizer.from_pretrained(self.model_id, subfolder="tokenizer", use_fast=False)
@@ -41,8 +41,8 @@ class AIImageGeneratorNSFW:
41
  variant="fp16" if self.device == "cuda" else None
42
  )
43
 
44
- # Cargar LoRA usando m茅todo load_lora (actual en diffusers)
45
- self.pipeline.load_lora(self.lora_id, weight=1.0) # Ajusta peso seg煤n convenga
46
 
47
  if self.device == "cuda":
48
  self.pipeline.enable_model_cpu_offload()
@@ -84,14 +84,11 @@ class AIImageGeneratorNSFW:
84
  torch.cuda.empty_cache()
85
  return None
86
 
87
- # Instancia global para Hugging Face Spaces
88
- nsfw_app = None
89
-
90
  def initialize_generator_nsfw():
91
- global nsfw_app
92
- if nsfw_app is None:
93
- nsfw_app = AIImageGeneratorNSFW()
94
- return nsfw_app
95
 
96
  def generate_image_nsfw(prompt, width, height, steps, guidance_scale):
97
  gen = initialize_generator_nsfw()
@@ -125,4 +122,5 @@ def create_nsfw_interface():
125
  )
126
  return iface
127
 
 
128
  nsfw_app = create_nsfw_interface()
 
21
  if self.is_model_loaded:
22
  return True
23
  try:
24
+ logger.info("Cargando modelo base NSFW con LoRA y optimizaci贸n...")
25
  torch_dtype = torch.float16 if self.device == "cuda" else torch.float32
26
 
27
  tokenizer_1 = CLIPTokenizer.from_pretrained(self.model_id, subfolder="tokenizer", use_fast=False)
 
41
  variant="fp16" if self.device == "cuda" else None
42
  )
43
 
44
+ # Carga LoRA con m茅todo actual
45
+ self.pipeline.load_lora(self.lora_id, weight=1.0)
46
 
47
  if self.device == "cuda":
48
  self.pipeline.enable_model_cpu_offload()
 
84
  torch.cuda.empty_cache()
85
  return None
86
 
 
 
 
87
  def initialize_generator_nsfw():
88
+ global generator_nsfw
89
+ if 'generator_nsfw' not in globals():
90
+ globals()['generator_nsfw'] = AIImageGeneratorNSFW()
91
+ return globals()['generator_nsfw']
92
 
93
  def generate_image_nsfw(prompt, width, height, steps, guidance_scale):
94
  gen = initialize_generator_nsfw()
 
122
  )
123
  return iface
124
 
125
+ # Declarar interfaz global para Hugging Face Spaces
126
  nsfw_app = create_nsfw_interface()