File size: 1,312 Bytes
a90d470
d7528b5
3a7236e
0436d22
 
 
 
 
 
 
 
 
 
 
 
 
 
d7528b5
0436d22
 
 
 
 
 
 
 
d7528b5
0436d22
 
3a7236e
 
 
 
 
a90d470
 
 
 
 
 
3a7236e
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
42
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
    # For example, if your model expects vectorized input:
    vectorized_text = vectorizer.transform([input_text])
    
    # Make a prediction
    prediction = model.predict(vectorized_text)
    
    # If your model's output needs to be decoded (optional)
    decoded_prediction = encoder.inverse_transform(prediction)
    
    # Return the prediction (you might want to convert it into a more readable form)
    return prediction[0]  # Modify this according to your needs

# 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()
"""