Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,28 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def create_gradio_app():
|
| 5 |
"""
|
| 6 |
-
|
| 7 |
This is required for Hugging Face Spaces deployment
|
| 8 |
"""
|
| 9 |
|
|
@@ -19,6 +38,19 @@ def create_gradio_app():
|
|
| 19 |
with open('script.js', 'r', encoding='utf-8') as f:
|
| 20 |
js_content = f.read()
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
# Combine everything into a single HTML page
|
| 23 |
combined_html = html_content.replace(
|
| 24 |
'<link rel="stylesheet" href="style.css">',
|
|
@@ -30,8 +62,9 @@ def create_gradio_app():
|
|
| 30 |
|
| 31 |
# Create the Gradio interface
|
| 32 |
with gr.Blocks(
|
| 33 |
-
title="MCP
|
| 34 |
theme=gr.themes.Soft(),
|
|
|
|
| 35 |
) as demo:
|
| 36 |
gr.HTML(
|
| 37 |
combined_html,
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
+
import base64
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
def encode_image_to_base64(image_path):
|
| 7 |
+
"""Convert image to base64 for embedding in HTML"""
|
| 8 |
+
if os.path.exists(image_path):
|
| 9 |
+
with open(image_path, "rb") as img_file:
|
| 10 |
+
encoded = base64.b64encode(img_file.read()).decode()
|
| 11 |
+
# Get file extension
|
| 12 |
+
ext = Path(image_path).suffix.lower()
|
| 13 |
+
mime_type = {
|
| 14 |
+
'.png': 'image/png',
|
| 15 |
+
'.jpg': 'image/jpeg',
|
| 16 |
+
'.jpeg': 'image/jpeg',
|
| 17 |
+
'.gif': 'image/gif',
|
| 18 |
+
'.webp': 'image/webp'
|
| 19 |
+
}.get(ext, 'image/png')
|
| 20 |
+
return f"data:{mime_type};base64,{encoded}"
|
| 21 |
+
return ""
|
| 22 |
|
| 23 |
def create_gradio_app():
|
| 24 |
"""
|
| 25 |
+
Gradio app to serve the static HTML leaderboard with embedded images
|
| 26 |
This is required for Hugging Face Spaces deployment
|
| 27 |
"""
|
| 28 |
|
|
|
|
| 38 |
with open('script.js', 'r', encoding='utf-8') as f:
|
| 39 |
js_content = f.read()
|
| 40 |
|
| 41 |
+
# Convert images to base64 for embedding
|
| 42 |
+
diagram_b64 = encode_image_to_base64('mcp-bench.png')
|
| 43 |
+
ranking_b64 = encode_image_to_base64('ranking.png')
|
| 44 |
+
|
| 45 |
+
# Replace image references with base64 embedded versions
|
| 46 |
+
html_content = html_content.replace(
|
| 47 |
+
'src="mcp-bench.png"',
|
| 48 |
+
f'src="{diagram_b64}"'
|
| 49 |
+
).replace(
|
| 50 |
+
'src="ranking.png"',
|
| 51 |
+
f'src="{ranking_b64}"'
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
# Combine everything into a single HTML page
|
| 55 |
combined_html = html_content.replace(
|
| 56 |
'<link rel="stylesheet" href="style.css">',
|
|
|
|
| 62 |
|
| 63 |
# Create the Gradio interface
|
| 64 |
with gr.Blocks(
|
| 65 |
+
title="MCP-Bench Leaderboard",
|
| 66 |
theme=gr.themes.Soft(),
|
| 67 |
+
css="body { margin: 0; padding: 0; }"
|
| 68 |
) as demo:
|
| 69 |
gr.HTML(
|
| 70 |
combined_html,
|