gni commited on
Commit ·
05d63f9
1
Parent(s): bace0ea
fix: rename parameters for slowapi compatibility
Browse files- api/main.py +7 -8
api/main.py
CHANGED
|
@@ -94,40 +94,39 @@ async def api_status():
|
|
| 94 |
|
| 95 |
@app.post("/api/redact")
|
| 96 |
@limiter.limit("1/2seconds")
|
| 97 |
-
async def redact_text(
|
| 98 |
-
# ... (rest of the logic)
|
| 99 |
try:
|
| 100 |
try:
|
| 101 |
-
target_lang = detect(
|
| 102 |
if target_lang not in ["en", "fr"]: target_lang = "en"
|
| 103 |
except:
|
| 104 |
target_lang = "en"
|
| 105 |
|
| 106 |
-
results = analyzer.analyze(text=
|
| 107 |
|
| 108 |
# Filter protected words
|
| 109 |
clean_results = []
|
| 110 |
for res in results:
|
| 111 |
-
detected_text =
|
| 112 |
if any(pw.lower() in detected_text.lower() for pw in PROTECTED_WORDS):
|
| 113 |
continue
|
| 114 |
clean_results.append(res)
|
| 115 |
|
| 116 |
-
anonymized = anonymizer.anonymize(text=
|
| 117 |
|
| 118 |
# Build detailed metadata for frontend
|
| 119 |
entities_meta = []
|
| 120 |
for res in clean_results:
|
| 121 |
entities_meta.append({
|
| 122 |
"type": res.entity_type,
|
| 123 |
-
"text":
|
| 124 |
"score": round(res.score * 100),
|
| 125 |
"start": res.start,
|
| 126 |
"end": res.end
|
| 127 |
})
|
| 128 |
|
| 129 |
return {
|
| 130 |
-
"original_text":
|
| 131 |
"redacted_text": anonymized.text,
|
| 132 |
"detected_language": target_lang,
|
| 133 |
"entities": entities_meta
|
|
|
|
| 94 |
|
| 95 |
@app.post("/api/redact")
|
| 96 |
@limiter.limit("1/2seconds")
|
| 97 |
+
async def redact_text(body: RedactRequest, request: Request):
|
|
|
|
| 98 |
try:
|
| 99 |
try:
|
| 100 |
+
target_lang = detect(body.text) if body.language == "auto" else body.language
|
| 101 |
if target_lang not in ["en", "fr"]: target_lang = "en"
|
| 102 |
except:
|
| 103 |
target_lang = "en"
|
| 104 |
|
| 105 |
+
results = analyzer.analyze(text=body.text, language=target_lang)
|
| 106 |
|
| 107 |
# Filter protected words
|
| 108 |
clean_results = []
|
| 109 |
for res in results:
|
| 110 |
+
detected_text = body.text[res.start:res.end]
|
| 111 |
if any(pw.lower() in detected_text.lower() for pw in PROTECTED_WORDS):
|
| 112 |
continue
|
| 113 |
clean_results.append(res)
|
| 114 |
|
| 115 |
+
anonymized = anonymizer.anonymize(text=body.text, analyzer_results=clean_results)
|
| 116 |
|
| 117 |
# Build detailed metadata for frontend
|
| 118 |
entities_meta = []
|
| 119 |
for res in clean_results:
|
| 120 |
entities_meta.append({
|
| 121 |
"type": res.entity_type,
|
| 122 |
+
"text": body.text[res.start:res.end],
|
| 123 |
"score": round(res.score * 100),
|
| 124 |
"start": res.start,
|
| 125 |
"end": res.end
|
| 126 |
})
|
| 127 |
|
| 128 |
return {
|
| 129 |
+
"original_text": body.text,
|
| 130 |
"redacted_text": anonymized.text,
|
| 131 |
"detected_language": target_lang,
|
| 132 |
"entities": entities_meta
|