BenchGecko's picture
Upload app.py with huggingface_hub
9c7b6c7 verified
Raw
History Blame Contribute Delete
8.53 kB
import gradio as gr
import csv
import io
# Embedded sample data (from BenchGecko dataset)
MODELS_CSV = """name,provider,input_price,output_price,context_window,average_score,mmlu_score,humaneval_score,gpqa_score,math_score,open_source
Qwen3.5 397B A17B,Alibaba Qwen,0.39,1.17,262000,96.3,95.1,97.8,71.2,94.5,true
DeepSeek V3.2 Speciale,DeepSeek,0.40,1.20,164000,95.2,92.4,96.2,68.5,91.3,true
GPT-5.4 Pro,OpenAI,30.00,60.00,1050000,93.0,93.8,94.5,72.1,88.7,false
GPT-5 Chat,OpenAI,1.25,5.00,128000,89.0,90.2,91.8,58.3,82.1,false
Gemini 3.1 Pro Preview,Google DeepMind,2.00,8.00,1049000,90.0,91.5,89.2,64.8,85.3,false
Claude Opus 4.6,Anthropic,30.00,150.00,1000000,83.3,88.5,87.2,55.1,78.4,false
DeepSeek R1 0528,DeepSeek,0.55,2.19,128000,88.3,89.1,90.5,87.2,92.1,true
GLM 5.1,Zhipu AI,0.70,2.10,203000,87.0,86.2,88.1,52.3,79.5,false
Step 3.5 Flash,StepFun,0.10,0.30,262000,89.5,87.3,91.2,55.8,83.2,false
MiMo-V2-Flash,Xiaomi,0.09,0.27,262000,81.7,82.1,85.3,48.2,74.1,true"""
def load_models():
reader = csv.DictReader(io.StringIO(MODELS_CSV))
models = []
for row in reader:
for key in ["input_price", "output_price", "average_score", "mmlu_score", "humaneval_score", "gpqa_score", "math_score"]:
if row[key]:
row[key] = float(row[key])
row["context_window"] = int(row["context_window"])
row["open_source"] = row["open_source"] == "true"
models.append(row)
return models
MODELS = load_models()
def compare_models(model1_name, model2_name):
m1 = next((m for m in MODELS if m["name"] == model1_name), None)
m2 = next((m for m in MODELS if m["name"] == model2_name), None)
if not m1 or not m2:
return "Select two models to compare."
output = f"## {m1['name']} vs {m2['name']}\n\n"
output += "| Metric | " + m1["name"] + " | " + m2["name"] + " | Winner |\n"
output += "|--------|" + "-" * (len(m1["name"]) + 2) + "|" + "-" * (len(m2["name"]) + 2) + "|--------|\n"
metrics = [
("Average Score", "average_score", True),
("MMLU", "mmlu_score", True),
("HumanEval", "humaneval_score", True),
("GPQA Diamond", "gpqa_score", True),
("MATH", "math_score", True),
("Input Price ($/M)", "input_price", False),
("Output Price ($/M)", "output_price", False),
("Context Window", "context_window", True),
]
for label, key, higher_is_better in metrics:
v1 = m1[key]
v2 = m2[key]
if higher_is_better:
winner = m1["name"] if v1 > v2 else m2["name"] if v2 > v1 else "Tie"
else:
winner = m1["name"] if v1 < v2 else m2["name"] if v2 < v1 else "Tie"
fmt = lambda v: f"${v:.2f}" if "price" in key.lower() else f"{v:,}" if key == "context_window" else f"{v:.1f}"
output += f"| {label} | {fmt(v1)} | {fmt(v2)} | {winner} |\n"
output += f"\n**Open Source**: {m1['name']} ({'Yes' if m1['open_source'] else 'No'}) | {m2['name']} ({'Yes' if m2['open_source'] else 'No'})\n"
output += f"\n---\n"
output += f"\n*Sample from [BenchGecko](https://benchgecko.ai). Full live data with thousands of models at [benchgecko.ai/compare](https://benchgecko.ai/compare).*"
return output
def search_models(query, sort_by, open_source_only):
results = MODELS
if query:
query_lower = query.lower()
results = [m for m in results if query_lower in m["name"].lower() or query_lower in m["provider"].lower()]
if open_source_only:
results = [m for m in results if m["open_source"]]
sort_map = {
"Score (highest)": ("average_score", True),
"Price (lowest)": ("input_price", False),
"Context (largest)": ("context_window", True),
"MMLU (highest)": ("mmlu_score", True),
}
if sort_by in sort_map:
key, reverse = sort_map[sort_by]
results.sort(key=lambda m: m[key], reverse=reverse)
output = "| # | Model | Provider | Score | $/M in | Context | Open Source |\n"
output += "|---|-------|----------|-------|--------|---------|-------------|\n"
for i, m in enumerate(results, 1):
oss = "Yes" if m["open_source"] else "No"
output += f"| {i} | {m['name']} | {m['provider']} | {m['average_score']:.1f} | ${m['input_price']:.2f} | {m['context_window']:,} | {oss} |\n"
output += f"\n---\n"
output += f"\n*Showing {len(results)} of 10 sample models. Full rankings with thousands of models at [benchgecko.ai/models](https://benchgecko.ai/models).*\n"
output += f"\n*Cross-provider pricing at [benchgecko.ai/pricing](https://benchgecko.ai/pricing). AI economy data at [benchgecko.ai/economy](https://benchgecko.ai/economy).*"
return output
def get_price_analysis():
sorted_by_value = sorted(MODELS, key=lambda m: m["average_score"] / max(m["input_price"], 0.01), reverse=True)
output = "## Best Value: Score per Dollar\n\n"
output += "| # | Model | Score | $/M in | Score/$ Ratio | Open Source |\n"
output += "|---|-------|-------|--------|---------------|-------------|\n"
for i, m in enumerate(sorted_by_value, 1):
ratio = m["average_score"] / max(m["input_price"], 0.01)
oss = "Yes" if m["open_source"] else "No"
output += f"| {i} | {m['name']} | {m['average_score']:.1f} | ${m['input_price']:.2f} | {ratio:.0f} | {oss} |\n"
output += f"\n---\n"
output += f"\n*Find the cheapest provider for any model at [benchgecko.ai/pricing](https://benchgecko.ai/pricing).*\n"
output += f"\n*Estimate monthly costs with the [Pricing Calculator](https://benchgecko.ai/calculator). Track the AI economy at [benchgecko.ai/economy](https://benchgecko.ai/economy).*"
return output
model_names = [m["name"] for m in MODELS]
with gr.Blocks(title="BenchGecko AI Model Explorer", theme=gr.themes.Soft()) as demo:
gr.Markdown("""
# BenchGecko AI Model Explorer
Explore AI model benchmarks, pricing, and performance data from [BenchGecko](https://benchgecko.ai).
This is a sample of 10 models. The full platform tracks **thousands of models** across **hundreds of providers** with real-time updates.
[Full Rankings](https://benchgecko.ai/models) | [Pricing](https://benchgecko.ai/pricing) | [Compare](https://benchgecko.ai/compare) | [API](https://benchgecko.ai/api-docs) | [Economy](https://benchgecko.ai/economy) | [Compute](https://benchgecko.ai/compute) | [Mindshare](https://benchgecko.ai/mindshare)
""")
with gr.Tab("Search & Filter"):
with gr.Row():
query = gr.Textbox(label="Search models or providers", placeholder="e.g. DeepSeek, OpenAI, Qwen...")
sort_by = gr.Dropdown(choices=["Score (highest)", "Price (lowest)", "Context (largest)", "MMLU (highest)"], value="Score (highest)", label="Sort by")
oss_only = gr.Checkbox(label="Open source only", value=False)
search_btn = gr.Button("Search", variant="primary")
search_output = gr.Markdown()
search_btn.click(search_models, inputs=[query, sort_by, oss_only], outputs=search_output)
demo.load(search_models, inputs=[query, sort_by, oss_only], outputs=search_output)
with gr.Tab("Compare"):
with gr.Row():
m1 = gr.Dropdown(choices=model_names, label="Model 1", value=model_names[0])
m2 = gr.Dropdown(choices=model_names, label="Model 2", value=model_names[1])
compare_btn = gr.Button("Compare", variant="primary")
compare_output = gr.Markdown()
compare_btn.click(compare_models, inputs=[m1, m2], outputs=compare_output)
with gr.Tab("Value Analysis"):
value_btn = gr.Button("Analyze Price/Performance", variant="primary")
value_output = gr.Markdown()
value_btn.click(get_price_analysis, outputs=value_output)
gr.Markdown("""
---
**Data source**: [BenchGecko](https://benchgecko.ai) tracks thousands of AI models with cross-provider pricing, benchmark scores, and daily updates.
[Models](https://benchgecko.ai/models) | [Pricing](https://benchgecko.ai/pricing) | [Agents](https://benchgecko.ai/agents) | [MCP Servers](https://benchgecko.ai/mcp) | [Economy](https://benchgecko.ai/economy) | [Compute](https://benchgecko.ai/compute) | [Mindshare](https://benchgecko.ai/mindshare) | [Learn](https://benchgecko.ai/learn) | [Changelog](https://benchgecko.ai/changelog) | [API](https://benchgecko.ai/api-docs)
""")
demo.launch()