2001haitem commited on
Commit
b3cedeb
·
verified ·
1 Parent(s): f8b96a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -4,24 +4,22 @@ from transformers import pipeline
4
  # Load your fine-tuned SpanBERT ADR model
5
  ner_pipeline = pipeline(
6
  "token-classification",
7
- model="hazarri/fine_tuned_spanbert", # replace with your actual model repo name
8
  aggregation_strategy="simple"
9
  )
10
 
11
  def extract_adrs(text):
12
- # Run the model on the input text
13
  results = ner_pipeline(text)
14
 
15
- # If no ADRs found, return an empty list
16
  if not results:
17
  return []
18
 
19
- # Format the results as a list
20
- formatted = [
21
- f"{r['word']} ({r['entity_group']}, score={r['score']:.2f})"
22
- for r in results
23
- ]
24
- return formatted
25
 
26
  # Gradio interface
27
  demo = gr.Interface(
 
4
  # Load your fine-tuned SpanBERT ADR model
5
  ner_pipeline = pipeline(
6
  "token-classification",
7
+ model="hazarri/fine_tuned_spanbert", # replace with your actual model name
8
  aggregation_strategy="simple"
9
  )
10
 
11
  def extract_adrs(text):
12
+ # Run the model
13
  results = ner_pipeline(text)
14
 
15
+ # Return empty list if no entities detected
16
  if not results:
17
  return []
18
 
19
+ # Extract only the ADR words
20
+ adrs = [r["word"] for r in results]
21
+
22
+ return adrs
 
 
23
 
24
  # Gradio interface
25
  demo = gr.Interface(