Spaces:
Sleeping
Sleeping
File size: 867 Bytes
8fe81cb 1afb34d 9ff2fd6 1afb34d 9ff2fd6 1afb34d 9ff2fd6 1afb34d 9ff2fd6 1afb34d 9ff2fd6 1afb34d c80f140 3358bee c80f140 |
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 |
import gradio as gr
from sklearn.pipeline import Pipeline
import joblib
class CustomTextClassificationPipeline(Pipeline):
def __init__(self):
tfidf_vectorizer = joblib.load("tfidf_vectorizer.joblib")
linear_svc = joblib.load("model_linear_svc.joblib")
super().__init__([
('tfidf', tfidf_vectorizer),
('classifier', linear_svc)
])
def predict(self, text):
# Call the parent predict method to get the list of predicted labels
y_pred_list = super().predict([text])
# Convert the list to a string by taking the first element
y_pred_str = str(y_pred_list[0])
return y_pred_str
model = CustomTextClassificationPipeline()
def classify(sentence):
return model.predict(sentence)
demo = gr.Interface(fn=classify, inputs="text", outputs="text")
demo.launch()
|