Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,13 +10,6 @@ import sys
|
|
| 10 |
import logging
|
| 11 |
import urllib3 # Import urllib3 to handle warnings
|
| 12 |
|
| 13 |
-
# --- Patch asyncio for HuggingFace Spaces / Gradio conflicts ---
|
| 14 |
-
try:
|
| 15 |
-
import nest_asyncio
|
| 16 |
-
nest_asyncio.apply()
|
| 17 |
-
except ImportError:
|
| 18 |
-
print("⚠️ nest_asyncio not installed. It is recommended for running Asyncio apps in Spaces.")
|
| 19 |
-
|
| 20 |
# --- Suppress specific noisy asyncio errors on shutdown ---
|
| 21 |
if sys.version_info >= (3, 10):
|
| 22 |
logging.getLogger("asyncio").setLevel(logging.WARNING)
|
|
@@ -414,11 +407,19 @@ def rag_predict_fn(text: str):
|
|
| 414 |
else:
|
| 415 |
explanation = "" # Just label found
|
| 416 |
|
| 417 |
-
# Normalize label
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
|
|
|
|
|
|
|
|
|
| 421 |
label = "BENIGN"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 422 |
except:
|
| 423 |
pass # Fallback to showing full response
|
| 424 |
|
|
|
|
| 10 |
import logging
|
| 11 |
import urllib3 # Import urllib3 to handle warnings
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# --- Suppress specific noisy asyncio errors on shutdown ---
|
| 14 |
if sys.version_info >= (3, 10):
|
| 15 |
logging.getLogger("asyncio").setLevel(logging.WARNING)
|
|
|
|
| 407 |
else:
|
| 408 |
explanation = "" # Just label found
|
| 409 |
|
| 410 |
+
# Normalize label part
|
| 411 |
+
label_part = parts[0].replace("LABEL:", "").strip().upper()
|
| 412 |
+
|
| 413 |
+
# Robust parsing logic
|
| 414 |
+
if "BENIGN" in label_part or "SAFE" in label_part or "LEGITIMATE" in label_part:
|
| 415 |
+
label = "BENIGN"
|
| 416 |
+
elif "NOT PHISHING" in label_part:
|
| 417 |
label = "BENIGN"
|
| 418 |
+
elif "PHISHING" in label_part or "MALICIOUS" in label_part:
|
| 419 |
+
label = "PHISHING"
|
| 420 |
+
|
| 421 |
+
# Clean up explanation (remove artifacts)
|
| 422 |
+
explanation = explanation.replace("> EOF by user", "").strip()
|
| 423 |
except:
|
| 424 |
pass # Fallback to showing full response
|
| 425 |
|