Spaces:
Running
Running
OrifjonKenjayev
commited on
Commit
•
8aa9451
1
Parent(s):
1573b7e
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import joblib
|
3 |
+
from textclassification import IndependentMultiLabelClassifier
|
4 |
+
|
5 |
+
# Load the saved classifier model
|
6 |
+
classifier = joblib.load('classifier_model.joblib')
|
7 |
+
|
8 |
+
# Define the prediction function
|
9 |
+
def predict_text(text):
|
10 |
+
predictions = classifier.predict_proba([text])
|
11 |
+
result = {category: prob for category, prob in predictions}
|
12 |
+
return result
|
13 |
+
|
14 |
+
# Create the Gradio interface
|
15 |
+
interface = gr.Interface(
|
16 |
+
fn=predict_text,
|
17 |
+
inputs=gr.Textbox(label="Enter your text"),
|
18 |
+
outputs=gr.Label(label="Prediction Scores"),
|
19 |
+
title="Multi-label Text Classifier",
|
20 |
+
description="Enter a text to see the prediction scores for each category."
|
21 |
+
)
|
22 |
+
|
23 |
+
# Launch the app
|
24 |
+
if __name__ == "__main__":
|
25 |
+
interface.launch(share=True, debug=True)
|