Staticaliza commited on
Commit
1d2025e
·
verified ·
1 Parent(s): 0656c70

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -11
app.py CHANGED
@@ -5,9 +5,11 @@ import spaces
5
  import torch
6
  import uuid
7
  import os
 
8
 
9
  from diffusers import StableDiffusionXLPipeline, ControlNetModel
10
  from diffusers.models import AutoencoderKL
 
11
 
12
  # Pre-Initialize
13
  DEVICE = "auto"
@@ -38,19 +40,19 @@ repo_default = StableDiffusionXLPipeline.from_pretrained("sd-community/sdxl-flas
38
  repo_default.load_lora_weights("ehristoforu/dalle-3-xl-v2", adapter_name="base")
39
  repo_default.set_adapters(["base"], adapter_weights=[0.7])
40
 
41
- repo_pixel = StableDiffusionXLPipeline.from_pretrained("sd-community/sdxl-flash", vae=vae, controlnet=controlnet, torch_dtype=torch.float16, use_safetensors=True, add_watermarker=False)
42
- repo_pixel.load_lora_weights("artificialguybr/PixelArtRedmond", adapter_name="base")
43
- repo_pixel.load_lora_weights("nerijs/pixel-art-xl", adapter_name="base2")
44
- repo_pixel.set_adapters(["base", "base2"], adapter_weights=[1, 1])
45
 
46
- repo_large = StableDiffusionXLPipeline.from_pretrained("Corcelio/mobius", vae=vae, controlnet=controlnet, torch_dtype=torch.float16, use_safetensors=True, add_watermarker=False)
47
 
48
  repo_customs = {
49
  "Default": repo_default,
50
- "Realistic": StableDiffusionXLPipeline.from_pretrained("stablediffusionapi/NightVision_XL", vae=vae, controlnet=controlnet, torch_dtype=torch.float16, use_safetensors=False, add_watermarker=False),
51
- "Anime": StableDiffusionXLPipeline.from_pretrained("cagliostrolab/animagine-xl-3.1", vae=vae, controlnet=controlnet, torch_dtype=torch.float16, use_safetensors=True, add_watermarker=False),
52
- "Pixel": repo_pixel,
53
- "Large": repo_large,
54
  }
55
 
56
  # Functions
@@ -120,8 +122,13 @@ def generate(input=DEFAULT_INPUT, filter_input="", negative_input=DEFAULT_NEGATI
120
 
121
  images = repo(**parameters).images
122
  image_paths = [save_image(img, seed) for img in images]
 
 
 
123
  print(image_paths)
124
- return image_paths
 
 
125
 
126
  def cloud():
127
  print("[CLOUD] | Space maintained.")
@@ -148,8 +155,9 @@ with gr.Blocks(css=css) as main:
148
 
149
  with gr.Column():
150
  images = gr.Gallery(columns=1, label="Image")
 
151
 
152
- submit.click(generate, inputs=[input, filter_input, negative_input, model, height, width, steps, guidance, number, seed], outputs=[images], queue=False)
153
  maintain.click(cloud, inputs=[], outputs=[], queue=False)
154
 
155
  main.launch(show_api=True)
 
5
  import torch
6
  import uuid
7
  import os
8
+ from transformers import pipeline
9
 
10
  from diffusers import StableDiffusionXLPipeline, ControlNetModel
11
  from diffusers.models import AutoencoderKL
12
+ from PIL import Image
13
 
14
  # Pre-Initialize
15
  DEVICE = "auto"
 
40
  repo_default.load_lora_weights("ehristoforu/dalle-3-xl-v2", adapter_name="base")
41
  repo_default.set_adapters(["base"], adapter_weights=[0.7])
42
 
43
+ #repo_pixel = StableDiffusionXLPipeline.from_pretrained("sd-community/sdxl-flash", vae=vae, controlnet=controlnet, torch_dtype=torch.float16, use_safetensors=True, add_watermarker=False)
44
+ #repo_pixel.load_lora_weights("artificialguybr/PixelArtRedmond", adapter_name="base")
45
+ #repo_pixel.load_lora_weights("nerijs/pixel-art-xl", adapter_name="base2")
46
+ #repo_pixel.set_adapters(["base", "base2"], adapter_weights=[1, 1])
47
 
48
+ #repo_large = StableDiffusionXLPipeline.from_pretrained("Corcelio/mobius", vae=vae, controlnet=controlnet, torch_dtype=torch.float16, use_safetensors=True, add_watermarker=False)
49
 
50
  repo_customs = {
51
  "Default": repo_default,
52
+ "Realistic": None, #StableDiffusionXLPipeline.from_pretrained("stablediffusionapi/NightVision_XL", vae=vae, controlnet=controlnet, torch_dtype=torch.float16, use_safetensors=False, add_watermarker=False),
53
+ "Anime": None, #StableDiffusionXLPipeline.from_pretrained("cagliostrolab/animagine-xl-3.1", vae=vae, controlnet=controlnet, torch_dtype=torch.float16, use_safetensors=True, add_watermarker=False),
54
+ "Pixel": None, #repo_pixel,
55
+ "Large": None, #repo_large,
56
  }
57
 
58
  # Functions
 
122
 
123
  images = repo(**parameters).images
124
  image_paths = [save_image(img, seed) for img in images]
125
+
126
+ classifier = pipeline("image-classification", model="Falconsai/nsfw_image_detection")(Image.open(image_paths[0]))
127
+
128
  print(image_paths)
129
+ print(classifier)
130
+
131
+ return image_paths, classifier
132
 
133
  def cloud():
134
  print("[CLOUD] | Space maintained.")
 
155
 
156
  with gr.Column():
157
  images = gr.Gallery(columns=1, label="Image")
158
+ classifier = gr.Label()
159
 
160
+ submit.click(generate, inputs=[input, filter_input, negative_input, model, height, width, steps, guidance, number, seed], outputs=[images, classifier], queue=False)
161
  maintain.click(cloud, inputs=[], outputs=[], queue=False)
162
 
163
  main.launch(show_api=True)