Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
import gradio as gr
|
2 |
-
from huggingface_hub import login
|
3 |
from transformers import pipeline
|
4 |
import os
|
5 |
|
@@ -10,39 +9,20 @@ def load_healthcare_ner_pipeline():
|
|
10 |
"""Load the Hugging Face pipeline for Healthcare NER."""
|
11 |
global ner_pipeline
|
12 |
if ner_pipeline is None:
|
13 |
-
#login(token=os.environ["HFTOKEN"])
|
14 |
ner_pipeline = pipeline(
|
15 |
"token-classification",
|
16 |
model="TypicaAI/HealthcareNER-Fr",
|
17 |
-
#use_auth_token=os.environ["HFTOKEN"],
|
18 |
aggregation_strategy="first" # Groups B- and I- tokens into entities
|
19 |
)
|
20 |
return ner_pipeline
|
21 |
|
|
|
22 |
def process_text(text):
|
23 |
"""Process input text and return highlighted entities."""
|
24 |
pipeline = load_healthcare_ner_pipeline()
|
25 |
entities = pipeline(text)
|
26 |
return {"text": text, "entities": entities}
|
27 |
|
28 |
-
# Highlight entities in the text
|
29 |
-
#html_output = highlight_entities(text, entities)
|
30 |
-
# Log usage
|
31 |
-
#log_demo_usage(text, len(entities))
|
32 |
-
#return html_output
|
33 |
-
|
34 |
-
"""
|
35 |
-
def highlight_entities(text, entities):
|
36 |
-
#Highlight identified entities in the input text.
|
37 |
-
highlighted_text = text
|
38 |
-
for entity in entities:
|
39 |
-
entity_text = entity["word"]
|
40 |
-
highlighted_text = highlighted_text.replace(
|
41 |
-
entity_text,
|
42 |
-
f'<mark style="background-color: yellow;">{entity_text}</mark>'
|
43 |
-
)
|
44 |
-
return f"<p>{highlighted_text}</p>"
|
45 |
-
"""
|
46 |
|
47 |
def log_demo_usage(text, num_entities):
|
48 |
"""Log demo usage for analytics."""
|
@@ -60,16 +40,21 @@ demo = gr.Interface(
|
|
60 |
#outputs=gr.HTML(label="Identified Medical Entities"),
|
61 |
title="French Healthcare NER Demo | As featured in 'NLP on OCI'",
|
62 |
description="""
|
63 |
-
🔬 Live demo of the French Healthcare NER model built in Chapter
|
64 |
|
65 |
📚 Follow along with the book to build this exact model step-by-step
|
66 |
🏥 Perfect for medical text analysis, clinical studies, and healthcare compliance
|
67 |
-
⚡
|
68 |
|
69 |
-
By [Hicham Assoudi] - Oracle Consultant
|
70 |
""",
|
71 |
examples=[
|
72 |
-
["Le
|
|
|
|
|
|
|
|
|
|
|
73 |
["Antécédents: infarctus du myocarde en 2019. Allergie à la pénicilline."]
|
74 |
]
|
75 |
)
|
@@ -79,13 +64,13 @@ with gr.Blocks() as marketing_elements:
|
|
79 |
gr.Markdown("""
|
80 |
### 📖 Get the Complete Guide
|
81 |
|
82 |
-
Learn how to build and deploy this exact model in '
|
83 |
- ✓ Step-by-step implementation
|
84 |
- ✓ Performance optimization
|
85 |
- ✓ Enterprise deployment patterns
|
86 |
- ✓ Complete source code
|
87 |
|
88 |
-
[Get the Book](
|
89 |
""")
|
90 |
|
91 |
with gr.Row():
|
|
|
1 |
import gradio as gr
|
|
|
2 |
from transformers import pipeline
|
3 |
import os
|
4 |
|
|
|
9 |
"""Load the Hugging Face pipeline for Healthcare NER."""
|
10 |
global ner_pipeline
|
11 |
if ner_pipeline is None:
|
|
|
12 |
ner_pipeline = pipeline(
|
13 |
"token-classification",
|
14 |
model="TypicaAI/HealthcareNER-Fr",
|
|
|
15 |
aggregation_strategy="first" # Groups B- and I- tokens into entities
|
16 |
)
|
17 |
return ner_pipeline
|
18 |
|
19 |
+
|
20 |
def process_text(text):
|
21 |
"""Process input text and return highlighted entities."""
|
22 |
pipeline = load_healthcare_ner_pipeline()
|
23 |
entities = pipeline(text)
|
24 |
return {"text": text, "entities": entities}
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
def log_demo_usage(text, num_entities):
|
28 |
"""Log demo usage for analytics."""
|
|
|
40 |
#outputs=gr.HTML(label="Identified Medical Entities"),
|
41 |
title="French Healthcare NER Demo | As featured in 'NLP on OCI'",
|
42 |
description="""
|
43 |
+
🔬 Live demo of the French Healthcare NER model built in Chapter 6 of the book 'Natural Language Processing on Oracle Cloud Infrastructure: Building Transformer-Based NLP Solutions Using Oracle AI and Hugging Face Kindle Edition'
|
44 |
|
45 |
📚 Follow along with the book to build this exact model step-by-step
|
46 |
🏥 Perfect for medical text analysis, clinical studies, and healthcare compliance
|
47 |
+
⚡ Model Trained on Oracle Cloud Infrastructure (OCI)
|
48 |
|
49 |
+
By [Hicham Assoudi] - AI Researcher (Ph.D.) • Oracle Consultant • Author
|
50 |
""",
|
51 |
examples=[
|
52 |
+
["Le medecin donne des antibiotiques en cas d'infections des voies respiratoires."],
|
53 |
+
["Le médecin recommande des corticoïdes pour réduire l'inflammation dans les poumons."],
|
54 |
+
["Pour soulager les symptômes d'allergie, le médecin prescrit des antihistaminiques."],
|
55 |
+
["Pour gérer le diabète, le médecin prescrit une insulinothérapie."],
|
56 |
+
["Après une blessure musculaire, le patient doit suivre une physiothérapie."],
|
57 |
+
["En cas d'infection bactérienne, le médecin recommande une antibiothérapie."],
|
58 |
["Antécédents: infarctus du myocarde en 2019. Allergie à la pénicilline."]
|
59 |
]
|
60 |
)
|
|
|
64 |
gr.Markdown("""
|
65 |
### 📖 Get the Complete Guide
|
66 |
|
67 |
+
Learn how to build and deploy this exact model in 'Natural Language Processing on Oracle Cloud Infrastructure: Building Transformer-Based NLP Solutions Using Oracle AI and Hugging Face Kindle Edition'
|
68 |
- ✓ Step-by-step implementation
|
69 |
- ✓ Performance optimization
|
70 |
- ✓ Enterprise deployment patterns
|
71 |
- ✓ Complete source code
|
72 |
|
73 |
+
[Get the Book](https://a.co/d/eg7my5G)
|
74 |
""")
|
75 |
|
76 |
with gr.Row():
|