AnanthanarayananSeetharaman
commited on
Update app.py
Browse filesenhanced to handle casual / malicuous / threat message and do NER only if mrkt research text.
Used Zero short classifier !
app.py
CHANGED
@@ -65,7 +65,7 @@ def predict_ner(text):
|
|
65 |
# Define the classification function
|
66 |
def classify_text(text):
|
67 |
# Refined labels for better classification
|
68 |
-
candidate_labels = ["market research", "casual/social message"]
|
69 |
hypothesis_template = "This text is a {}."
|
70 |
|
71 |
# Classify the text
|
@@ -81,7 +81,13 @@ def process_text(text):
|
|
81 |
# Classify the text as social or research
|
82 |
classification, confidence = classify_text(text)
|
83 |
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
# If it's social text with high confidence, print it as a social message
|
86 |
print("This is a social message:")
|
87 |
print(text)
|
@@ -94,7 +100,7 @@ def process_text(text):
|
|
94 |
retail_confidence = retail_classification["scores"][0]
|
95 |
|
96 |
if retail_label != "r" and retail_confidence > 0.2:
|
97 |
-
# If it's about retail, send it to the NER pipeline
|
98 |
print("This is a research text about retail. Extracting entities...")
|
99 |
predictions = predict_ner(text)
|
100 |
|
|
|
65 |
# Define the classification function
|
66 |
def classify_text(text):
|
67 |
# Refined labels for better classification
|
68 |
+
candidate_labels = ["market research", "casual/social message", "security threat", "malicious"]
|
69 |
hypothesis_template = "This text is a {}."
|
70 |
|
71 |
# Classify the text
|
|
|
81 |
# Classify the text as social or research
|
82 |
classification, confidence = classify_text(text)
|
83 |
|
84 |
+
print(classification)
|
85 |
+
if classification == "security threat" or classification == "malicious":
|
86 |
+
# If it's social text with high confidence, print it as a social message
|
87 |
+
print("This is a security threat:")
|
88 |
+
print(text)
|
89 |
+
return ["This is not a market research text!"]
|
90 |
+
elif classification == "casual/social message" and confidence > 0.8:
|
91 |
# If it's social text with high confidence, print it as a social message
|
92 |
print("This is a social message:")
|
93 |
print(text)
|
|
|
100 |
retail_confidence = retail_classification["scores"][0]
|
101 |
|
102 |
if retail_label != "r" and retail_confidence > 0.2:
|
103 |
+
# TODO If it's about retail, send it to the NER pipeline
|
104 |
print("This is a research text about retail. Extracting entities...")
|
105 |
predictions = predict_ner(text)
|
106 |
|