Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
-
import argparse
|
| 3 |
import warnings
|
| 4 |
import time
|
| 5 |
-
from typing import Dict, Tuple, List
|
| 6 |
from dataclasses import dataclass
|
| 7 |
from pathlib import Path
|
| 8 |
|
|
@@ -345,6 +344,27 @@ def evaluate_single_response(gemini_api_key, prompt, response, model_name="Test
|
|
| 345 |
}
|
| 346 |
|
| 347 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 348 |
def create_gradio_interface():
|
| 349 |
"""Create Gradio interface for evaluation app"""
|
| 350 |
with gr.Blocks(title="Model Response Evaluator") as app:
|
|
@@ -384,62 +404,54 @@ def create_gradio_interface():
|
|
| 384 |
evaluate_batch_btn = gr.Button("Run Benchmark")
|
| 385 |
benchmark_output = gr.DataFrame(label="Benchmark Results")
|
| 386 |
|
| 387 |
-
def evaluate_batch(api_key, file, prompt_column, models_text):
|
| 388 |
-
try:
|
| 389 |
-
# Load the CSV file
|
| 390 |
-
file_path = file.name
|
| 391 |
-
df = pd.read_csv(file_path)
|
| 392 |
-
|
| 393 |
-
# Process model names if provided
|
| 394 |
-
models = None
|
| 395 |
-
if models_text.strip():
|
| 396 |
-
models = [m.strip() for m in models_text.split(',')]
|
| 397 |
-
|
| 398 |
-
# Run the evaluation
|
| 399 |
-
evaluator = BenchmarkEvaluator(api_key)
|
| 400 |
-
results = evaluator.evaluate_all_models(df, models, prompt_column)
|
| 401 |
-
|
| 402 |
-
return results
|
| 403 |
-
except Exception as e:
|
| 404 |
-
return pd.DataFrame({'Error': [str(e)]})
|
| 405 |
-
|
| 406 |
evaluate_batch_btn.click(
|
| 407 |
evaluate_batch,
|
| 408 |
inputs=[gemini_api_key_batch, csv_file, prompt_col, models_input],
|
| 409 |
outputs=benchmark_output
|
| 410 |
)
|
| 411 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
return app
|
| 413 |
|
| 414 |
|
| 415 |
def main():
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
parser.add_argument("--models", type=str, help="Comma-separated list of model names to evaluate")
|
| 420 |
-
parser.add_argument("--prompt_col", type=str, default="rus_prompt", help="Column name containing prompts")
|
| 421 |
-
parser.add_argument("--web", action="store_true", help="Launch web interface")
|
| 422 |
-
|
| 423 |
-
args = parser.parse_args()
|
| 424 |
-
|
| 425 |
-
if args.web:
|
| 426 |
-
app = create_gradio_interface()
|
| 427 |
-
app.launch(share=True)
|
| 428 |
-
elif args.input_file:
|
| 429 |
-
if not args.gemini_api_key:
|
| 430 |
-
print("Error: Gemini API key is required. Set GEMINI_API_KEY environment variable or pass --gemini_api_key")
|
| 431 |
-
return
|
| 432 |
-
|
| 433 |
-
df = pd.read_csv(args.input_file)
|
| 434 |
-
models = None
|
| 435 |
-
if args.models:
|
| 436 |
-
models = [m.strip() for m in args.models.split(',')]
|
| 437 |
-
|
| 438 |
-
evaluator = BenchmarkEvaluator(args.gemini_api_key)
|
| 439 |
-
evaluator.evaluate_all_models(df, models, args.prompt_col)
|
| 440 |
-
else:
|
| 441 |
-
print("Error: Either --input_file or --web argument is required")
|
| 442 |
-
print("Run with --help for usage information")
|
| 443 |
|
| 444 |
|
| 445 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
import warnings
|
| 3 |
import time
|
| 4 |
+
from typing import Dict, Tuple, List
|
| 5 |
from dataclasses import dataclass
|
| 6 |
from pathlib import Path
|
| 7 |
|
|
|
|
| 344 |
}
|
| 345 |
|
| 346 |
|
| 347 |
+
def evaluate_batch(api_key, file, prompt_column, models_text):
|
| 348 |
+
"""Process batch evaluation from the UI"""
|
| 349 |
+
try:
|
| 350 |
+
# Load the CSV file
|
| 351 |
+
file_path = file.name
|
| 352 |
+
df = pd.read_csv(file_path)
|
| 353 |
+
|
| 354 |
+
# Process model names if provided
|
| 355 |
+
models = None
|
| 356 |
+
if models_text.strip():
|
| 357 |
+
models = [m.strip() for m in models_text.split(',')]
|
| 358 |
+
|
| 359 |
+
# Run the evaluation
|
| 360 |
+
evaluator = BenchmarkEvaluator(api_key)
|
| 361 |
+
results = evaluator.evaluate_all_models(df, models, prompt_column)
|
| 362 |
+
|
| 363 |
+
return results
|
| 364 |
+
except Exception as e:
|
| 365 |
+
return pd.DataFrame({'Error': [str(e)]})
|
| 366 |
+
|
| 367 |
+
|
| 368 |
def create_gradio_interface():
|
| 369 |
"""Create Gradio interface for evaluation app"""
|
| 370 |
with gr.Blocks(title="Model Response Evaluator") as app:
|
|
|
|
| 404 |
evaluate_batch_btn = gr.Button("Run Benchmark")
|
| 405 |
benchmark_output = gr.DataFrame(label="Benchmark Results")
|
| 406 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 407 |
evaluate_batch_btn.click(
|
| 408 |
evaluate_batch,
|
| 409 |
inputs=[gemini_api_key_batch, csv_file, prompt_col, models_input],
|
| 410 |
outputs=benchmark_output
|
| 411 |
)
|
| 412 |
+
|
| 413 |
+
# Add a new tab for configuration settings
|
| 414 |
+
with gr.Tab("Configuration"):
|
| 415 |
+
gr.Markdown("## Advanced Configuration")
|
| 416 |
+
gr.Markdown("Adjust evaluation parameters to customize the benchmarking process.")
|
| 417 |
+
|
| 418 |
+
with gr.Row():
|
| 419 |
+
batch_size = gr.Slider(minimum=1, maximum=20, value=5, step=1, label="Batch Size")
|
| 420 |
+
retry_attempts = gr.Slider(minimum=1, maximum=10, value=5, step=1, label="Retry Attempts")
|
| 421 |
+
|
| 422 |
+
with gr.Row():
|
| 423 |
+
min_wait = gr.Slider(minimum=1, maximum=30, value=4, step=1, label="Minimum Wait Time (seconds)")
|
| 424 |
+
max_wait = gr.Slider(minimum=10, maximum=300, value=60, step=10, label="Maximum Wait Time (seconds)")
|
| 425 |
+
|
| 426 |
+
with gr.Row():
|
| 427 |
+
gemini_model = gr.Dropdown(
|
| 428 |
+
choices=["gemini-1.5-flash", "gemini-1.5-pro", "gemini-1.5-ultra"],
|
| 429 |
+
value="gemini-1.5-flash",
|
| 430 |
+
label="Gemini Model"
|
| 431 |
+
)
|
| 432 |
+
|
| 433 |
+
gr.Markdown("Note: Changes to configuration settings will apply to new evaluations.")
|
| 434 |
+
|
| 435 |
+
def update_config(batch_size, retry_attempts, min_wait, max_wait, gemini_model):
|
| 436 |
+
# This function doesn't actually do anything in the demo but would update global config
|
| 437 |
+
return f"Configuration updated: batch_size={batch_size}, retry_attempts={retry_attempts}, min_wait={min_wait}, max_wait={max_wait}, model={gemini_model}"
|
| 438 |
+
|
| 439 |
+
update_config_btn = gr.Button("Update Configuration")
|
| 440 |
+
config_status = gr.Textbox(label="Status", interactive=False)
|
| 441 |
+
|
| 442 |
+
update_config_btn.click(
|
| 443 |
+
update_config,
|
| 444 |
+
inputs=[batch_size, retry_attempts, min_wait, max_wait, gemini_model],
|
| 445 |
+
outputs=config_status
|
| 446 |
+
)
|
| 447 |
+
|
| 448 |
return app
|
| 449 |
|
| 450 |
|
| 451 |
def main():
|
| 452 |
+
"""Main function to run the application"""
|
| 453 |
+
app = create_gradio_interface()
|
| 454 |
+
app.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 455 |
|
| 456 |
|
| 457 |
if __name__ == "__main__":
|