rohansampath commited on
Commit
24af1c0
·
verified ·
1 Parent(s): c9f6bdd

Create app_models_config.py

Browse files
Files changed (1) hide show
  1. app_models_config.py +167 -0
app_models_config.py ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ # Available models
4
+ AVAILABLE_MODELS = [
5
+ "(Select Model)",
6
+ "mistralai/Mistral-7B-v0.1",
7
+ "meta-llama/Llama-2-7b-hf",
8
+ "google/flan-t5-xxl",
9
+ "tiiuae/falcon-7b"
10
+ ]
11
+
12
+ def create_model_config_section():
13
+ """
14
+ Creates the "Head to Head - Choose Models" section with two model configurations side by side.
15
+ Returns the components needed for the main app.
16
+ """
17
+ with gr.Column() as model_config_container:
18
+ gr.Markdown("## (C) Head to Head - Choose Models to evaluate against each other")
19
+
20
+ with gr.Row():
21
+ # Left column - Model 1 configuration
22
+ with gr.Column(scale=1) as model1_column:
23
+ with gr.Group(elem_classes=["config-box"]):
24
+ gr.Markdown("### Model 1")
25
+
26
+ model1_dropdown = gr.Dropdown(
27
+ choices=AVAILABLE_MODELS,
28
+ value="(Select Model)",
29
+ label="Select Model 1",
30
+ info="Choose the first model for head-to-head comparison"
31
+ )
32
+
33
+ model1_shots = gr.Slider(
34
+ minimum=0,
35
+ maximum=5,
36
+ value=5,
37
+ step=1,
38
+ label="Number of Few-shot Examples",
39
+ info="Number of examples to use for few-shot learning (0-5)"
40
+ )
41
+
42
+ model1_regex = gr.Textbox(
43
+ label="Regex Pattern",
44
+ placeholder="Optional: Apply regex pattern to model outputs",
45
+ info="Leave empty for no regex pattern"
46
+ )
47
+
48
+ model1_flash_attn = gr.Checkbox(
49
+ label="Use FlashAttention",
50
+ value=True,
51
+ info="Use FlashAttention for better performance (if supported by model)"
52
+ )
53
+
54
+ # Divider in the middle
55
+ with gr.Column(scale=0.1):
56
+ gr.Markdown('<div style="border-left: 1px solid #ddd; height: 100%;"></div>', elem_classes=["center-divider"])
57
+
58
+ # Right column - Model 2 configuration
59
+ with gr.Column(scale=1) as model2_column:
60
+ with gr.Group(elem_classes=["config-box"]):
61
+ gr.Markdown("### Model 2")
62
+
63
+ model2_dropdown = gr.Dropdown(
64
+ choices=AVAILABLE_MODELS,
65
+ value="(Select Model)",
66
+ label="Select Model 2",
67
+ info="Choose the second model for head-to-head comparison"
68
+ )
69
+
70
+ model2_shots = gr.Slider(
71
+ minimum=0,
72
+ maximum=5,
73
+ value=5,
74
+ step=1,
75
+ label="Number of Few-shot Examples",
76
+ info="Number of examples to use for few-shot learning (0-5)"
77
+ )
78
+
79
+ model2_regex = gr.Textbox(
80
+ label="Regex Pattern",
81
+ placeholder="Optional: Apply regex pattern to model outputs",
82
+ info="Leave empty for no regex pattern"
83
+ )
84
+
85
+ model2_flash_attn = gr.Checkbox(
86
+ label="Use FlashAttention",
87
+ value=True,
88
+ info="Use FlashAttention for better performance (if supported by model)"
89
+ )
90
+
91
+ # Error message area - initially hidden
92
+ model_config_error = gr.Markdown(
93
+ visible=False,
94
+ value="⚠️ **Error**: Both models and configurations are identical. Please select different models or configurations for comparison.",
95
+ elem_classes=["error-message"]
96
+ )
97
+
98
+ return {
99
+ 'container': model_config_container,
100
+ 'model1_dropdown': model1_dropdown,
101
+ 'model1_shots': model1_shots,
102
+ 'model1_regex': model1_regex,
103
+ 'model1_flash_attn': model1_flash_attn,
104
+ 'model2_dropdown': model2_dropdown,
105
+ 'model2_shots': model2_shots,
106
+ 'model2_regex': model2_regex,
107
+ 'model2_flash_attn': model2_flash_attn,
108
+ 'error_message': model_config_error
109
+ }
110
+
111
+ def validate_model_configs(model1, model1_shots, model1_regex, model1_flash,
112
+ model2, model2_shots, model2_regex, model2_flash):
113
+ """
114
+ Validates that the two model configurations are not identical.
115
+ Returns:
116
+ - bool: Whether the configurations are valid (not identical)
117
+ - str: Error message if invalid, otherwise empty string
118
+ """
119
+ if model1 == "(Select Model)" or model2 == "(Select Model)":
120
+ return True, ""
121
+
122
+ # Check if models and all configs are identical
123
+ if (model1 == model2 and
124
+ model1_shots == model2_shots and
125
+ model1_regex == model2_regex and
126
+ model1_flash == model2_flash):
127
+ return False, "⚠️ **Error**: Both models and configurations are identical. Please select different models or configurations for comparison."
128
+
129
+ return True, ""
130
+
131
+ def update_eval_button_state(model1, model1_shots, model1_regex, model1_flash,
132
+ model2, model2_shots, model2_regex, model2_flash):
133
+ """
134
+ Checks model configurations and updates the error message visibility and eval button state.
135
+ """
136
+ is_valid, error_msg = validate_model_configs(
137
+ model1, model1_shots, model1_regex, model1_flash,
138
+ model2, model2_shots, model2_regex, model2_flash
139
+ )
140
+
141
+ if model1 == "(Select Model)" or model2 == "(Select Model)":
142
+ return gr.update(visible=False), gr.update(interactive=False)
143
+
144
+ if not is_valid:
145
+ return gr.update(visible=True, value=error_msg), gr.update(interactive=False)
146
+
147
+ return gr.update(visible=False), gr.update(interactive=True)
148
+
149
+ def get_model_configs(model1, model1_shots, model1_regex, model1_flash,
150
+ model2, model2_shots, model2_regex, model2_flash):
151
+ """
152
+ Returns the model configurations as structured data for the evaluation function.
153
+ """
154
+ return {
155
+ "model1": {
156
+ "name": model1,
157
+ "shots": model1_shots,
158
+ "regex": model1_regex,
159
+ "flash_attention": model1_flash
160
+ },
161
+ "model2": {
162
+ "name": model2,
163
+ "shots": model2_shots,
164
+ "regex": model2_regex,
165
+ "flash_attention": model2_flash
166
+ }
167
+ }