File size: 762 Bytes
8aa9451
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import joblib
from textclassification import IndependentMultiLabelClassifier

# Load the saved classifier model
classifier = joblib.load('classifier_model.joblib')

# Define the prediction function
def predict_text(text):
    predictions = classifier.predict_proba([text])
    result = {category: prob for category, prob in predictions}
    return result

# Create the Gradio interface
interface = gr.Interface(
    fn=predict_text,
    inputs=gr.Textbox(label="Enter your text"),
    outputs=gr.Label(label="Prediction Scores"),
    title="Multi-label Text Classifier",
    description="Enter a text to see the prediction scores for each category."
)

# Launch the app
if __name__ == "__main__":
    interface.launch(share=True, debug=True)