CoolFace
Apppublic

technosoft/TechnosoftSolutions

sourceHugging Faceotherupdated 2y agoView on Hugging Face
0likes
app.py148 linesDownload Raw Back to root
1import gradio as gr2from service import GPT_Service, Stage3 4 5title_html = """6<div style="display: flex; align-items: center; width=100%; background-color:#FFC90E; border-radius:10px;">7    <img src='https://i.ibb.co/gPFskvg/LOGO-1.png' style='height: 90px; width:90px; margin-left: 20px;'>8    <span style="margin-left: 20px;font-size:30px">9        <span>Patient Assessment Documentation</span>10    </span>11</div>12 13"""14 15css = """16#subButton, #rephraseBtn {17    background-color: #EA580C !important;18    background: #EA580C !important;19    color: #FFFFFF !important;20    border: none !important; /* Remove the border */21    transition: background-color 0.3s ease; /* Add transition for smoother hover effect */22}23 24#subButton:hover, #rephraseBtn:hover {25    color: #EA580C !important;26    background-color: #FFC90E !important; /* Change to a lighter background color on hover */27}28 29"""30 31def split_based_on_commas(string):32    return [substring.strip() for substring in string.split(",")]33 34def process_text(keywords, stage, medical_history):35    if(keywords.strip()!='' and stage!=None and len(stage)!=0 and  len(split_based_on_commas(keywords))<=5):36        try:37            gptService=GPT_Service()38            if stage == Stage.INITIAL_ASSESSMENT.value:39                options = gptService.getInitialAssessment(keywords,medical_history)40                return gr.update(choices=options, value="", interactive=True)41            elif stage == Stage.FOLLOWUP_ASSESSMENT.value:42                options = gptService.getFollowUpAssessment(keywords,medical_history)43                return gr.update(choices=options, value="", interactive=True)44            elif stage == Stage.EVALUATION.value:45                options = gptService.getEvaluation(keywords,medical_history)46                return gr.update(choices=options, value="", interactive=True)47            elif stage == Stage.DETAILED_EVALUATION.value:48                options = gptService.getDetailedEvaluation(keywords,medical_history)49                return gr.update(choices=options, value="", interactive=True)50            elif stage == Stage.PROGRESS_NOTE.value:51                options = gptService.getProgressNote(keywords,medical_history)52                return gr.update(choices=options, value="", interactive=True)53            elif stage == Stage.DISCHARGE_SUMMARY.value:54                options = gptService.getDischargeSummary(keywords,medical_history)55                return gr.update(choices=options, value="", interactive=True)56            elif stage == Stage.SHORT_TERM_GOALS.value:57                options = gptService.getShortTermGoals(keywords,medical_history)58                return gr.update(choices=options, value="", interactive=True)59            elif stage == Stage.LONG_TERM_GOALS.value:60                options = gptService.getLongTermGoals(keywords,medical_history)61                return gr.update(choices=options, value="", interactive=True)62            elif stage == Stage.RECOMMENDATION.value:63                options =  gptService.getRecommendation(keywords,medical_history)64                return gr.update(choices=options, value="", interactive=True)65            else:66                print("Unknown stage")67                raise gr.Error('Unknown stage encountered')68        except:69            print("GPT error encounters")70            raise gr.Error('Something went wrong please try again')71    else:72        print("Unknown stage parameters")73        raise gr.Error('Provide appropriate parameters and try again')74 75    76def clear_input(response):77    return gr.update(value="")78 79 80def getPatientAssessment(sentences,stage, medical_history):81 82    if(sentences is None or len(sentences) == 0 or stage is None):83        raise gr.Error('Provide appropriate parameters and try again')84    else:85        try:86            gptService=GPT_Service()87            if stage == Stage.INITIAL_ASSESSMENT.value:88                return gptService.getDetailInitialAssessment(medical_history,sentences)89            elif stage == Stage.SHORT_TERM_GOALS.value:90                return gptService.getDetailShortTermGoals(medical_history,sentences)91            elif stage == Stage.LONG_TERM_GOALS.value:92                return gptService.getDetailLongTermGoals(medical_history,sentences)93            elif stage == Stage.RECOMMENDATION.value:94                return gptService.getDetailRecommendation(medical_history,sentences)95            else:96                print("Unknown stage")97                raise gr.Error('Unknown stage encountered')98        except:99            print("GPT error encounters")100            raise gr.Error('Something went wrong please try again')101        102           103def getRephrasedSentences(sentences):104    if (sentences is None or sentences.strip() == ''):105          raise gr.Error('Provide appropriate parameters and try again')106    else:107        try:108            gptService=GPT_Service()109            return gptService.getRephrasedPatientAssessment(sentences)110        except:111            raise gr.Error('Something went wrong please try again')112          113 114with gr.Blocks(css=css) as demo:115    gr.HTML(title_html)116    gr.HTML("<h2>Step 1:- Patient Assessment Input</h2>")117    with gr.Row():118        keywords = gr.Textbox(label="Keywords", placeholder="Write comma separated sample keywords (max=5)")119        medicalHistory = gr.Textbox(label="Medical History", placeholder="Enter patient history")120        stage_choices = [Stage.INITIAL_ASSESSMENT.value,Stage.SHORT_TERM_GOALS.value,Stage.LONG_TERM_GOALS.value, Stage.RECOMMENDATION.value]121        stage = gr.Dropdown(choices=stage_choices, label="Assessment Stage")122    123    with gr.Row():124        clearInputFields = gr.ClearButton(value="Clear Inputs",components=[keywords,medicalHistory,stage])125        responseButton = gr.Button("Submit",elem_id="subButton")126 127 128    with gr.Column(scale=2):129        gr.HTML("<h2>Step 2:- Keyword-Driven Sentence Analysis</h2>")130        selectedSentence = gr.Dropdown(choices=[], show_label=False,interactive=False,multiselect=True)131    132    133    with gr.Row():134        clearSelectedSentences = gr.Button(value="Clear Selection")135        detailAssessmentButton = gr.Button("Generate Summary",elem_id="rephraseBtn",)136 137    with gr.Column():138        gr.HTML("<h2>Step 3:- Patient Assessment Summary</h2>")139        patientDetailAssessment=gr.Textbox(show_label=False, interactive=False, show_copy_button=True,lines=15)140        rephraseButton = gr.Button("I don't like response, Generate New :)",elem_id="rephraseBtn",)141 142    responseButton.click(process_text,[keywords,stage,medicalHistory],[selectedSentence])143    detailAssessmentButton.click(getPatientAssessment,[selectedSentence,stage,medicalHistory],patientDetailAssessment)144    rephraseButton.click(getPatientAssessment,[selectedSentence,stage,medicalHistory],patientDetailAssessment)145    clearSelectedSentences.click(clear_input,inputs=[selectedSentence],outputs=[selectedSentence])146    147        148demo.launch(share=True)