-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
112 lines (92 loc) · 3.67 KB
/
Copy pathapp.py
File metadata and controls
112 lines (92 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import streamlit as st
import spacy
from transformers import pipeline
from textblob import TextBlob
import json
# Load the SciSpacy model
nlp = spacy.load("en_core_sci_md") # Ensure you have this model installed
# Load the summarization model from transformers
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
# Function to extract medical entities
def extract_medical_entities(transcript):
doc = nlp(transcript)
entities = {
"symptoms": [],
"diagnosis": [],
"treatment": [],
"prognosis": []
}
for ent in doc.ents:
if ent.label_ == "SYMPTOM":
entities["symptoms"].append(ent.text)
elif ent.label_ == "DIAGNOSIS":
entities["diagnosis"].append(ent.text)
elif ent.label_ == "TREATMENT":
entities["treatment"].append(ent.text)
elif ent.label_ == "PROGNOSIS":
entities["prognosis"].append(ent.text)
return entities
# Function to generate summary using transformers
def generate_summary(transcript):
# The model expects input text to be less than 1024 tokens
max_input_length = 1024
if len(transcript) > max_input_length:
transcript = transcript[:max_input_length]
summary = summarizer(transcript, max_length=150, min_length=30, do_sample=False)
return summary[0]['summary_text']
# Function for sentiment analysis
def analyze_sentiment(dialogue):
analysis = TextBlob(dialogue)
return "Anxious" if analysis.sentiment.polarity < 0 else "Reassured"
# Function to generate SOAP note
def generate_soap(entities):
soap_note = {
"Subjective": {
"Chief_Complaint": ", ".join(entities["symptoms"]),
"History_of_Present_Illness": "Patient reported symptoms related to the accident."
},
"Objective": {
"Physical_Exam": "Full range of motion, no tenderness.",
"Observations": "Patient appears in normal health."
},
"Assessment": {
"Diagnosis": ", ".join(entities["diagnosis"]),
"Severity": "Mild, improving"
},
"Plan": {
"Treatment": ", ".join(entities["treatment"]),
"Follow-Up": "Patient to return if symptoms worsen."
}
}
return soap_note
# Streamlit UI
st.title("Medical Transcription using NLP")
st.markdown("👋 Welcome! This application helps in medical transcription, summarization, and sentiment analysis.")
# Input section
transcript = st.text_area("Enter the Physician-Patient Conversation Transcript", height=300)
if st.button("Analyze"):
if transcript:
# Extract medical entities
entities = extract_medical_entities(transcript)
# Generate summary
summary = generate_summary(transcript)
# Analyze sentiment
sentiment = analyze_sentiment(transcript)
# Generate SOAP note
soap_note = generate_soap(entities)
# Display results
st.subheader("Extracted Medical Entities")
st.json(entities)
st.subheader("Summary")
st.write(summary)
st.subheader("Sentiment Analysis")
st.write(f"Sentiment: {sentiment}")
st.subheader("SOAP Note")
st.json(soap_note)
else:
st.warning("Please enter a transcript to analyze.")
# Footer
st.markdown("---")
st.markdown("### About This App")
st.markdown("This app uses NLP techniques to assist healthcare professionals in documenting patient interactions.")
st.markdown("Made by Syed Abdul Kareem Ahmed as Assignment : Emitrr")