masif's picture
Update app.py file (#6)
deb89a3 verified
Raw
History Blame
4.23 kB
import gradio as gr
from service import GPT_Service, Stage
# Define the function to be called when the button is clicked
def process_text(keywords, stage, medical_history):
if(keywords.strip()!='' and stage!=None and len(stage)!=0):
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')
# Create text input components with labels
input_text = gr.Textbox(lines=7, label="Sample keywords", placeholder="Enter sample keywords here")
medical_history = gr.Textbox(lines=7, label="Medical History", placeholder="Enter medical history here")
# Populating stage choices and creating dropdown component with label
# To add all the stages
# stage_choices = [stage.value for stage in Stage]
# To add few stages
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="Stage")
# Create output containers
output_text_1 = gr.Textbox(lines=6, label="Variant 1", show_copy_button=True)
output_text_2 = gr.Textbox(lines=6, label="Variant 2", show_copy_button=True)
output_text_3 = gr.Textbox(lines=6, label="Variant 3", show_copy_button=True)
title_html = """
<div style="display: flex; align-items: center; width=100%; background-color:#FFC90E; overflow:auto;">
<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 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
</span>
</div>
"""
# Create a Gradio interface
interface=gr.Interface(fn=process_text,
inputs=[input_text, stage, medical_history],
outputs=[output_text_1,output_text_2,output_text_3],
title=title_html,
theme=gr.themes.Default(),
allow_flagging='never')
interface.launch()