NIVEthaG commited on
Commit
c8e2e2e
·
verified ·
1 Parent(s): f739cab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -1,3 +1,8 @@
 
 
 
 
 
1
  import gradio as gr
2
  import pickle
3
  import numpy as np
@@ -8,15 +13,13 @@ from transformers import pipeline
8
  # ==========================================
9
  # 1. LOAD MODEL A: Toxic Classifier (LSTM)
10
  # ==========================================
11
- # Load the old Keras model and its pickle tokenizer
12
  lstm_model = tf.keras.models.load_model("toxic_classifier_lstm.h5")
13
  with open("tokenizer.pkl", "rb") as f:
14
  lstm_tokenizer = pickle.load(f)
15
 
16
  def predict_toxicity(text):
17
- # Tokenize and pad for the LSTM
18
  sequences = lstm_tokenizer.texts_to_sequences([text])
19
- padded = pad_sequences(sequences, maxlen=100) # adjust maxlen if yours was different
20
  prediction = lstm_model.predict(padded)[0][0]
21
 
22
  if prediction > 0.5:
 
1
+ import os
2
+ # CRITICAL: Fix for Exit Code 139 segmentation fault on Hugging Face CPU
3
+ os.environ["TF_ENABLE_ONEDNN_OPTS"] = "0"
4
+ os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
5
+
6
  import gradio as gr
7
  import pickle
8
  import numpy as np
 
13
  # ==========================================
14
  # 1. LOAD MODEL A: Toxic Classifier (LSTM)
15
  # ==========================================
 
16
  lstm_model = tf.keras.models.load_model("toxic_classifier_lstm.h5")
17
  with open("tokenizer.pkl", "rb") as f:
18
  lstm_tokenizer = pickle.load(f)
19
 
20
  def predict_toxicity(text):
 
21
  sequences = lstm_tokenizer.texts_to_sequences([text])
22
+ padded = pad_sequences(sequences, maxlen=100)
23
  prediction = lstm_model.predict(padded)[0][0]
24
 
25
  if prediction > 0.5: