Aishwarya Solanki commited on
Commit
d5c067b
·
1 Parent(s): 788d5cb

Refining UI

Browse files
Files changed (1) hide show
  1. app.py +30 -7
app.py CHANGED
@@ -116,7 +116,8 @@ def sanitize_outputs(outputs):
116
  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: Psoriasis, Arthritis, Bronchial asthma, Cervical spondylosis. Please only output the classified diagnosis and nothing after that."
 
120
  prompt += "Choose only one among the words Psoriasis, Arthritis, Bronchial asthma or Cervical spondylosis"
121
  prompt += "Do not list the symptoms again in the response. Do not add any additional text. Do not attempt to explain your answer."
122
  prompt += symptoms
@@ -129,12 +130,34 @@ def diagnose(gpt_key, llama_key, gemini_key, top_p, temperature, symptoms):
129
  outputs = sanitize_outputs(outputs)
130
  output_counts = Counter(outputs)
131
  majority_output, majority_count = output_counts.most_common(1)[0]
132
- confidence = (majority_count / len(outputs)) * 100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  else:
134
- majority_output = "Please add the symptoms data to start the ranking process."
135
- confidence = 0
136
 
137
- return outputs, majority_output, confidence
138
 
139
  def update_model_components(selected_model):
140
  model_map = {
@@ -188,7 +211,7 @@ with gr.Blocks() as ui:
188
  llm_btn = gr.Button(value="Diagnose Disease", variant="primary", elem_id="diagnose", interactive=False)
189
  symptoms.input(toggle_button, inputs=[symptoms, gpt_key, llama_key, gemini_key], outputs=llm_btn)
190
  output = gr.Textbox(label="LLM output with majority vote and confidence", interactive=False, placeholder="Output will appear here...")
191
- llm_btn.click(fn=diagnose, inputs=[gpt_key, llama_key, gemini_key, top_p, temperature, symptoms], outputs=output, api_name="LLM_Comparator")
192
-
193
 
194
  ui.launch(share=True)
 
116
  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 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
 
130
  outputs = sanitize_outputs(outputs)
131
  output_counts = Counter(outputs)
132
  majority_output, majority_count = output_counts.most_common(1)[0]
133
+ confidence = int((majority_count / len(outputs)) * 100)
134
+
135
+ if majority_output > 0:
136
+ if confidence < 50:
137
+ message = "LLMs do not seem to agree on one output." + "\n"
138
+ message += " GPT output: " + gpt_message + "\n"
139
+ message += " Llama output: " + llama_message + "\n"
140
+ message += " Gemini output: " + gemini_message + "\n"
141
+ message += " Confidence score: " + 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 += " Confidence score: " + confidence + "%"
148
+ elif confidence >= 100:
149
+ message = "All LLMs agree on the same output." + "\n"
150
+ message += " GPT output: " + gpt_message + "\n"
151
+ message += " Llama output: " + llama_message + "\n"
152
+ message += " Gemini output: " + gemini_message + "\n"
153
+ message += " Confidence score: " + confidence + "%"
154
+ else:
155
+ message = "Majority output is not a valid value, please check what is wrong."
156
+ return message
157
  else:
158
+ message = "Please add the symptoms data to start the ranking process."
 
159
 
160
+ return message
161
 
162
  def update_model_components(selected_model):
163
  model_map = {
 
211
  llm_btn = gr.Button(value="Diagnose Disease", variant="primary", elem_id="diagnose", interactive=False)
212
  symptoms.input(toggle_button, inputs=[symptoms, gpt_key, llama_key, gemini_key], outputs=llm_btn)
213
  output = gr.Textbox(label="LLM output with majority vote and confidence", interactive=False, placeholder="Output will appear here...")
214
+ llm_btn.click(fn=diagnose, inputs=[gpt_key, llama_key, gemini_key, top_p, temperature, symptoms],
215
+ outputs=output, api_name="LLM_Comparator")
216
 
217
  ui.launch(share=True)