SCANSKY commited on
Commit
9977acb
·
verified ·
1 Parent(s): b8ba708

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +7 -2
handler.py CHANGED
@@ -38,8 +38,11 @@ class EndpointHandler:
38
  topic_info = self.topic_model.get_topic(topic)
39
  topic_words = [word for word, _ in topic_info] if topic_info else []
40
 
41
- # Get custom label for the topic
42
- custom_label = self.topic_model.custom_labels_[topic + 1] if hasattr(self.topic_model, "custom_labels_") else f"Topic {topic}"
 
 
 
43
 
44
  results.append({
45
  "topic": int(topic),
@@ -76,3 +79,5 @@ class EndpointHandler:
76
  except Exception as e:
77
  return [{"error": str(e)}] # Returning error as a list with a dictionary
78
 
 
 
 
38
  topic_info = self.topic_model.get_topic(topic)
39
  topic_words = [word for word, _ in topic_info] if topic_info else []
40
 
41
+ # Get custom label for the topic (with fallback if custom_labels_ is not available)
42
+ if hasattr(self.topic_model, "custom_labels_") and self.topic_model.custom_labels_ is not None:
43
+ custom_label = self.topic_model.custom_labels_[topic + 1]
44
+ else:
45
+ custom_label = f"Topic {topic}" # Fallback label
46
 
47
  results.append({
48
  "topic": int(topic),
 
79
  except Exception as e:
80
  return [{"error": str(e)}] # Returning error as a list with a dictionary
81
 
82
+ # Create an instance of the handler
83
+ handler = EndpointHandler()