Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,9 @@ from transformers import pipeline
|
|
| 4 |
import gradio as gr
|
| 5 |
import spaces
|
| 6 |
|
|
|
|
|
|
|
|
|
|
| 7 |
# Load the model and LoRA weights
|
| 8 |
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16)
|
| 9 |
pipe.load_lora_weights("Shakker-Labs/FLUX.1-dev-LoRA-Children-Simple-Sketch", weight_name="FLUX-dev-lora-children-simple-sketch.safetensors")
|
|
@@ -11,12 +14,22 @@ pipe.fuse_lora(lora_scale=1.5)
|
|
| 11 |
pipe.to("cuda")
|
| 12 |
|
| 13 |
# Load the NSFW classifier
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
NSFW_THRESHOLD = 0.5
|
| 16 |
|
| 17 |
# Define the function to generate the sketch
|
| 18 |
@spaces.GPU
|
| 19 |
def generate_sketch(prompt, num_inference_steps, guidance_scale):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
image = pipe("sketched style, " + prompt,
|
| 21 |
num_inference_steps=num_inference_steps,
|
| 22 |
guidance_scale=guidance_scale,
|
|
@@ -24,12 +37,12 @@ def generate_sketch(prompt, num_inference_steps, guidance_scale):
|
|
| 24 |
|
| 25 |
|
| 26 |
# Classify the image for NSFW content
|
| 27 |
-
|
| 28 |
|
| 29 |
-
print(
|
| 30 |
|
| 31 |
# Check the classification results
|
| 32 |
-
for result in
|
| 33 |
if result['label'] == 'nsfw' and result['score'] > NSFW_THRESHOLD:
|
| 34 |
return "Inappropriate content detected. Please try another prompt."
|
| 35 |
|
|
@@ -46,7 +59,7 @@ interface = gr.Interface(
|
|
| 46 |
gr.Slider(5, 50, value=24, step=1, label="Number of Inference Steps"), # Slider for num_inference_steps
|
| 47 |
gr.Slider(1.0, 10.0, value=3.5, step=0.1, label="Guidance Scale") # Slider for guidance_scale
|
| 48 |
],
|
| 49 |
-
outputs="
|
| 50 |
title="Kids Sketch Generator",
|
| 51 |
description="Enter a text prompt and generate a fun sketch for kids with customizable inference steps and guidance scale."
|
| 52 |
)
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
import spaces
|
| 6 |
|
| 7 |
+
|
| 8 |
+
device=torch.device('cuda')
|
| 9 |
+
|
| 10 |
# Load the model and LoRA weights
|
| 11 |
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16)
|
| 12 |
pipe.load_lora_weights("Shakker-Labs/FLUX.1-dev-LoRA-Children-Simple-Sketch", weight_name="FLUX-dev-lora-children-simple-sketch.safetensors")
|
|
|
|
| 14 |
pipe.to("cuda")
|
| 15 |
|
| 16 |
# Load the NSFW classifier
|
| 17 |
+
image_classifier = pipeline("image-classification", model="Falconsai/nsfw_image_detection",device=device)
|
| 18 |
+
text_classifier = pipeline("sentiment-analysis", model="michellejieli/NSFW_text_classification",device=device)
|
| 19 |
+
classifier("I see you’ve set aside this special time to humiliate yourself in public.")
|
| 20 |
NSFW_THRESHOLD = 0.5
|
| 21 |
|
| 22 |
# Define the function to generate the sketch
|
| 23 |
@spaces.GPU
|
| 24 |
def generate_sketch(prompt, num_inference_steps, guidance_scale):
|
| 25 |
+
# Classify the text for NSFW content
|
| 26 |
+
text_classification = text_classifier(prompt)
|
| 27 |
+
|
| 28 |
+
# Check the classification results
|
| 29 |
+
for result in text_classification:
|
| 30 |
+
if result['label'] == 'nsfw' and result['score'] > NSFW_THRESHOLD:
|
| 31 |
+
return "Inappropriate prompt detected. Please try another prompt."
|
| 32 |
+
|
| 33 |
image = pipe("sketched style, " + prompt,
|
| 34 |
num_inference_steps=num_inference_steps,
|
| 35 |
guidance_scale=guidance_scale,
|
|
|
|
| 37 |
|
| 38 |
|
| 39 |
# Classify the image for NSFW content
|
| 40 |
+
image_classification = image_classifier(image)
|
| 41 |
|
| 42 |
+
print(image_classification)
|
| 43 |
|
| 44 |
# Check the classification results
|
| 45 |
+
for result in image_classification:
|
| 46 |
if result['label'] == 'nsfw' and result['score'] > NSFW_THRESHOLD:
|
| 47 |
return "Inappropriate content detected. Please try another prompt."
|
| 48 |
|
|
|
|
| 59 |
gr.Slider(5, 50, value=24, step=1, label="Number of Inference Steps"), # Slider for num_inference_steps
|
| 60 |
gr.Slider(1.0, 10.0, value=3.5, step=0.1, label="Guidance Scale") # Slider for guidance_scale
|
| 61 |
],
|
| 62 |
+
outputs="auto",
|
| 63 |
title="Kids Sketch Generator",
|
| 64 |
description="Enter a text prompt and generate a fun sketch for kids with customizable inference steps and guidance scale."
|
| 65 |
)
|