Spaces:
Sleeping
Sleeping
add model comparision tab
Browse files- gemmademo/_chat.py +41 -1
gemmademo/_chat.py
CHANGED
|
@@ -226,7 +226,47 @@ class GradioChat:
|
|
| 226 |
)
|
| 227 |
|
| 228 |
with gr.Tab("Model Comparision"):
|
| 229 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
|
| 231 |
demo.launch()
|
| 232 |
|
|
|
|
| 226 |
)
|
| 227 |
|
| 228 |
with gr.Tab("Model Comparision"):
|
| 229 |
+
with gr.Row():
|
| 230 |
+
# Input for user query
|
| 231 |
+
user_input = gr.Textbox(
|
| 232 |
+
placeholder="Enter your query here...", label="User Input"
|
| 233 |
+
)
|
| 234 |
+
|
| 235 |
+
# Dropdown for model selection
|
| 236 |
+
model_comparison_dropdown = gr.Dropdown(
|
| 237 |
+
choices=self.model_options,
|
| 238 |
+
label="Select Models",
|
| 239 |
+
multiselect=True, # Allow multiple selections
|
| 240 |
+
value=[self.current_model_name], # Default to current model
|
| 241 |
+
)
|
| 242 |
+
|
| 243 |
+
# Output area for model responses
|
| 244 |
+
output_area = gr.Row()
|
| 245 |
+
|
| 246 |
+
def compare_models(user_input, selected_models):
|
| 247 |
+
responses = {}
|
| 248 |
+
for model_name in selected_models:
|
| 249 |
+
model = self._load_model(model_name) # Load each selected model
|
| 250 |
+
prompt = self.prompt_manager.get_prompt(user_input=user_input)
|
| 251 |
+
response = model.generate_response(prompt)
|
| 252 |
+
responses[model_name] = response # Store response by model name
|
| 253 |
+
return responses
|
| 254 |
+
|
| 255 |
+
# Button to trigger comparison
|
| 256 |
+
compare_button = gr.Button("Compare Models")
|
| 257 |
+
compare_button.click(
|
| 258 |
+
fn=compare_models,
|
| 259 |
+
inputs=[user_input, model_comparison_dropdown],
|
| 260 |
+
outputs=output_area,
|
| 261 |
+
)
|
| 262 |
+
|
| 263 |
+
# Display responses for each model
|
| 264 |
+
with output_area:
|
| 265 |
+
for model_name in self.model_options:
|
| 266 |
+
gr.Markdown(f"### Output from {model_name}:")
|
| 267 |
+
gr.Textbox(
|
| 268 |
+
label=model_name, interactive=False
|
| 269 |
+
) # Placeholder for model output
|
| 270 |
|
| 271 |
demo.launch()
|
| 272 |
|