healthdocs / app.py
umar-ts's picture
Update app.py
7163109 verified
Raw
History Blame
10.5 kB
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'
border: none !important; /* Remove the border */
transition: background-color 0.3s ease; /* Add transition for smoother hover effect */
}
#subButton:hover, #rephraseBtn:hover {
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:
return gptService.getInitialAssessment(keywords,medical_history)
elif stage == Stage.FOLLOWUP_ASSESSMENT.value:
return gptService.getFollowUpAssessment(keywords,medical_history)
elif stage == Stage.EVALUATION.value:
return gptService.getEvaluation(keywords,medical_history)
elif stage == Stage.DETAILED_EVALUATION.value:
return gptService.getDetailedEvaluation(keywords,medical_history)
elif stage == Stage.PROGRESS_NOTE.value:
return gptService.getProgressNote(keywords,medical_history)
elif stage == Stage.DISCHARGE_SUMMARY.value:
return gptService.getDischargeSummary(keywords,medical_history)
elif stage == Stage.SHORT_TERM_GOALS.value:
return gptService.getShortTermGoals(keywords,medical_history)
elif stage == Stage.LONG_TERM_GOALS.value:
return gptService.getLongTermGoals(keywords,medical_history)
elif stage == Stage.RECOMMENDATION.value:
return gptService.getRecommendation(keywords,medical_history)
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 select_handler(prevResponse, newResponse):
if newResponse.strip() not in prevResponse:
return f"{prevResponse + (' ' if prevResponse.strip() != '' else '')} {newResponse}"
else:
return prevResponse
def clear_input(response):
return ""
def getRephrasedSentences(sentences):
if sentences.strip() == '':
raise gr.Error('Provide appropriate parameters and try again')
else:
try:
print(sentences)
gptService=GPT_Service()
return gptService.getRephrasedSentences(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>Patient Assessment Input</h2>")
with gr.Row():
keywords = gr.Textbox(label="Assessment 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.Row():
with gr.Column(scale=2):
gr.HTML("<h2>Suggested Assessment Documentation</h2>")
label1 = gr.Markdown(value="Keyword 1",show_label=False)
with gr.Row() as firstKeywordResponses:
firstKeywordResponseUtterance1 = gr.Textbox(label="Variant 1",interactive=False, show_copy_button=True)
firstKeywordResponseUtterance2 = gr.Textbox(label="Variant 2", interactive=False, show_copy_button=True)
firstKeywordResponseUtterance3 = gr.Textbox(label="Variant 3", interactive=False, show_copy_button=True)
label2 = gr.Markdown(value="Keyword 2",show_label=False)
with gr.Row() as secondKeywordResponses:
secondKeywordResponseUtterance1 = gr.Textbox(label="Variant 1", interactive=False, show_copy_button=True)
secondKeywordResponseUtterance2 = gr.Textbox(label="Variant 2", interactive=False, show_copy_button=True)
secondKeywordResponseUtterance3 = gr.Textbox(label="Variant 3", interactive=False, show_copy_button=True)
label3 = gr.Markdown(value="Keyword 3",show_label=False)
with gr.Row() as thirdKeywordResponses:
thirdKeywordResponseUtterance1 = gr.Textbox(label="Variant 1", interactive=False, show_copy_button=True)
thirdKeywordResponseUtterance2 = gr.Textbox(label="Variant 2", interactive=False, show_copy_button=True)
thirdKeywordResponseUtterance3 = gr.Textbox(label="Variant 3", interactive=False, show_copy_button=True)
label4 = gr.Markdown(value="Keyword 4",show_label=False)
with gr.Row() as fourthKeywordResponses:
fourthKeywordResponseUtterance1 = gr.Textbox(label="Variant 1", interactive=False, show_copy_button=True)
fourthKeywordResponseUtterance2 = gr.Textbox(label="Variant 2", interactive=False, show_copy_button=True)
fourthKeywordResponseUtterance3 = gr.Textbox(label="Variant 3", interactive=False, show_copy_button=True)
label5 = gr.Markdown(value="Keyword 5",show_label=False)
with gr.Row() as fifthKeywordResponses:
fifthKeywordResponseUtterance1 = gr.Textbox(label="Variant 1", interactive=False, show_copy_button=True)
fifthKeywordResponseUtterance2 = gr.Textbox(label="Variant 2", interactive=False, show_copy_button=True)
fifthKeywordResponseUtterance3 = gr.Textbox(label="Variant 3", interactive=False, show_copy_button=True)
with gr.Column(scale=1):
gr.HTML("<h2>Documentation Generator</h2>")
with gr.Row():
with gr.Column():
selectedSentence=gr.Textbox(label="Selected Sentences", show_copy_button=True,lines=15)
with gr.Row():
clearSelectedSentences= gr.Button("Clear")
rephraseButton = gr.Button("Generate Documentation",elem_id="rephraseBtn",)
rephrasedSentence=gr.Textbox(label="Patient Visit Documentation", interactive=False, show_copy_button=True,lines=15)
# First response event listeners
firstKeywordResponseUtterance1.select(select_handler,[selectedSentence,firstKeywordResponseUtterance1],selectedSentence)
firstKeywordResponseUtterance2.select(select_handler,[selectedSentence,firstKeywordResponseUtterance2],selectedSentence)
firstKeywordResponseUtterance3.select(select_handler,[selectedSentence,firstKeywordResponseUtterance3],selectedSentence)
# Second response event listeners
secondKeywordResponseUtterance1.select(select_handler,[selectedSentence,secondKeywordResponseUtterance1],selectedSentence)
secondKeywordResponseUtterance2.select(select_handler,[selectedSentence,secondKeywordResponseUtterance2],selectedSentence)
secondKeywordResponseUtterance3.select(select_handler,[selectedSentence,secondKeywordResponseUtterance3],selectedSentence)
# Third response event listeners
thirdKeywordResponseUtterance1.select(select_handler,[selectedSentence,thirdKeywordResponseUtterance1],selectedSentence)
thirdKeywordResponseUtterance2.select(select_handler,[selectedSentence,thirdKeywordResponseUtterance2],selectedSentence)
thirdKeywordResponseUtterance3.select(select_handler,[selectedSentence,thirdKeywordResponseUtterance3],selectedSentence)
# Fourth response event listeners
fourthKeywordResponseUtterance1.select(select_handler,[selectedSentence,fourthKeywordResponseUtterance1],selectedSentence)
fourthKeywordResponseUtterance2.select(select_handler,[selectedSentence,fourthKeywordResponseUtterance2],selectedSentence)
fourthKeywordResponseUtterance3.select(select_handler,[selectedSentence,fourthKeywordResponseUtterance3],selectedSentence)
# Fifth response event listeners
fifthKeywordResponseUtterance1.select(select_handler,[selectedSentence,fifthKeywordResponseUtterance1],selectedSentence)
fifthKeywordResponseUtterance2.select(select_handler,[selectedSentence,fifthKeywordResponseUtterance2],selectedSentence)
fifthKeywordResponseUtterance3.select(select_handler,[selectedSentence,fifthKeywordResponseUtterance3],selectedSentence)
responseButton.click(process_text,[keywords,stage,medicalHistory],[label1,firstKeywordResponseUtterance1,firstKeywordResponseUtterance2,firstKeywordResponseUtterance3,
label2,secondKeywordResponseUtterance1,secondKeywordResponseUtterance2,secondKeywordResponseUtterance3,
label3,thirdKeywordResponseUtterance1,thirdKeywordResponseUtterance2,thirdKeywordResponseUtterance3,
label4,fourthKeywordResponseUtterance1,fourthKeywordResponseUtterance2,fourthKeywordResponseUtterance3,
label5,fifthKeywordResponseUtterance1,fifthKeywordResponseUtterance2,fifthKeywordResponseUtterance3])
rephraseButton.click(getRephrasedSentences,selectedSentence,rephrasedSentence)
clearSelectedSentences.click(clear_input,selectedSentence,selectedSentence)
demo.launch()