Staticaliza commited on
Commit
6d6dac5
·
verified ·
1 Parent(s): efe2aab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -9
app.py CHANGED
@@ -11,6 +11,7 @@ import os
11
 
12
  from diffusers import StableDiffusionXLPipeline, StableDiffusion3Pipeline, SD3Transformer2DModel, FlashFlowMatchEulerDiscreteScheduler
13
  from huggingface_hub import snapshot_download
 
14
  from peft import PeftModel
15
  from PIL import Image
16
 
@@ -40,6 +41,8 @@ footer {
40
  }
41
  '''
42
 
 
 
43
  repo_default = StableDiffusionXLPipeline.from_pretrained("fluently/Fluently-XL-Final", torch_dtype=torch.float16, use_safetensors=True, add_watermarker=False)
44
  repo_default.load_lora_weights("ehristoforu/dalle-3-xl-v2", adapter_name="base")
45
  repo_default.set_adapters(["base"], adapter_weights=[0.7])
@@ -76,17 +79,9 @@ def get_seed(seed):
76
  else:
77
  return random.randint(0, MAX_SEED)
78
 
79
- def api_classification_request(url, filename, headers):
80
- with open(filename, "rb") as file:
81
- data = file.read()
82
- response = requests.request("POST", url, headers=headers or {}, data=data)
83
- return json.loads(response.content.decode("utf-8"))
84
-
85
  @spaces.GPU(duration=60)
86
  def generate(input=DEFAULT_INPUT, filter_input="", negative_input=DEFAULT_NEGATIVE_INPUT, model=DEFAULT_MODEL, height=DEFAULT_HEIGHT, width=DEFAULT_WIDTH, steps=1, guidance=0, number=1, seed=None):
87
 
88
- threading.Thread(target=api_classification_request, args=("https://api-inference.huggingface.co/models/Falconsai/nsfw_image_detection", "./Image.png", headers))
89
-
90
  repo = repo_customs[model or "Default"]
91
  filter_input = filter_input or ""
92
  negative_input = negative_input or DEFAULT_NEGATIVE_INPUT
@@ -138,7 +133,7 @@ def generate(input=DEFAULT_INPUT, filter_input="", negative_input=DEFAULT_NEGATI
138
 
139
  print(image_paths)
140
 
141
- nsfw_prediction = api_classification_request("https://api-inference.huggingface.co/models/Falconsai/nsfw_image_detection", image_paths[0], headers)
142
 
143
  print(nsfw_prediction)
144
 
 
11
 
12
  from diffusers import StableDiffusionXLPipeline, StableDiffusion3Pipeline, SD3Transformer2DModel, FlashFlowMatchEulerDiscreteScheduler
13
  from huggingface_hub import snapshot_download
14
+ from transformers import pipeline
15
  from peft import PeftModel
16
  from PIL import Image
17
 
 
41
  }
42
  '''
43
 
44
+ nsfw_classifier = pipeline("image-classification", model="Falconsai/nsfw_image_detection")
45
+
46
  repo_default = StableDiffusionXLPipeline.from_pretrained("fluently/Fluently-XL-Final", torch_dtype=torch.float16, use_safetensors=True, add_watermarker=False)
47
  repo_default.load_lora_weights("ehristoforu/dalle-3-xl-v2", adapter_name="base")
48
  repo_default.set_adapters(["base"], adapter_weights=[0.7])
 
79
  else:
80
  return random.randint(0, MAX_SEED)
81
 
 
 
 
 
 
 
82
  @spaces.GPU(duration=60)
83
  def generate(input=DEFAULT_INPUT, filter_input="", negative_input=DEFAULT_NEGATIVE_INPUT, model=DEFAULT_MODEL, height=DEFAULT_HEIGHT, width=DEFAULT_WIDTH, steps=1, guidance=0, number=1, seed=None):
84
 
 
 
85
  repo = repo_customs[model or "Default"]
86
  filter_input = filter_input or ""
87
  negative_input = negative_input or DEFAULT_NEGATIVE_INPUT
 
133
 
134
  print(image_paths)
135
 
136
+ nsfw_prediction = nsfw_classifier(image_paths[0])
137
 
138
  print(nsfw_prediction)
139