aigmixer commited on
Commit
19be65d
1 Parent(s): a3cf651

add nsfw filter

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -4,8 +4,17 @@ import numpy as np
4
  from io import BytesIO
5
  from huggingface_hub import hf_hub_download
6
  from piper import PiperVoice
 
 
 
 
7
 
8
  def synthesize_speech(text):
 
 
 
 
 
9
  model_path = hf_hub_download(repo_id="aigmixer/speaker_00", filename="speaker_00_model.onnx")
10
  config_path = hf_hub_download(repo_id="aigmixer/speaker_00", filename="speaker_00_model.onnx.json")
11
  voice = PiperVoice.load(model_path, config_path)
@@ -24,10 +33,9 @@ def synthesize_speech(text):
24
  buffer.seek(0)
25
  audio_data = np.frombuffer(buffer.read(), dtype=np.int16)
26
 
27
- return audio_data.tobytes()
28
 
29
  # Using Gradio Blocks
30
-
31
  with gr.Blocks(theme=gr.themes.Base()) as blocks:
32
  gr.Markdown("# Text to Speech Synthesizer")
33
  gr.Markdown("Enter text to synthesize it into speech using PiperVoice.")
@@ -35,7 +43,8 @@ with gr.Blocks(theme=gr.themes.Base()) as blocks:
35
  output_audio = gr.Audio(label="Synthesized Speech", type="numpy")
36
  submit_button = gr.Button("Synthesize")
37
 
38
- submit_button.click(synthesize_speech, inputs=input_text, outputs=output_audio)
39
 
40
  # Run the app
41
  blocks.launch()
 
 
4
  from io import BytesIO
5
  from huggingface_hub import hf_hub_download
6
  from piper import PiperVoice
7
+ from transformers import pipeline
8
+
9
+ # Load the NSFW classifier model
10
+ nsfw_detector = pipeline("text-classification", model="michellejieli/NSFW_text_classifier")
11
 
12
  def synthesize_speech(text):
13
+ # Check for NSFW content
14
+ nsfw_result = nsfw_detector(text)
15
+ if nsfw_result[0]['label'] == 'NSFW':
16
+ return "NSFW content detected. Cannot process.", None
17
+
18
  model_path = hf_hub_download(repo_id="aigmixer/speaker_00", filename="speaker_00_model.onnx")
19
  config_path = hf_hub_download(repo_id="aigmixer/speaker_00", filename="speaker_00_model.onnx.json")
20
  voice = PiperVoice.load(model_path, config_path)
 
33
  buffer.seek(0)
34
  audio_data = np.frombuffer(buffer.read(), dtype=np.int16)
35
 
36
+ return audio_data.tobytes(), None
37
 
38
  # Using Gradio Blocks
 
39
  with gr.Blocks(theme=gr.themes.Base()) as blocks:
40
  gr.Markdown("# Text to Speech Synthesizer")
41
  gr.Markdown("Enter text to synthesize it into speech using PiperVoice.")
 
43
  output_audio = gr.Audio(label="Synthesized Speech", type="numpy")
44
  submit_button = gr.Button("Synthesize")
45
 
46
+ submit_button.click(synthesize_speech, inputs=input_text, outputs=[output_audio, "text"])
47
 
48
  # Run the app
49
  blocks.launch()
50
+