Spaces:
Paused
Paused
Update func_ai.py
Browse files- func_ai.py +18 -2
func_ai.py
CHANGED
@@ -27,8 +27,24 @@ classifier = pipeline(
|
|
27 |
|
28 |
|
29 |
def classify_comment(text):
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
top_class = result['labels'][0]
|
33 |
return top_class
|
34 |
|
|
|
27 |
|
28 |
|
29 |
def classify_comment(text):
|
30 |
+
if not text:
|
31 |
+
print("Received empty text for classification.")
|
32 |
+
return "non-interrogative"
|
33 |
+
print(f"Classifying comment: {text}")
|
34 |
+
try:
|
35 |
+
translated_text = GoogleTranslator(source='auto', target="en").translate(text)
|
36 |
+
except Exception as e:
|
37 |
+
print(f"Translation failed: {e}")
|
38 |
+
return "non-interrogative"
|
39 |
+
if not translated_text:
|
40 |
+
print("Translation returned empty text.")
|
41 |
+
return "non-interrogative"
|
42 |
+
print(f"Translated text: {translated_text}")
|
43 |
+
try:
|
44 |
+
result = classifier(translated_text, ["interrogative", "non-interrogative"], clean_up_tokenization_spaces=True)
|
45 |
+
except Exception as e:
|
46 |
+
print(f"Classification failed: {e}")
|
47 |
+
return "non-interrogative"
|
48 |
top_class = result['labels'][0]
|
49 |
return top_class
|
50 |
|