yasserrmd commited on
Commit
7ca8bcd
1 Parent(s): c66e22e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -24,11 +24,11 @@ NSFW_THRESHOLD = 0.5
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
  # 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,
@@ -44,12 +44,12 @@ def generate_sketch(prompt, num_inference_steps, guidance_scale):
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
 
49
  image_path = "generated_sketch.png"
50
 
51
  image.save(image_path)
52
- return image_path
53
 
54
  # Gradio interface with sliders for num_inference_steps and guidance_scale
55
  interface = gr.Interface(
@@ -59,10 +59,10 @@ interface = gr.Interface(
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
  )
66
 
67
  # Launch the app
68
- interface.launch()
 
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 gr.update(visible=False),gr.Text(value="Inappropriate prompt detected. Please try another prompt.")
32
 
33
  image = pipe("sketched style, " + prompt,
34
  num_inference_steps=num_inference_steps,
 
44
  # Check the classification results
45
  for result in image_classification:
46
  if result['label'] == 'nsfw' and result['score'] > NSFW_THRESHOLD:
47
+ return gr.update(visible=False),gr.Text(value="Inappropriate content detected. Please try another prompt.")
48
 
49
  image_path = "generated_sketch.png"
50
 
51
  image.save(image_path)
52
+ return gr.Image(value=image_path), gr.update(visible=False)
53
 
54
  # Gradio interface with sliders for num_inference_steps and guidance_scale
55
  interface = gr.Interface(
 
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=[gr.Image(), gr.Text()],
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
  )
66
 
67
  # Launch the app
68
+ interface.launch()