arawindsg commited on
Commit
53750e9
·
verified ·
1 Parent(s): bf95213

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
3
+
4
+ # Set Streamlit page config
5
+ st.set_page_config(page_title="Disease NER", layout="centered")
6
+
7
+ # Title of the app
8
+ st.title("🧠 Disease Named Entity Recognition (NER)")
9
+ st.write("This app uses a BioBERT model to detect **disease entities** in clinical or medical text.")
10
+
11
+ # Load the model
12
+ @st.cache_resource
13
+ def load_model():
14
+ model_name = "Ishan0612/biobert-ner-disease-ncbi"
15
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
16
+ model = AutoModelForTokenClassification.from_pretrained(model_name)
17
+ ner_pipeline = pipeline("ner", model=model, tokenizer=tokenizer, aggregation_strategy="simple")
18
+ return ner_pipeline
19
+
20
+ ner = load_model()
21
+
22
+ # Input from user
23
+ text_input = st.text_area("Enter a medical sentence below:",
24
+ "The patient was diagnosed with diabetes mellitus and rheumatoid arthritis.")
25
+
26
+ # Run model when button is clicked
27
+ if st.button("Find Disease Entities"):
28
+ if text_input.strip() == "":
29
+ st.warning("Please enter some text.")
30
+ else:
31
+ results = ner(text_input)
32
+
33
+ if results:
34
+ st.subheader("🧬 Disease Entities Found:")
35
+ for e in results:
36
+ st.markdown(f"- **{e['word']}** ({e['entity_group']}) – Score: `{e['score']:.2f}`")
37
+ else:
38
+ st.info("No disease entities found in the given text.")