yosrissa commited on
Commit
e0abadb
·
verified ·
1 Parent(s): 1fbc5e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -1,6 +1,17 @@
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):
@@ -18,9 +29,12 @@ class CustomSVMTextClassificationPipeline:
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
 
1
  import gradio as gr
2
  import joblib
3
 
4
+ # Define the class names
5
+ class_names = [
6
+ 'Family Issues',
7
+ 'Relationship Conflicts',
8
+ 'Work Dynamics',
9
+ 'Financial and Legal Disagreements',
10
+ 'Personal Boundaries',
11
+ 'Cultural and Identity-Based Issues',
12
+ 'Other'
13
+ ]
14
+
15
  # Define the custom pipeline
16
  class CustomSVMTextClassificationPipeline:
17
  def __init__(self, model_path, vectorizer_path):
 
29
  # Predict using the model
30
  predictions = self.model.predict(preprocessed_texts)
31
 
32
+ # Convert predictions into readable format (class names)
33
+ results = []
34
+ for pred in predictions:
35
+ predicted_classes = [class_names[i] for i, value in enumerate(pred) if value == 1]
36
+ results.append(predicted_classes)
37
+ return results if len(results) > 1 else results[0] # Return a single result for single input
38
 
39
  # Load the model and vectorizer
40
  model_path = "svm_multi_output_model.pkl" # Replace with your model file path