Spaces:
Sleeping
Sleeping
Aishwarya Solanki
commited on
Commit
·
5170879
1
Parent(s):
41a6604
updating UI
Browse files
app.py
CHANGED
@@ -102,7 +102,7 @@ def sanitize_outputs(outputs):
|
|
102 |
for output in outputs:
|
103 |
output = output.replace("\n", " ")
|
104 |
output = re.sub(r"(Diagnose:|Answer:)", "", output, flags=re.IGNORECASE).strip()
|
105 |
-
diagnoses = ["Psoriasis", "Arthritis", "Bronchial
|
106 |
found_diagnoses = [disease for disease in diagnoses if disease in output]
|
107 |
|
108 |
if found_diagnoses:
|
@@ -117,8 +117,8 @@ def diagnose(gpt_key, llama_key, gemini_key, top_p, temperature, symptoms):
|
|
117 |
|
118 |
if symptoms:
|
119 |
prompt = "Given the next set of symptoms, classify the diagnosis as one of the following: "
|
120 |
-
prompt += "Psoriasis, Arthritis, Bronchial
|
121 |
-
prompt += "Choose only one among the words Psoriasis, Arthritis, Bronchial
|
122 |
prompt += "Do not list the symptoms again in the response. Do not add any additional text. Do not attempt to explain your answer."
|
123 |
prompt += symptoms
|
124 |
prompt += "Your Diagnosis: []"
|
@@ -132,33 +132,10 @@ def diagnose(gpt_key, llama_key, gemini_key, top_p, temperature, symptoms):
|
|
132 |
majority_output, majority_count = output_counts.most_common(1)[0]
|
133 |
confidence = int((majority_count / len(outputs)) * 100)
|
134 |
|
135 |
-
|
136 |
-
message = "LLMs do not seem to agree on one output." + "\n"
|
137 |
-
message += " GPT output: " + gpt_message + "\n"
|
138 |
-
message += " Llama output: " + llama_message + "\n"
|
139 |
-
message += " Gemini output: " + gemini_message + "\n"
|
140 |
-
message += " Majority output: " + majority_output + "\n"
|
141 |
-
message += " Confidence score: " + str(confidence) + "%"
|
142 |
-
elif confidence > 50:
|
143 |
-
message = "LLMs seem to agree on one output." + "\n"
|
144 |
-
message += " GPT output: " + gpt_message + "\n"
|
145 |
-
message += " Llama output: " + llama_message + "\n"
|
146 |
-
message += " Gemini output: " + gemini_message + "\n"
|
147 |
-
message += " Majority output: " + majority_output + "\n"
|
148 |
-
message += " Confidence score: " + str(confidence) + "%"
|
149 |
-
elif confidence >= 100:
|
150 |
-
message = "All LLMs agree on the same output." + "\n"
|
151 |
-
message += " GPT output: " + gpt_message + "\n"
|
152 |
-
message += " Llama output: " + llama_message + "\n"
|
153 |
-
message += " Gemini output: " + gemini_message + "\n"
|
154 |
-
message += " Majority output: " + majority_output + "\n"
|
155 |
-
message += " Confidence score: " + str(confidence) + "%"
|
156 |
-
else:
|
157 |
-
message = "Confidence output is not a valid value, please check what is wrong."
|
158 |
else:
|
159 |
-
message = "Please add the symptoms data to start the ranking process
|
160 |
-
|
161 |
-
return message
|
162 |
|
163 |
def update_model_components(selected_model):
|
164 |
model_map = {
|
@@ -211,8 +188,15 @@ with gr.Blocks() as ui:
|
|
211 |
symptoms = gr.Textbox(label="Add the symptom data in the input to receive diagnosis")
|
212 |
llm_btn = gr.Button(value="Diagnose Disease", variant="primary", elem_id="diagnose", interactive=False)
|
213 |
symptoms.input(toggle_button, inputs=[symptoms, gpt_key, llama_key, gemini_key], outputs=llm_btn)
|
214 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
llm_btn.click(fn=diagnose, inputs=[gpt_key, llama_key, gemini_key, top_p, temperature, symptoms],
|
216 |
-
outputs=
|
217 |
|
218 |
ui.launch(share=True)
|
|
|
102 |
for output in outputs:
|
103 |
output = output.replace("\n", " ")
|
104 |
output = re.sub(r"(Diagnose:|Answer:)", "", output, flags=re.IGNORECASE).strip()
|
105 |
+
diagnoses = ["Psoriasis", "Arthritis", "Bronchial Asthma", "Cervical spondylosis"]
|
106 |
found_diagnoses = [disease for disease in diagnoses if disease in output]
|
107 |
|
108 |
if found_diagnoses:
|
|
|
117 |
|
118 |
if symptoms:
|
119 |
prompt = "Given the next set of symptoms, classify the diagnosis as one of the following: "
|
120 |
+
prompt += "Psoriasis, Arthritis, Bronchial Asthma, Cervical spondylosis. Please only output the classified diagnosis and nothing after that."
|
121 |
+
prompt += "Choose only one among the words Psoriasis, Arthritis, Bronchial Asthma or Cervical spondylosis"
|
122 |
prompt += "Do not list the symptoms again in the response. Do not add any additional text. Do not attempt to explain your answer."
|
123 |
prompt += symptoms
|
124 |
prompt += "Your Diagnosis: []"
|
|
|
132 |
majority_output, majority_count = output_counts.most_common(1)[0]
|
133 |
confidence = int((majority_count / len(outputs)) * 100)
|
134 |
|
135 |
+
return gpt_message, llama_message, gemini_message, majority_output, confidence
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
else:
|
137 |
+
return {"is_valid": False, "message": f'<p style="color: red;">Please add the symptoms data to start the ranking process.</p>'}
|
138 |
+
|
|
|
139 |
|
140 |
def update_model_components(selected_model):
|
141 |
model_map = {
|
|
|
188 |
symptoms = gr.Textbox(label="Add the symptom data in the input to receive diagnosis")
|
189 |
llm_btn = gr.Button(value="Diagnose Disease", variant="primary", elem_id="diagnose", interactive=False)
|
190 |
symptoms.input(toggle_button, inputs=[symptoms, gpt_key, llama_key, gemini_key], outputs=llm_btn)
|
191 |
+
with gr.Row(equal_height=200):
|
192 |
+
with gr.Column(scale=1, min_width=150):
|
193 |
+
gpt_message = gr.Textbox(label="GPT Output", interactive=False, placeholder="GPT Output")
|
194 |
+
llama_message = gr.Textbox(label="LLaMA Output", interactive=False, placeholder="LLaMA Output")
|
195 |
+
gemini_message = gr.Textbox(label="Gemini Output", interactive=False, placeholder="Gemini Output")
|
196 |
+
majority_output = gr.Textbox(label="Majority Output", interactive=False, placeholder="Majority Output")
|
197 |
+
confidence = gr.Textbox(label="Confidence Score (%)", interactive=False, placeholder="Confidence Score")
|
198 |
+
|
199 |
llm_btn.click(fn=diagnose, inputs=[gpt_key, llama_key, gemini_key, top_p, temperature, symptoms],
|
200 |
+
outputs=[gpt_message, llama_message, gemini_message, majority_output, confidence], api_name="LLM_Comparator")
|
201 |
|
202 |
ui.launch(share=True)
|