Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,35 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
def classify_text(input_text):
|
9 |
"""
|
10 |
-
Classify the input text using the
|
11 |
"""
|
12 |
results = classifier(input_text)
|
13 |
return results
|
|
|
1 |
import gradio as gr
|
2 |
+
import joblib
|
3 |
|
4 |
+
# Define the custom pipeline
|
5 |
+
class CustomSVMTextClassificationPipeline:
|
6 |
+
def __init__(self, model_path, vectorizer_path):
|
7 |
+
# Load the model and vectorizer
|
8 |
+
self.model = joblib.load(model_path)
|
9 |
+
self.vectorizer = joblib.load(vectorizer_path)
|
10 |
+
|
11 |
+
def __call__(self, texts):
|
12 |
+
if isinstance(texts, str):
|
13 |
+
texts = [texts] # Ensure input is a list
|
14 |
+
|
15 |
+
# Preprocess input using the vectorizer
|
16 |
+
preprocessed_texts = self.vectorizer.transform(texts)
|
17 |
+
|
18 |
+
# Predict using the model
|
19 |
+
predictions = self.model.predict(preprocessed_texts)
|
20 |
+
|
21 |
+
# Convert predictions into a readable format
|
22 |
+
results = [{"text": text, "predictions": list(pred)} for text, pred in zip(texts, predictions)]
|
23 |
+
return results
|
24 |
+
|
25 |
+
# Load the model and vectorizer
|
26 |
+
model_path = "svm_multi_output_model.pkl" # Replace with your model file path
|
27 |
+
vectorizer_path = "tfidf_vectorizer.pkl" # Replace with your vectorizer file path
|
28 |
+
classifier = CustomSVMTextClassificationPipeline(model_path, vectorizer_path)
|
29 |
|
30 |
def classify_text(input_text):
|
31 |
"""
|
32 |
+
Classify the input text using the custom pipeline.
|
33 |
"""
|
34 |
results = classifier(input_text)
|
35 |
return results
|