hassoudi commited on
Commit
93fdf42
·
verified ·
1 Parent(s): 402c39a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -9,20 +9,22 @@ login("your-hf-api-token")
9
  # Initialize global pipeline
10
  ner_pipeline = None
11
 
 
 
 
 
 
 
 
 
12
  def load_healthcare_ner_pipeline():
13
  """Load the Hugging Face pipeline for Healthcare NER."""
14
  global ner_pipeline
15
- if ner_pipeline is None:
16
-
17
- token = os.getenv("HFTOKEN") # Retrieve token from environment variable
18
- if not token:
19
- raise ValueError("HF_TOKEN is not set. Please add it to the Secrets in your Space settings.")
20
-
21
  ner_pipeline = pipeline(
22
  "token-classification",
23
  model="TypicaAI/HealthcareNER-Fr",
24
- aggregation_strategy="first", # Groups B- and I- tokens into entities
25
- use_auth_token=token # Use the token for gated models
26
  )
27
  return ner_pipeline
28
 
@@ -40,9 +42,11 @@ def log_demo_usage(text, num_entities):
40
 
41
 
42
 
43
- # Define the main demo interface
44
 
 
 
45
 
 
46
  demo = gr.Interface(
47
  fn=process_text,
48
  inputs=gr.Textbox(
 
9
  # Initialize global pipeline
10
  ner_pipeline = None
11
 
12
+ # Authenticate using the secret `HFTOKEN`
13
+ def authenticate_with_token():
14
+ """Authenticate with the Hugging Face API using the HFTOKEN secret."""
15
+ hf_token = os.getenv("HFTOKEN") # Retrieve the token from environment variables
16
+ if not hf_token:
17
+ raise ValueError("HFTOKEN is not set. Please add it to the Secrets in your Space settings.")
18
+ login(token=hf_token)
19
+
20
  def load_healthcare_ner_pipeline():
21
  """Load the Hugging Face pipeline for Healthcare NER."""
22
  global ner_pipeline
23
+ if ner_pipeline is None:
 
 
 
 
 
24
  ner_pipeline = pipeline(
25
  "token-classification",
26
  model="TypicaAI/HealthcareNER-Fr",
27
+ aggregation_strategy="first" # Groups B- and I- tokens into entities
 
28
  )
29
  return ner_pipeline
30
 
 
42
 
43
 
44
 
 
45
 
46
+ # Authenticate and initialize pipeline
47
+ authenticate_with_token()
48
 
49
+ # Define the main demo interface
50
  demo = gr.Interface(
51
  fn=process_text,
52
  inputs=gr.Textbox(