Spaces:
Sleeping
Sleeping
Upload 4 files
Browse filesAI-Powered Bullying & Abuse Detection
- app.py +22 -0
- audio_processing.py +18 -0
- requirements.txt +8 -0
- text_analysis.py +22 -0
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from audio_processing import transcribe_audio
|
3 |
+
from text_analysis import analyze_text
|
4 |
+
|
5 |
+
st.title("🎙️ AI-Powered Bullying & Abuse Detection")
|
6 |
+
|
7 |
+
uploaded_file = st.file_uploader("Upload an audio file", type=["wav", "mp3", "ogg"])
|
8 |
+
|
9 |
+
if uploaded_file is not None:
|
10 |
+
st.audio(uploaded_file, format="audio/wav")
|
11 |
+
|
12 |
+
with st.spinner("Processing audio..."):
|
13 |
+
transcript = transcribe_audio(uploaded_file)
|
14 |
+
|
15 |
+
st.subheader("Transcribed Text")
|
16 |
+
st.write(transcript)
|
17 |
+
|
18 |
+
with st.spinner("Analyzing text..."):
|
19 |
+
result = analyze_text(transcript)
|
20 |
+
|
21 |
+
st.subheader("Analysis Result")
|
22 |
+
st.json(result)
|
audio_processing.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import whisper
|
2 |
+
import tempfile
|
3 |
+
from pydub import AudioSegment
|
4 |
+
import os
|
5 |
+
|
6 |
+
# Set FFmpeg path manually (if needed)
|
7 |
+
AudioSegment.converter = r"C:\ffmpeg\bin\ffmpeg.exe"
|
8 |
+
|
9 |
+
def transcribe_audio(audio_file):
|
10 |
+
model = whisper.load_model("base")
|
11 |
+
|
12 |
+
# Convert to WAV if necessary
|
13 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as temp_wav:
|
14 |
+
audio = AudioSegment.from_file(audio_file)
|
15 |
+
audio.export(temp_wav.name, format="wav")
|
16 |
+
|
17 |
+
result = model.transcribe(temp_wav.name)
|
18 |
+
return result["text"]
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
openai
|
3 |
+
transformers
|
4 |
+
torch
|
5 |
+
vosk
|
6 |
+
pydub
|
7 |
+
numpy
|
8 |
+
openai-whisper
|
text_analysis.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
|
3 |
+
# Load the model (use a fine-tuned model for abuse detection)
|
4 |
+
classifier = pipeline("text-classification", model="unitary/toxic-bert")
|
5 |
+
|
6 |
+
def analyze_text(text):
|
7 |
+
results = classifier(text)
|
8 |
+
|
9 |
+
# Convert to readable format
|
10 |
+
final_result = {
|
11 |
+
"bullying": any(res["label"] == "toxic" and res["score"] > 0.5 for res in results),
|
12 |
+
"threat": any(res["label"] == "threat" and res["score"] > 0.5 for res in results),
|
13 |
+
"scolding": any(res["label"] == "insult" and res["score"] > 0.5 for res in results),
|
14 |
+
"abuse": any(res["label"] in ["toxic", "severe_toxic"] and res["score"] > 0.6 for res in results),
|
15 |
+
"detailed_scores": results
|
16 |
+
}
|
17 |
+
# Make detected categories bold
|
18 |
+
for key in ["bullying", "threat", "scolding", "abuse"]:
|
19 |
+
if final_result[key]:
|
20 |
+
final_result[key] = f"**{key.upper()} DETECTED**"
|
21 |
+
|
22 |
+
return final_result
|