import gradio as gr
from service import GPT_Service, Stage
title_html = """
Patient Assessment Documentation
"""
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("Step 1:- Patient Assessment Input
")
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("Step 2:- Keyword-Driven Sentence Analysis
")
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("Step 3:- Patient Assessment Summary
")
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)