DexterSptizu commited on
Commit
8c4e0aa
·
verified ·
1 Parent(s): 7b02dda

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -22,7 +22,7 @@ def classify_text(text):
22
  # Get token classification results
23
  result = pipe(text)
24
 
25
- # Format the results into HTML with color highlighting
26
  highlighted_text = ""
27
  last_pos = 0
28
 
@@ -35,9 +35,9 @@ def classify_text(text):
35
  # Add text before the entity without highlighting
36
  highlighted_text += text[last_pos:start]
37
 
38
- # Add highlighted entity text
39
  color = entity_colors.get(entity, "#e0e0e0") # Default to gray if entity type not defined
40
- highlighted_text += f"<span style='background-color:{color}; padding:2px; border-radius:5px;'>{word}</span>"
41
 
42
  # Update last position
43
  last_pos = end
@@ -45,15 +45,15 @@ def classify_text(text):
45
  # Add the rest of the text after the last entity
46
  highlighted_text += text[last_pos:]
47
 
48
- return highlighted_text
49
 
50
  # Gradio Interface
51
  demo = gr.Interface(
52
  fn=classify_text,
53
  inputs=gr.Textbox(lines=5, label="Enter Medical Text"),
54
- outputs=gr.HTML(label="Entity Classification with Highlighting"),
55
  title="Medical Entity Classification",
56
- description="Enter medical-related text, and the model will classify medical entities with color highlighting.",
57
  examples=[
58
  ["45 year old woman diagnosed with CAD"],
59
  ["A 65-year-old male presents with acute chest pain and a history of hypertension."],
 
22
  # Get token classification results
23
  result = pipe(text)
24
 
25
+ # Format the results into HTML with color highlighting and entity names
26
  highlighted_text = ""
27
  last_pos = 0
28
 
 
35
  # Add text before the entity without highlighting
36
  highlighted_text += text[last_pos:start]
37
 
38
+ # Add highlighted entity text with the entity name displayed
39
  color = entity_colors.get(entity, "#e0e0e0") # Default to gray if entity type not defined
40
+ highlighted_text += f"<span style='background-color:{color}; padding:2px; border-radius:5px; position:relative;'><strong>{word}</strong> <small style='color:#000; background-color: #fff; padding: 2px 4px; border-radius: 3px; position: absolute; top: -25px; left: 0;'>{entity}</small></span>"
41
 
42
  # Update last position
43
  last_pos = end
 
45
  # Add the rest of the text after the last entity
46
  highlighted_text += text[last_pos:]
47
 
48
+ return f"<div style='font-family: Arial, sans-serif; line-height: 1.5;'>{highlighted_text}</div>"
49
 
50
  # Gradio Interface
51
  demo = gr.Interface(
52
  fn=classify_text,
53
  inputs=gr.Textbox(lines=5, label="Enter Medical Text"),
54
+ outputs=gr.HTML(label="Entity Classification with Highlighting and Labels"),
55
  title="Medical Entity Classification",
56
+ description="Enter medical-related text, and the model will classify medical entities with color highlighting and labels.",
57
  examples=[
58
  ["45 year old woman diagnosed with CAD"],
59
  ["A 65-year-old male presents with acute chest pain and a history of hypertension."],