File size: 1,197 Bytes
a440c84
a90d470
d7528b5
3a7236e
0436d22
 
 
 
 
 
 
 
 
 
 
 
8564b32
d7528b5
0436d22
8564b32
 
0436d22
 
 
 
 
d7528b5
0436d22
 
3a7236e
 
 
 
 
a90d470
 
 
 
 
 
8564b32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
pip install -r requirements.txt
import gradio as gr
import joblib

# Load your serialized objects
model = joblib.load('random_forest_model_3labels2.joblib')
encoder = joblib.load('label_encoder2.joblib')
vectorizer = joblib.load('count_vectorizer2.joblib')

def predict(input_text):
    # Preprocess the input with your vectorizer and encoder as needed
    vectorized_text = vectorizer.transform([input_text])
    
    # Make a prediction
    prediction = model.predict(vectorized_text)
    
    # Decode the prediction into a readable label
    decoded_prediction = encoder.inverse_transform(prediction)
    
    # Return the decoded prediction
    return decoded_prediction[0]  #

# Setup the Gradio interface
iface = gr.Interface(fn=predict,
                     inputs=gr.Textbox(lines=2, placeholder="Enter Text Here..."),
                     outputs="text",
                     description="Detects hate speech in text. Outputs 'Neutral or Ambiguous', 'Not Hate', or 'Offensive or Hate Speech'.")

# Launch the app
iface.launch()


"""
import gradio as gr

def greet(name):
    return "Hello " + name + "!!"

iface = gr.Interface(fn=greet, inputs="text", outputs="text")
iface.launch()
"""