Spaces:
Sleeping
Sleeping
File size: 16,454 Bytes
bd8cbd2 5bf1eab 0c53877 bd8cbd2 5bf1eab 9f5d67a 5bf1eab bd8cbd2 5bf1eab bd8cbd2 5bf1eab bd8cbd2 5bf1eab bd8cbd2 5bf1eab 0c53877 5bf1eab 0c53877 5bf1eab d96e9f3 5bf1eab d96e9f3 0c53877 5bf1eab 0c53877 5bf1eab d96e9f3 0c53877 5bf1eab 0c53877 5bf1eab 0c53877 5bf1eab 0c53877 5bf1eab 0c53877 5bf1eab 0c53877 5bf1eab 0c53877 5bf1eab 0c53877 5bf1eab 0c53877 5bf1eab 0c53877 5bf1eab bd8cbd2 5bf1eab bd8cbd2 5bf1eab bd8cbd2 5bf1eab bd8cbd2 0c53877 5bf1eab bd8cbd2 5bf1eab 0c53877 bd8cbd2 0c53877 5bf1eab 0c53877 5bf1eab 0c53877 bd8cbd2 5bf1eab bd8cbd2 5bf1eab bd8cbd2 5bf1eab 9f5d67a 0c53877 9f5d67a 5bf1eab 0c53877 5bf1eab 0c53877 5bf1eab 0c53877 5bf1eab 0c53877 5bf1eab 9f5d67a 5bf1eab 9f5d67a 5bf1eab bd8cbd2 5bf1eab |
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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
import gradio as gr
from gradio_leaderboard import Leaderboard, ColumnFilter, SelectColumns
import pandas as pd
import os
import json
import tempfile
import shutil
import zipfile
from huggingface_hub import snapshot_download
# Constants for PhysicalCodeBench
TITLE = """
<div style="text-align: center; max-width: 900px; margin: 0 auto;">
<div>
<h1 style="font-weight: 900; margin-bottom: 7px; margin-top: 5px;">
PhysicalCodeBench Leaderboard
</h1>
<h3 style="margin-top: 0; margin-bottom: 10px; font-weight: 500;">
Evaluating LLMs on Physics-based Simulation Code Generation
</h3>
</div>
</div>
"""
INTRODUCTION_TEXT = """
PhysicalCodeBench evaluates the abilities of Large Language Models (LLMs) to generate code for physics-based simulations.
The benchmark consists of user instructions that describe physical scenarios to be simulated, reference code implementations,
and resulting simulation videos generated using the [Genesis](https://github.com/Genesis-Embodied-AI/Genesis) physics engine.
This leaderboard showcases model performance on the PhysicalCodeBench-50 dataset, measuring both text-based execution success
and visual quality of the generated simulations.
"""
ABOUT_TEXT = """
## About PhysicalCodeBench
PhysicalCodeBench evaluates an LLM's ability to:
- Understand natural language descriptions of physical scenarios
- Generate executable code that correctly implements the physics simulation
- Produce visually accurate and physically plausible results
The benchmark covers a variety of physical phenomena including:
- Rigid body dynamics (collisions, rolling, bouncing, etc.)
- Fluid and particle simulations
- Soft body physics
- Controlled environments (robotic arms, drones, etc.)
- Chain reactions and complex interactions
## Evaluation Metrics
PhysicalCodeBench uses two main evaluation dimensions:
1. **Text Score (50 points)**: Evaluates code execution success
- Code runs without errors (25 points)
- Generates proper output files (10 points)
- Output files meet required specifications (15 points)
2. **Visual Score (50 points)**: Evaluates simulation quality
- CLIP Score: Measures text-video alignment (25 points)
- Motion Smoothness: Evaluates physics simulation quality (25 points)
Total score is the sum of Text and Visual scores (maximum 100 points).
"""
SUBMISSION_TEXT = """
## How to Submit Your Model Results
1. Fork the [PhysicalCodeBench repository](https://github.com/Sealical/PhysicalCodeBench)
2. Generate code for all 50 tasks in the benchmark using your model
3. Run the evaluation pipeline with your generated code
4. Create a submission folder with the following structure:
```
submission/
βββ model_info.json # Contains model details (name, size, etc.)
βββ evaluation_results/ # Directory containing all result files
βββ PhysCodeEval_results.json # Main evaluation results file
```
5. Zip your submission folder and upload it below along with your model details
Your submission will be verified and added to the leaderboard once approved.
"""
CITATION_TEXT = """
@article{PhysicalCodeBench2025,
title={PhysicalCodeBench: Evaluating LLMs on Physics-based Simulation Code Generation},
author={Your Name and Co-authors},
journal={arXiv preprint arXiv:XXXX.XXXXX},
year={2025}
}
"""
# Custom CSS for the interface
custom_css = """
.markdown-text {
font-size: 16px !important;
text-align: left !important;
}
.tab-button {
font-size: 16px !important;
}
"""
# Define column structure for the leaderboard
class PhysCodeColumn:
def __init__(self, name, type, displayed_by_default=True, never_hidden=False, hidden=False):
self.name = name
self.type = type
self.displayed_by_default = displayed_by_default
self.never_hidden = never_hidden
self.hidden = hidden
# Define the columns for our leaderboard
COLUMNS = [
PhysCodeColumn("rank", "number", True, True, False),
PhysCodeColumn("model", "str", True, True, False),
PhysCodeColumn("model_type", "str", True, False, False),
PhysCodeColumn("organization", "str", True, False, False),
PhysCodeColumn("text_score", "number", True, False, False),
PhysCodeColumn("visual_score", "number", True, False, False),
PhysCodeColumn("total_score", "number", True, False, False),
PhysCodeColumn("clip_score", "number", False, False, False),
PhysCodeColumn("motion_smooth_score", "number", False, False, False),
PhysCodeColumn("execution_success", "number", False, False, False),
PhysCodeColumn("file_generation", "number", False, False, False),
PhysCodeColumn("file_quality", "number", False, False, False),
PhysCodeColumn("submission_date", "date", False, False, False)
]
# Enums for model metadata
class ModelType:
Proprietary = "Proprietary"
OpenSource = "Open Source"
CloseSource = "Close Source"
API = "API"
Unknown = "Unknown"
@staticmethod
def to_str(model_type):
return model_type
# Load sample data (replace with your actual data loading logic)
def get_leaderboard_df():
# Sample data based on your README
data = [
{
"rank": 1,
"model": "GPT4o",
"model_type": ModelType.CloseSource,
"organization": "OpenAI",
"text_score": 16.0,
"visual_score": 18.262,
"total_score": 34.262,
"clip_score": 10.2,
"motion_smooth_score": 8.062,
"execution_success": 10.0,
"file_generation": 3.0,
"file_quality": 3.0,
"submission_date": "2025-01-15"
},
{
"rank": 2,
"model": "Gemini-2.0-flash",
"model_type": ModelType.CloseSource,
"organization": "Google",
"text_score": 15.0,
"visual_score": 16.963,
"total_score": 31.963,
"clip_score": 9.5,
"motion_smooth_score": 7.463,
"execution_success": 9.0,
"file_generation": 3.0,
"file_quality": 3.0,
"submission_date": "2025-01-20"
},
{
"rank": 3,
"model": "DS-R1",
"model_type": ModelType.OpenSource,
"organization": "DeepSeek",
"text_score": 14.0,
"visual_score": 15.815,
"total_score": 29.815,
"clip_score": 8.9,
"motion_smooth_score": 6.915,
"execution_success": 8.5,
"file_generation": 3.0,
"file_quality": 2.5,
"submission_date": "2025-01-25"
},
{
"rank": 4,
"model": "DeepSeek-R1-Distill-Qwen-32B",
"model_type": ModelType.OpenSource,
"organization": "DeepSeek",
"text_score": 12.2,
"visual_score": 15.82,
"total_score": 28.02,
"clip_score": 8.8,
"motion_smooth_score": 7.02,
"execution_success": 7.2,
"file_generation": 2.5,
"file_quality": 2.5,
"submission_date": "2025-01-28"
},
{
"rank": 5,
"model": "QwQ-32B",
"model_type": ModelType.OpenSource,
"organization": "QwQ Team",
"text_score": 7.1,
"visual_score": 8.964,
"total_score": 16.064,
"clip_score": 4.964,
"motion_smooth_score": 4.0,
"execution_success": 4.1,
"file_generation": 1.5,
"file_quality": 1.5,
"submission_date": "2025-02-05"
},
{
"rank": 6,
"model": "Qwen-2.5-32B",
"model_type": ModelType.OpenSource,
"organization": "Alibaba",
"text_score": 0.7,
"visual_score": 1.126,
"total_score": 1.826,
"clip_score": 0.626,
"motion_smooth_score": 0.5,
"execution_success": 0.5,
"file_generation": 0.1,
"file_quality": 0.1,
"submission_date": "2025-02-10"
}
]
return pd.DataFrame(data)
# Function to load submission from JSON file
def load_submissions_from_json(json_path):
if os.path.exists(json_path):
with open(json_path, 'r') as f:
data = json.load(f)
return pd.DataFrame(data)
return None
# Initialize the leaderboard
def init_leaderboard(dataframe):
if dataframe is None or dataframe.empty:
raise ValueError("Leaderboard DataFrame is empty or None.")
return Leaderboard(
value=dataframe,
datatype=[c.type for c in COLUMNS],
select_columns=SelectColumns(
default_selection=[c.name for c in COLUMNS if c.displayed_by_default],
cant_deselect=[c.name for c in COLUMNS if c.never_hidden],
label="Select Columns to Display:",
),
search_columns=["model", "organization"],
hide_columns=[c.name for c in COLUMNS if c.hidden],
filter_columns=[
ColumnFilter("model_type", type="checkboxgroup", label="Model types"),
ColumnFilter("organization", type="checkboxgroup", label="Organizations"),
],
interactive=False,
)
# Function to handle ZIP file upload and extraction
def process_zip_submission(zip_file):
if zip_file is None:
return "No file uploaded. Please upload a ZIP file containing your submission."
# Create temp directory for extraction
temp_dir = tempfile.mkdtemp()
try:
# Extract the zip file
with zipfile.ZipFile(zip_file.name, 'r') as zip_ref:
zip_ref.extractall(temp_dir)
# Check for required files
model_info_path = os.path.join(temp_dir, "model_info.json")
results_json_path = os.path.join(temp_dir, "PhysCodeEval_results.json")
if not os.path.exists(model_info_path):
return "Error: model_info.json not found in the ZIP file."
if not os.path.exists(results_json_path):
return "Error: PhysCodeEval_results.json not found in the ZIP file."
# Load model info
with open(model_info_path, 'r') as f:
model_info = json.load(f)
# Check for required model info fields
required_fields = ["model_name", "model_type", "organization"]
missing_fields = [field for field in required_fields if field not in model_info]
if missing_fields:
return f"Error: Missing required fields in model_info.json: {', '.join(missing_fields)}"
# TODO: Process the submission files (this would involve your validation logic)
return f"Successfully processed submission for {model_info['model_name']} by {model_info['organization']}. Your submission will be reviewed and added to the leaderboard once approved."
except zipfile.BadZipFile:
return "Error: Invalid ZIP file."
except Exception as e:
return f"Error processing submission: {str(e)}"
finally:
# Clean up
shutil.rmtree(temp_dir)
# Submission form handling
def process_submission(model_name, model_type, organization, team_name, email, submission_link):
# Check for required fields
if not model_name:
return "Error: Model name is required."
if not model_type:
return "Error: Model type is required."
if not email:
return "Error: Contact email is required."
# This would be implemented to handle actual submission processing
return f"Thank you for submitting {model_name} from {organization or team_name}! Your submission will be reviewed and added to the leaderboard once verified. We will contact you at {email} if we need additional information."
# Main application
def create_demo():
# Load the leaderboard data
leaderboard_df = get_leaderboard_df()
# Create the Gradio interface
demo = gr.Blocks(css=custom_css)
with demo:
gr.HTML(TITLE)
gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
with gr.Tabs() as tabs:
with gr.TabItem("π
Leaderboard", id=0):
leaderboard = init_leaderboard(leaderboard_df)
with gr.TabItem("π Visualizations", id=1):
gr.Markdown("## Performance Comparisons")
with gr.Row():
with gr.Column():
gr.Markdown("### Text vs. Visual Scores")
# Add a visualization component here (e.g., scatter plot)
with gr.Column():
gr.Markdown("### Score Breakdown by Task Type")
# Add a visualization component here (e.g., bar chart)
with gr.Row():
model_selector = gr.Dropdown(
choices=leaderboard_df["model"].tolist(),
label="Select Model for Detailed Analysis",
multiselect=False,
)
with gr.TabItem("π About", id=2):
gr.Markdown(ABOUT_TEXT, elem_classes="markdown-text")
with gr.TabItem("π Submit", id=3):
gr.Markdown(SUBMISSION_TEXT, elem_classes="markdown-text")
gr.Markdown("### Submission Details")
with gr.Row():
zip_file_input = gr.File(label="Upload submission ZIP file*")
with gr.Row():
with gr.Column():
model_name_input = gr.Textbox(label="Model Name*")
model_type_input = gr.Dropdown(
choices=["Open Source", "Close Source", "API", "Proprietary"],
label="Model Type*",
multiselect=False,
)
organization_input = gr.Textbox(label="Organization (if applicable)")
with gr.Column():
team_name_input = gr.Textbox(label="Team Name (if applicable)")
email_input = gr.Textbox(label="Contact Email*")
submission_link_input = gr.Textbox(label="GitHub Pull Request URL")
submit_button = gr.Button("Submit")
submission_result = gr.Markdown()
# Combined submission function that processes both ZIP and form data
def combined_submission(zip_file, model_name, model_type, organization, team_name, email, submission_link):
if zip_file is None:
return "Error: Please upload a ZIP file containing your submission."
if not model_name or not model_type or not email:
return "Error: Model name, model type, and email are required fields."
# Process ZIP file
zip_result = process_zip_submission(zip_file)
if zip_result.startswith("Error:"):
return zip_result
# Process form data
return f"Thank you for submitting {model_name} from {organization or team_name}! Your submission ZIP has been processed successfully. We will contact you at {email} if we need additional information."
submit_button.click(
combined_submission,
[zip_file_input, model_name_input, model_type_input, organization_input, team_name_input, email_input, submission_link_input],
submission_result,
)
with gr.Row():
with gr.Accordion("π Citation", open=False):
citation_button = gr.Textbox(
value=CITATION_TEXT,
label="Citation",
lines=8,
elem_id="citation-button",
show_copy_button=True,
)
return demo
# Launch the application
if __name__ == "__main__":
demo = create_demo()
demo.launch() |