Update app.py
Browse files
app.py
CHANGED
@@ -1065,7 +1065,49 @@ def update_inputs_with_llm_suggestions(suggestions):
|
|
1065 |
gr.update(value=suggestions["apply_phonetic"]), # apply_phonetic_input
|
1066 |
gr.update(value=suggestions["phonetic_weight"]) # phonetic_weight_input
|
1067 |
]
|
|
|
|
|
|
|
|
|
1068 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1069 |
|
1070 |
# Gradio Interface
|
1071 |
def launch_interface(share=True):
|
@@ -1111,8 +1153,6 @@ def launch_interface(share=True):
|
|
1111 |
use_reranking_input = gr.Checkbox(label="Use Reranking", value=False)
|
1112 |
|
1113 |
with gr.Tab("Automation"):
|
1114 |
-
|
1115 |
-
|
1116 |
with gr.Row():
|
1117 |
auto_file_input = gr.File(label="Upload File (Optional)")
|
1118 |
auto_query_input = gr.Textbox(label="Search Query")
|
@@ -1138,14 +1178,14 @@ def launch_interface(share=True):
|
|
1138 |
value=[f"HuggingFace:{DEFAULT_MODELS['HuggingFace'][0]}"]
|
1139 |
)
|
1140 |
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
auto_split_strategies = gr.CheckboxGroup(
|
1150 |
choices=["token", "recursive"],
|
1151 |
label="Split Strategies to Test"
|
@@ -1164,24 +1204,69 @@ def launch_interface(share=True):
|
|
1164 |
auto_optimize_vocab = gr.Checkbox(label="Test Vocabulary Optimization", value=True)
|
1165 |
auto_use_query_optimization = gr.Checkbox(label="Test Query Optimization", value=True)
|
1166 |
auto_use_reranking = gr.Checkbox(label="Test Reranking", value=True)
|
1167 |
-
|
1168 |
|
1169 |
auto_results_output = gr.Dataframe(label="Automated Test Results", interactive=False)
|
1170 |
auto_stats_output = gr.Dataframe(label="Automated Test Statistics", interactive=False)
|
1171 |
recommendations_output = gr.JSON(label="Recommendations")
|
1172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1173 |
auto_submit_button = gr.Button("Run Automated Tests")
|
1174 |
auto_submit_button.click(
|
1175 |
-
fn=
|
1176 |
inputs=[
|
1177 |
-
auto_file_input, auto_query_input, auto_expected_result_input,
|
|
|
1178 |
auto_split_strategies, auto_chunk_sizes, auto_overlap_sizes,
|
1179 |
auto_vector_store_types, auto_search_types, auto_top_k,
|
1180 |
-
auto_optimize_vocab, auto_use_query_optimization, auto_use_reranking
|
|
|
1181 |
],
|
1182 |
outputs=[auto_results_output, auto_stats_output, recommendations_output]
|
1183 |
)
|
1184 |
-
|
1185 |
|
1186 |
with gr.Tab("Results"):
|
1187 |
with gr.Row():
|
|
|
1065 |
gr.update(value=suggestions["apply_phonetic"]), # apply_phonetic_input
|
1066 |
gr.update(value=suggestions["phonetic_weight"]) # phonetic_weight_input
|
1067 |
]
|
1068 |
+
|
1069 |
+
def parse_model_selections(default_models, custom_models):
|
1070 |
+
"""
|
1071 |
+
Parse selected default models and custom models into model configurations
|
1072 |
|
1073 |
+
Args:
|
1074 |
+
default_models (List[str]): Selected default models in format "type:name"
|
1075 |
+
custom_models (str): Custom models string with one model per line in format "type:name"
|
1076 |
+
|
1077 |
+
Returns:
|
1078 |
+
List[Dict[str, str]]: List of model configurations with 'type' and 'name' keys
|
1079 |
+
"""
|
1080 |
+
model_configs = []
|
1081 |
+
|
1082 |
+
# Process default models
|
1083 |
+
if default_models:
|
1084 |
+
for model in default_models:
|
1085 |
+
model_type, model_name = model.split(':')
|
1086 |
+
model_configs.append({
|
1087 |
+
'type': model_type,
|
1088 |
+
'name': model_name
|
1089 |
+
})
|
1090 |
+
|
1091 |
+
# Process custom models
|
1092 |
+
if custom_models:
|
1093 |
+
custom_model_lines = custom_models.strip().split('\n')
|
1094 |
+
for line in custom_model_lines:
|
1095 |
+
if line.strip() and ':' in line:
|
1096 |
+
model_type, model_name = line.strip().split(':')
|
1097 |
+
model_configs.append({
|
1098 |
+
'type': model_type.strip(),
|
1099 |
+
'name': model_name.strip()
|
1100 |
+
})
|
1101 |
+
|
1102 |
+
return model_configs
|
1103 |
+
|
1104 |
+
def parse_comma_separated(text):
|
1105 |
+
"""Parse comma-separated values into a list"""
|
1106 |
+
if not text:
|
1107 |
+
return []
|
1108 |
+
return [x.strip() for x in text.split(',') if x.strip()]
|
1109 |
+
|
1110 |
+
|
1111 |
|
1112 |
# Gradio Interface
|
1113 |
def launch_interface(share=True):
|
|
|
1153 |
use_reranking_input = gr.Checkbox(label="Use Reranking", value=False)
|
1154 |
|
1155 |
with gr.Tab("Automation"):
|
|
|
|
|
1156 |
with gr.Row():
|
1157 |
auto_file_input = gr.File(label="Upload File (Optional)")
|
1158 |
auto_query_input = gr.Textbox(label="Search Query")
|
|
|
1178 |
value=[f"HuggingFace:{DEFAULT_MODELS['HuggingFace'][0]}"]
|
1179 |
)
|
1180 |
|
1181 |
+
with gr.Column():
|
1182 |
+
# Custom model input
|
1183 |
+
custom_models_input = gr.TextArea(
|
1184 |
+
label="Custom Models (Optional)",
|
1185 |
+
placeholder="Enter one model per line in format: type:name",
|
1186 |
+
lines=3
|
1187 |
+
)
|
1188 |
+
|
1189 |
auto_split_strategies = gr.CheckboxGroup(
|
1190 |
choices=["token", "recursive"],
|
1191 |
label="Split Strategies to Test"
|
|
|
1204 |
auto_optimize_vocab = gr.Checkbox(label="Test Vocabulary Optimization", value=True)
|
1205 |
auto_use_query_optimization = gr.Checkbox(label="Test Query Optimization", value=True)
|
1206 |
auto_use_reranking = gr.Checkbox(label="Test Reranking", value=True)
|
|
|
1207 |
|
1208 |
auto_results_output = gr.Dataframe(label="Automated Test Results", interactive=False)
|
1209 |
auto_stats_output = gr.Dataframe(label="Automated Test Statistics", interactive=False)
|
1210 |
recommendations_output = gr.JSON(label="Recommendations")
|
1211 |
+
|
1212 |
+
def run_automation(file_input, query_input, expected_result, default_models, custom_models,
|
1213 |
+
split_strategies, chunk_sizes, overlap_sizes,
|
1214 |
+
vector_store_types, search_types, top_k_values,
|
1215 |
+
optimize_vocab, use_query_optimization, use_reranking,
|
1216 |
+
model_feedback):
|
1217 |
+
"""Wrapper function to handle Gradio inputs and run automated tests"""
|
1218 |
+
|
1219 |
+
# Parse model configurations
|
1220 |
+
model_configs = parse_model_selections(default_models, custom_models)
|
1221 |
+
|
1222 |
+
# Parse test parameters
|
1223 |
+
test_params = {
|
1224 |
+
'split_strategy': split_strategies,
|
1225 |
+
'chunk_size': parse_comma_separated(chunk_sizes),
|
1226 |
+
'overlap_size': parse_comma_separated(overlap_sizes),
|
1227 |
+
'vector_store_type': vector_store_types,
|
1228 |
+
'search_type': search_types,
|
1229 |
+
'top_k': parse_comma_separated(top_k_values),
|
1230 |
+
'optimize_vocab': [optimize_vocab],
|
1231 |
+
'use_query_optimization': [use_query_optimization],
|
1232 |
+
'use_reranking': [use_reranking],
|
1233 |
+
'lang': ['en'], # Default to English
|
1234 |
+
'apply_preprocessing': [True], # Default preprocessing
|
1235 |
+
'apply_phonetic': [False], # Default phonetic settings
|
1236 |
+
'phonetic_weight': [0.5],
|
1237 |
+
'custom_separators': [None],
|
1238 |
+
'query_optimization_model': ['gpt-3.5-turbo'] # Default query optimization model
|
1239 |
+
}
|
1240 |
+
|
1241 |
+
# Run automated tests
|
1242 |
+
results_df, stats_df = run_automated_tests(
|
1243 |
+
file_input.name if file_input else None,
|
1244 |
+
query_input,
|
1245 |
+
model_configs,
|
1246 |
+
test_params,
|
1247 |
+
expected_result if expected_result else None,
|
1248 |
+
model_feedback if model_feedback else None
|
1249 |
+
)
|
1250 |
+
|
1251 |
+
# Generate recommendations based on results
|
1252 |
+
recommendations = generate_recommendations(stats_df)
|
1253 |
+
|
1254 |
+
return results_df, stats_df, recommendations
|
1255 |
+
|
1256 |
auto_submit_button = gr.Button("Run Automated Tests")
|
1257 |
auto_submit_button.click(
|
1258 |
+
fn=run_automation,
|
1259 |
inputs=[
|
1260 |
+
auto_file_input, auto_query_input, auto_expected_result_input,
|
1261 |
+
default_models_input, custom_models_input,
|
1262 |
auto_split_strategies, auto_chunk_sizes, auto_overlap_sizes,
|
1263 |
auto_vector_store_types, auto_search_types, auto_top_k,
|
1264 |
+
auto_optimize_vocab, auto_use_query_optimization, auto_use_reranking,
|
1265 |
+
model_feedback_input
|
1266 |
],
|
1267 |
outputs=[auto_results_output, auto_stats_output, recommendations_output]
|
1268 |
)
|
1269 |
+
###
|
1270 |
|
1271 |
with gr.Tab("Results"):
|
1272 |
with gr.Row():
|