Spaces:
Sleeping
Sleeping
Commit
·
e2ce928
1
Parent(s):
c72cb4c
add visualization and warmup
Browse files- app.py +26 -1
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -358,7 +358,7 @@ class MedicalNERApp:
|
|
| 358 |
overflow: hidden;">
|
| 359 |
<div style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 360 |
color: white; padding: 15px; text-align: center;">
|
| 361 |
-
<h3 style="margin: 0; font-size: 18px;"
|
| 362 |
<p style="margin: 5px 0 0 0; opacity: 0.9; font-size: 14px;">
|
| 363 |
Found {entity_count} medical entities
|
| 364 |
</p>
|
|
@@ -395,6 +395,19 @@ class MedicalNERApp:
|
|
| 395 |
f"{'...' if len(unique_texts) > 3 else ''}\n"
|
| 396 |
)
|
| 397 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 398 |
return "\n".join(summary_parts)
|
| 399 |
|
| 400 |
|
|
@@ -402,6 +415,18 @@ class MedicalNERApp:
|
|
| 402 |
print("🚀 Initializing Medical NER Application...")
|
| 403 |
ner_app = MedicalNERApp()
|
| 404 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 405 |
|
| 406 |
def predict_wrapper(text: str, model_name: str):
|
| 407 |
"""Wrapper function for Gradio interface"""
|
|
|
|
| 358 |
overflow: hidden;">
|
| 359 |
<div style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 360 |
color: white; padding: 15px; text-align: center;">
|
| 361 |
+
<h3 style="margin: 0; font-size: 18px;">{model_name}</h3>
|
| 362 |
<p style="margin: 5px 0 0 0; opacity: 0.9; font-size: 14px;">
|
| 363 |
Found {entity_count} medical entities
|
| 364 |
</p>
|
|
|
|
| 395 |
f"{'...' if len(unique_texts) > 3 else ''}\n"
|
| 396 |
)
|
| 397 |
|
| 398 |
+
# Add BIO tags information
|
| 399 |
+
summary_parts.append("\n🏷️ **BIO Tagging Info**\n")
|
| 400 |
+
summary_parts.append("The model uses BIO (Beginning-Inside-Outside) tagging scheme:\n")
|
| 401 |
+
summary_parts.append("• `B-LABEL`: Beginning of an entity\n")
|
| 402 |
+
summary_parts.append("• `I-LABEL`: Inside/continuation of an entity\n")
|
| 403 |
+
summary_parts.append("• `O`: Outside any entity (not shown in results)\n")
|
| 404 |
+
|
| 405 |
+
# Show example BIO tags for detected entity types
|
| 406 |
+
if entity_counts:
|
| 407 |
+
summary_parts.append("\nDetected entity types with their BIO tags:\n")
|
| 408 |
+
for label in sorted(entity_counts.keys()):
|
| 409 |
+
summary_parts.append(f"• `B-{label}`, `I-{label}`: {label} entities\n")
|
| 410 |
+
|
| 411 |
return "\n".join(summary_parts)
|
| 412 |
|
| 413 |
|
|
|
|
| 415 |
print("🚀 Initializing Medical NER Application...")
|
| 416 |
ner_app = MedicalNERApp()
|
| 417 |
|
| 418 |
+
# Run a short warmup for each model here so it's not the first time
|
| 419 |
+
print("🔥 Warming up models...")
|
| 420 |
+
warmup_text = "The patient has diabetes and takes metformin."
|
| 421 |
+
for model_name in MODELS.keys():
|
| 422 |
+
if ner_app.pipelines[model_name] is not None:
|
| 423 |
+
try:
|
| 424 |
+
print(f"Warming up {model_name}...")
|
| 425 |
+
_ = ner_app.predict_entities(warmup_text, model_name)
|
| 426 |
+
print(f"✅ {model_name} warmed up successfully")
|
| 427 |
+
except Exception as e:
|
| 428 |
+
print(f"⚠️ Warmup failed for {model_name}: {str(e)}")
|
| 429 |
+
print("🎉 Model warmup complete!")
|
| 430 |
|
| 431 |
def predict_wrapper(text: str, model_name: str):
|
| 432 |
"""Wrapper function for Gradio interface"""
|
requirements.txt
CHANGED
|
@@ -4,4 +4,5 @@ torch
|
|
| 4 |
tokenizers
|
| 5 |
numpy
|
| 6 |
accelerate
|
| 7 |
-
safetensors
|
|
|
|
|
|
| 4 |
tokenizers
|
| 5 |
numpy
|
| 6 |
accelerate
|
| 7 |
+
safetensors
|
| 8 |
+
spacy
|