Spaces:
Sleeping
Sleeping
File size: 6,948 Bytes
9270f6b 1b80b66 9270f6b 1b80b66 9270f6b 1b80b66 9270f6b 1b80b66 9270f6b 1b80b66 9270f6b 1b80b66 9270f6b 1b80b66 9270f6b 1b80b66 9270f6b 1b80b66 9270f6b 1b80b66 daf7dea 1b80b66 9270f6b 1b80b66 9270f6b 1b80b66 deb89a3 1b80b66 deb89a3 1b80b66 9270f6b deb89a3 1b80b66 deb89a3 1b80b66 deb89a3 1b80b66 | 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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | import gradio as gr
from service import GPT_Service, Stage
title_html = """
<div style="display: flex; align-items: center; width=100%; background-color:#FFC90E; border-radius:10px;">
<img src='https://i.ibb.co/gPFskvg/LOGO-1.png' style='height: 90px; width:90px; margin-left: 20px;'>
<span style="margin-left: 20px;font-size:30px">
<span>Patient Assessment Documentation</span>
</span>
</div>
"""
css = """
#subButton, #rephraseBtn {
background-color: #EA580C !important;
background: #EA580C !important;
color: #FFFFFF !important;
border: none !important; /* Remove the border */
transition: background-color 0.3s ease; /* Add transition for smoother hover effect */
}
#subButton:hover, #rephraseBtn:hover {
color: #EA580C !important;
background-color: #FFC90E !important; /* Change to a lighter background color on hover */
}
"""
def split_based_on_commas(string):
return [substring.strip() for substring in string.split(",")]
def process_text(keywords, stage, medical_history):
if(keywords.strip()!='' and stage!=None and len(stage)!=0 and len(split_based_on_commas(keywords))<=5):
try:
gptService=GPT_Service()
if stage == Stage.INITIAL_ASSESSMENT.value:
options = gptService.getInitialAssessment(keywords,medical_history)
return gr.update(choices=options, value="", interactive=True)
elif stage == Stage.FOLLOWUP_ASSESSMENT.value:
options = gptService.getFollowUpAssessment(keywords,medical_history)
return gr.update(choices=options, value="", interactive=True)
elif stage == Stage.EVALUATION.value:
options = gptService.getEvaluation(keywords,medical_history)
return gr.update(choices=options, value="", interactive=True)
elif stage == Stage.DETAILED_EVALUATION.value:
options = gptService.getDetailedEvaluation(keywords,medical_history)
return gr.update(choices=options, value="", interactive=True)
elif stage == Stage.PROGRESS_NOTE.value:
options = gptService.getProgressNote(keywords,medical_history)
return gr.update(choices=options, value="", interactive=True)
elif stage == Stage.DISCHARGE_SUMMARY.value:
options = gptService.getDischargeSummary(keywords,medical_history)
return gr.update(choices=options, value="", interactive=True)
elif stage == Stage.SHORT_TERM_GOALS.value:
options = gptService.getShortTermGoals(keywords,medical_history)
return gr.update(choices=options, value="", interactive=True)
elif stage == Stage.LONG_TERM_GOALS.value:
options = gptService.getLongTermGoals(keywords,medical_history)
return gr.update(choices=options, value="", interactive=True)
elif stage == Stage.RECOMMENDATION.value:
options = gptService.getRecommendation(keywords,medical_history)
return gr.update(choices=options, value="", interactive=True)
else:
print("Unknown stage")
raise gr.Error('Unknown stage encountered')
except:
print("GPT error encounters")
raise gr.Error('Something went wrong please try again')
else:
print("Unknown stage parameters")
raise gr.Error('Provide appropriate parameters and try again')
def clear_input(response):
return gr.update(value="")
def getPatientAssessment(sentences,stage, medical_history):
if(sentences is None or len(sentences) == 0 or stage is None):
raise gr.Error('Provide appropriate parameters and try again')
else:
try:
gptService=GPT_Service()
if stage == Stage.INITIAL_ASSESSMENT.value:
return gptService.getDetailInitialAssessment(medical_history,sentences)
elif stage == Stage.SHORT_TERM_GOALS.value:
return gptService.getDetailShortTermGoals(medical_history,sentences)
elif stage == Stage.LONG_TERM_GOALS.value:
return gptService.getDetailLongTermGoals(medical_history,sentences)
elif stage == Stage.RECOMMENDATION.value:
return gptService.getDetailRecommendation(medical_history,sentences)
else:
print("Unknown stage")
raise gr.Error('Unknown stage encountered')
except:
print("GPT error encounters")
raise gr.Error('Something went wrong please try again')
def getRephrasedSentences(sentences):
if (sentences is None or sentences.strip() == ''):
raise gr.Error('Provide appropriate parameters and try again')
else:
try:
gptService=GPT_Service()
return gptService.getRephrasedPatientAssessment(sentences)
except:
raise gr.Error('Something went wrong please try again')
with gr.Blocks(css=css) as demo:
gr.HTML(title_html)
gr.HTML("<h2>Step 1:- Patient Assessment Input</h2>")
with gr.Row():
keywords = gr.Textbox(label="Keywords", placeholder="Write comma separated sample keywords (max=5)")
medicalHistory = gr.Textbox(label="Medical History", placeholder="Enter patient history")
stage_choices = [Stage.INITIAL_ASSESSMENT.value,Stage.SHORT_TERM_GOALS.value,Stage.LONG_TERM_GOALS.value, Stage.RECOMMENDATION.value]
stage = gr.Dropdown(choices=stage_choices, label="Assessment Stage")
with gr.Row():
clearInputFields = gr.ClearButton(value="Clear Inputs",components=[keywords,medicalHistory,stage])
responseButton = gr.Button("Submit",elem_id="subButton")
with gr.Column(scale=2):
gr.HTML("<h2>Step 2:- Keyword-Driven Sentence Analysis</h2>")
selectedSentence = gr.Dropdown(choices=[], show_label=False,interactive=False,multiselect=True)
with gr.Row():
clearSelectedSentences = gr.Button(value="Clear Selection")
detailAssessmentButton = gr.Button("Generate Summary",elem_id="rephraseBtn",)
with gr.Column():
gr.HTML("<h2>Step 3:- Patient Assessment Summary</h2>")
patientDetailAssessment=gr.Textbox(show_label=False, interactive=False, show_copy_button=True,lines=15)
rephraseButton = gr.Button("I don't like response, Generate New :)",elem_id="rephraseBtn",)
responseButton.click(process_text,[keywords,stage,medicalHistory],[selectedSentence])
detailAssessmentButton.click(getPatientAssessment,[selectedSentence,stage,medicalHistory],patientDetailAssessment)
rephraseButton.click(getPatientAssessment,[selectedSentence,stage,medicalHistory],patientDetailAssessment)
clearSelectedSentences.click(clear_input,inputs=[selectedSentence],outputs=[selectedSentence])
demo.launch(share=True) |