mojad121 commited on
Commit
0474c84
·
verified ·
1 Parent(s): 57bb8a9

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +4 -11
src/streamlit_app.py CHANGED
@@ -10,18 +10,12 @@ os.environ["HF_HOME"] = "/app/.cache/huggingface"
10
  os.environ["TORCH_HOME"] = "/app/.cache/torch"
11
  hf_token = os.getenv("HateSpeechMujtabatoken")
12
 
13
- import torch
14
- import torchaudio
15
- from transformers import AutoTokenizer, AutoModelForSequenceClassification
16
- from transformers import WhisperProcessor, WhisperForConditionalGeneration
17
- import streamlit as st
18
-
19
- whisper_processor = WhisperProcessor.from_pretrained("Hate-speech-CNERG/bert-base-uncased-hatexplain")
20
  whisper_model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-small")
21
  text_model = AutoModelForSequenceClassification.from_pretrained("Hate-speech-CNERG/bert-base-uncased-hatexplain")
22
  tokenizer = AutoTokenizer.from_pretrained("Hate-speech-CNERG/bert-base-uncased-hatexplain")
23
 
24
- label_map = {0: "Not Hate Speech", 1: "Hate Speech"}
25
 
26
  def transcribe(audio_path):
27
  waveform, sample_rate = torchaudio.load(audio_path)
@@ -44,11 +38,10 @@ def predict_hate_speech(audio_path=None, text=None):
44
  text_input = text
45
  else:
46
  return "No input provided"
47
-
48
  prediction = extract_text_features(text_input)
49
  return prediction
50
 
51
- st.title("Hate Speech Detector with Audio and Text")
52
  audio_file = st.file_uploader("Upload an audio file", type=["wav", "mp3", "flac", "ogg", "opus"])
53
  text_input = st.text_input("Optional text input")
54
  if st.button("Predict"):
@@ -61,4 +54,4 @@ if st.button("Predict"):
61
  prediction = predict_hate_speech(text=text_input)
62
  st.success(prediction)
63
  else:
64
- st.warning("Please upload an audio file or enter text.")
 
10
  os.environ["TORCH_HOME"] = "/app/.cache/torch"
11
  hf_token = os.getenv("HateSpeechMujtabatoken")
12
 
13
+ whisper_processor = WhisperProcessor.from_pretrained("openai/whisper-small")
 
 
 
 
 
 
14
  whisper_model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-small")
15
  text_model = AutoModelForSequenceClassification.from_pretrained("Hate-speech-CNERG/bert-base-uncased-hatexplain")
16
  tokenizer = AutoTokenizer.from_pretrained("Hate-speech-CNERG/bert-base-uncased-hatexplain")
17
 
18
+ label_map = {0: "Not Hate Speech", 1: "Hate Speech", 2: "Hate Speech"}
19
 
20
  def transcribe(audio_path):
21
  waveform, sample_rate = torchaudio.load(audio_path)
 
38
  text_input = text
39
  else:
40
  return "No input provided"
 
41
  prediction = extract_text_features(text_input)
42
  return prediction
43
 
44
+ st.title("Hate Speech Detector")
45
  audio_file = st.file_uploader("Upload an audio file", type=["wav", "mp3", "flac", "ogg", "opus"])
46
  text_input = st.text_input("Optional text input")
47
  if st.button("Predict"):
 
54
  prediction = predict_hate_speech(text=text_input)
55
  st.success(prediction)
56
  else:
57
+ st.warning("Please upload an audio file or enter text.")