DexterSptizu commited on
Commit
fcc241e
1 Parent(s): 7a451aa

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the token classification model
5
+ pipe = pipeline("token-classification", model="Clinical-AI-Apollo/Medical-NER", aggregation_strategy='simple')
6
+
7
+ def classify_text(text):
8
+ # Get token classification results
9
+ result = pipe(text)
10
+
11
+ # Format the results to resemble the UI shown in the image
12
+ formatted_output = ""
13
+ for res in result:
14
+ entity = res['entity_group']
15
+ word = res['word']
16
+ score = res['score']
17
+ start = res['start']
18
+ end = res['end']
19
+ formatted_output += f"Entity: {entity}, Word: {word}, Score: {score:.4f}, Span: [{start}:{end}]\n"
20
+
21
+ return formatted_output
22
+
23
+ # Gradio Interface
24
+ demo = gr.Interface(
25
+ fn=classify_text,
26
+ inputs=gr.Textbox(lines=5, label="Enter Medical Text"),
27
+ outputs=gr.Textbox(label="Entity Classification"),
28
+ title="Medical Entity Classification",
29
+ description="Enter medical-related text, and the model will classify medical entities.",
30
+ examples=[
31
+ ["45 year old woman diagnosed with CAD"],
32
+ ["A 65-year-old male presents with acute chest pain and a history of hypertension."],
33
+ ["The patient underwent a laparoscopic cholecystectomy."]
34
+ ]
35
+ )
36
+
37
+ if __name__ == "__main__":
38
+ demo.launch()