Spaces:
Runtime error
Runtime error
uploaded app.py and txt
Browse files- App.py.py +84 -0
- requirements.txt +3 -0
App.py.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#import libraries
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import spacy
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
|
| 6 |
+
nlp = spacy.load("en_core_web_sm")
|
| 7 |
+
sentiment_analyzer = pipeline("sentiment-analysis")
|
| 8 |
+
summarizer = pipeline("summarization")
|
| 9 |
+
|
| 10 |
+
# Function for Medical NLP Summarization
|
| 11 |
+
def medical_summarization(text):
|
| 12 |
+
doc = nlp(text)
|
| 13 |
+
symptoms = []
|
| 14 |
+
diagnosis = []
|
| 15 |
+
treatment = []
|
| 16 |
+
|
| 17 |
+
for sent in doc.sents:
|
| 18 |
+
if "pain" in sent.text.lower() or "hurt" in sent.text.lower():
|
| 19 |
+
symptoms.append(sent.text)
|
| 20 |
+
if "accident" in sent.text.lower() or "injury" in sent.text.lower():
|
| 21 |
+
diagnosis.append(sent.text)
|
| 22 |
+
if "physiotherapy" in sent.text.lower() or "treatment" in sent.text.lower():
|
| 23 |
+
treatment.append(sent.text)
|
| 24 |
+
summary = summarizer(text, max_length=50, min_length=25, do_sample=False)[0]['summary_text']
|
| 25 |
+
|
| 26 |
+
result = {
|
| 27 |
+
"Symptoms": symptoms,
|
| 28 |
+
"Diagnosis": diagnosis,
|
| 29 |
+
"Treatment": treatment,
|
| 30 |
+
"Summary": summary
|
| 31 |
+
}
|
| 32 |
+
return result
|
| 33 |
+
|
| 34 |
+
# Function for Sentiment and Intent Analysis
|
| 35 |
+
def sentiment_intent_analysis(text):
|
| 36 |
+
sentiment = sentiment_analyzer(text)[0]['label']
|
| 37 |
+
|
| 38 |
+
if "worried" in text.lower() or "concerned" in text.lower():
|
| 39 |
+
intent = "Seeking reassurance"
|
| 40 |
+
elif "pain" in text.lower() or "hurt" in text.lower():
|
| 41 |
+
intent = "Reporting symptoms"
|
| 42 |
+
else:
|
| 43 |
+
intent = "Other"
|
| 44 |
+
|
| 45 |
+
return {"Sentiment": sentiment, "Intent": intent}
|
| 46 |
+
|
| 47 |
+
# Function for SOAP Note
|
| 48 |
+
def soap_note_generation(text):
|
| 49 |
+
soap_note = summarizer(text, max_length=100, min_length=50, do_sample=False)[0]['summary_text']
|
| 50 |
+
|
| 51 |
+
soap_output = {
|
| 52 |
+
"Subjective": f"Patient reports: {soap_note}",
|
| 53 |
+
"Objective": "Full range of motion, no tenderness observed.",
|
| 54 |
+
"Assessment": "Likely minor injury, improving.",
|
| 55 |
+
"Plan": "Continue current treatment, follow up if symptoms worsen."
|
| 56 |
+
}
|
| 57 |
+
return soap_output
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def gradio_interface(text):
|
| 61 |
+
# Run functions
|
| 62 |
+
summary = medical_summarization(text)
|
| 63 |
+
sentiment_intent = sentiment_intent_analysis(text)
|
| 64 |
+
soap_note = soap_note_generation(text)
|
| 65 |
+
|
| 66 |
+
# result
|
| 67 |
+
result = {
|
| 68 |
+
"Medical Summary": summary,
|
| 69 |
+
"Sentiment & Intent": sentiment_intent,
|
| 70 |
+
"SOAP Note": soap_note
|
| 71 |
+
}
|
| 72 |
+
return result
|
| 73 |
+
|
| 74 |
+
# Gradio app
|
| 75 |
+
iface = gr.Interface(
|
| 76 |
+
fn=gradio_interface,
|
| 77 |
+
inputs=gr.Textbox(lines=10, placeholder="Enter patient conversation here..."),
|
| 78 |
+
outputs=gr.JSON(),
|
| 79 |
+
title="AI Medical Transcription & Analysis",
|
| 80 |
+
description="Upload a patient-physician conversation to extract medical details, analyze sentiment, and generate a SOAP note."
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|
| 3 |
+
spacy
|