Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -15,7 +15,7 @@ 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("text-classification", model="eliasalbouzidi/distilbert-nsfw-text-classifier",device=device)
|
19 |
|
20 |
NSFW_THRESHOLD = 0.5
|
21 |
|
@@ -23,13 +23,13 @@ NSFW_THRESHOLD = 0.5
|
|
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 |
-
print(text_classification)
|
28 |
|
29 |
# Check the classification results
|
30 |
-
for result in text_classification:
|
31 |
-
|
32 |
-
|
33 |
|
34 |
image = pipe("sketched style, " + prompt,
|
35 |
num_inference_steps=num_inference_steps,
|
@@ -45,12 +45,12 @@ def generate_sketch(prompt, num_inference_steps, guidance_scale):
|
|
45 |
# Check the classification results
|
46 |
for result in image_classification:
|
47 |
if result['label'] == 'nsfw' and result['score'] > NSFW_THRESHOLD:
|
48 |
-
return gr.update(visible=False),gr.Text(value="Inappropriate content detected. Please try another prompt.")
|
49 |
|
50 |
image_path = "generated_sketch.png"
|
51 |
|
52 |
image.save(image_path)
|
53 |
-
return gr.Image(value=image_path), gr.update(visible=False)
|
54 |
|
55 |
# Gradio interface with sliders for num_inference_steps and guidance_scale
|
56 |
interface = gr.Interface(
|
@@ -60,7 +60,10 @@ interface = gr.Interface(
|
|
60 |
gr.Slider(5, 50, value=24, step=1, label="Number of Inference Steps"), # Slider for num_inference_steps
|
61 |
gr.Slider(1.0, 10.0, value=3.5, step=0.1, label="Guidance Scale") # Slider for guidance_scale
|
62 |
],
|
63 |
-
outputs=[
|
|
|
|
|
|
|
64 |
title="Kids Sketch Generator",
|
65 |
description="Enter a text prompt and generate a fun sketch for kids with customizable inference steps and guidance scale."
|
66 |
)
|
|
|
15 |
|
16 |
# Load the NSFW classifier
|
17 |
image_classifier = pipeline("image-classification", model="Falconsai/nsfw_image_detection",device=device)
|
18 |
+
#text_classifier = pipeline("text-classification", model="eliasalbouzidi/distilbert-nsfw-text-classifier",device=device)
|
19 |
|
20 |
NSFW_THRESHOLD = 0.5
|
21 |
|
|
|
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 |
+
#print(text_classification)
|
28 |
|
29 |
# Check the classification results
|
30 |
+
#for result in text_classification:
|
31 |
+
# if result['label'] == 'nsfw' and result['score'] > NSFW_THRESHOLD:
|
32 |
+
# return gr.update(visible=False),gr.Text(value="Inappropriate prompt detected. Please try another prompt.")
|
33 |
|
34 |
image = pipe("sketched style, " + prompt,
|
35 |
num_inference_steps=num_inference_steps,
|
|
|
45 |
# Check the classification results
|
46 |
for result in image_classification:
|
47 |
if result['label'] == 'nsfw' and result['score'] > NSFW_THRESHOLD:
|
48 |
+
return "Inappropriate content detected. Please try another prompt." #return gr.update(visible=False),gr.Text(value="Inappropriate content detected. Please try another prompt.")
|
49 |
|
50 |
image_path = "generated_sketch.png"
|
51 |
|
52 |
image.save(image_path)
|
53 |
+
return image_path #gr.Image(value=image_path), gr.update(visible=False)
|
54 |
|
55 |
# Gradio interface with sliders for num_inference_steps and guidance_scale
|
56 |
interface = gr.Interface(
|
|
|
60 |
gr.Slider(5, 50, value=24, step=1, label="Number of Inference Steps"), # Slider for num_inference_steps
|
61 |
gr.Slider(1.0, 10.0, value=3.5, step=0.1, label="Guidance Scale") # Slider for guidance_scale
|
62 |
],
|
63 |
+
outputs=[
|
64 |
+
gr.Image(type="file", label="Generated Sketch"), # For image output
|
65 |
+
gr.Textbox(label="Message") # For message output (in case of NSFW content)
|
66 |
+
],
|
67 |
title="Kids Sketch Generator",
|
68 |
description="Enter a text prompt and generate a fun sketch for kids with customizable inference steps and guidance scale."
|
69 |
)
|