Spaces:
Runtime error
Runtime error
File size: 5,514 Bytes
52938ea 7727bbc 52938ea |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
import gradio as gr
import pandas as pd
from glob import glob
from pathlib import Path
from tabs.dashboard import df
from tabs.faq import (
about_olas_predict_benchmark,
about_olas_predict,
about_the_dataset,
about_the_tools
)
from tabs.howto_benchmark import how_to_run
from tabs.run_benchmark import run_benchmark_main
demo = gr.Blocks()
def run_benchmark_gradio(tool_name, model_name, openai_api_key, anthropic_api_key):
"""Run the benchmark using inputs."""
if tool_name is None:
return "Please enter the name of your tool."
if openai_api_key is None and anthropic_api_key is None:
return "Please enter either OpenAI or Anthropic API key."
result = run_benchmark_main(tool_name, model_name, openai_api_key, anthropic_api_key)
if result == 'completed':
# get the results file in the results directory
fns = glob('results/*.csv')
print(f"Number of files in results directory: {len(fns)}")
# convert to Path
files = [Path(file) for file in fns]
# get results and summary files
results_files = [file for file in files if 'results' in file.name]
# the other file is the summary file
summary_files = [file for file in files if 'summary' in file.name]
print(results_files, summary_files)
# get the path with results
results_df = pd.read_csv(results_files[0])
summary_df = pd.read_csv(summary_files[0])
# make sure all df float values are rounded to 4 decimal places
results_df = results_df.round(4)
summary_df = summary_df.round(4)
return gr.Dataframe(value=results_df), gr.Dataframe(value=summary_df)
return gr.Textbox(label="Benchmark Result", value=result, interactive=False), gr.Textbox(label="Summary", value="")
with demo:
gr.HTML("<h1>Olas Predict Benchmark</hjson>")
gr.Markdown("Leaderboard showing the performance of Olas Predict tools on the Autocast dataset and overview of the project.")
with gr.Tabs() as tabs:
# first tab - leaderboard
with gr.TabItem("π
Benchmark Leaderboard", id=0):
gr.components.Dataframe(
value=df,
)
# second tab - about
with gr.TabItem("βΉοΈ About"):
with gr.Row():
with gr.Accordion("About the Benchmark", open=False):
gr.Markdown(about_olas_predict_benchmark)
with gr.Row():
with gr.Accordion("About the Tools", open=False):
gr.Markdown(about_the_tools)
with gr.Row():
with gr.Accordion("About the Autocast Dataset", open=False):
gr.Markdown(about_the_dataset)
with gr.Row():
with gr.Accordion("About Olas", open=False):
gr.Markdown(about_olas_predict)
# third tab - how to run the benchmark
with gr.TabItem("π Contribute"):
gr.Markdown(how_to_run)
def update_dropdown(tool):
if "claude" in tool:
return ["claude-3-haiku-20240307", "claude-3-sonnet-20240229", "claude-3-opus-20240229"]
else:
return ["gpt-3.5-turbo-0125", "gpt-4-0125-preview"]
# fourth tab - run the benchmark
with gr.TabItem("π₯ Run the Benchmark"):
with gr.Row():
tool_name = gr.Dropdown(
[
"prediction-offline",
"prediction-online",
# "prediction-online-summarized-info",
"prediction-offline-sme",
"prediction-online-sme",
"claude-prediction-offline",
"claude-prediction-online",
'prediction-request-rag',
# "prediction-with-research-conservative",
# "prediction-with-research-bold",
"prediction-request-reasoning-claude",
"prediction-request-rag-claude",
"prediction-url-cot-claude",
], label="Tool Name", info="Choose the tool to run")
model_name = gr.Dropdown([
"gpt-3.5-turbo-0125",
"gpt-4-0125-preview"
"claude-3-haiku-20240307",
"claude-3-sonnet-20240229",
"claude-3-opus-20240229",
], label="Model Name", info="Choose the model to use")
with gr.Row():
openai_api_key = gr.Textbox(label="OpenAI API Key", placeholder="Enter your OpenAI API key here", type="password")
anthropic_api_key = gr.Textbox(label="Anthropic API Key", placeholder="Enter your Anthropic API key here", type="password")
with gr.Row():
run_button = gr.Button("Run Benchmark")
with gr.Row():
with gr.Accordion("Results", open=True):
result = gr.Dataframe()
with gr.Row():
with gr.Accordion("Summary", open=False):
summary = gr.Dataframe()
run_button.click(run_benchmark_gradio,
inputs=[tool_name, model_name, openai_api_key, anthropic_api_key],
outputs=[result, summary])
demo.queue(default_concurrency_limit=40).launch(server_port=7860) |