import gradio as gr import sys import pandas as pd import os import json import shutil import zipfile import uuid import requests TEMP_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tmp') metric_scale = { 'human_face_similarity': 1.5, 'clip_score': 0.02, 'env_clip': 1.5, 'other_subject_clip': 1.5, 'image_quality': 1, 'dynamic_degree': 1, 'aesthetic_quality': 1, 'motion_smoothness': 1, } class ModelResult: def __init__(self, data): self.name = data['model_name'] self.project_link = data.get('project_link', None) self.result = data['result'] def to_dict(self): if self.project_link is not None: res = { 'model_name': f'{self.name}', } else: res = { 'model_name': self.name, } total_score = [] for metric in self.result.keys(): res[metric] = round(float(self.result[metric]) - 1e-3, 4) total_score.append(self.result[metric] * metric_scale[metric]) total_score = sum(total_score) / len(total_score) res['comprehensive score'] = round(total_score, 4) return res def upload_large_zip_stream(zip_path, model_name, org_link, chunk_size=10*1024*1024): """Stream upload a large zip file in chunks""" file_id = str(uuid.uuid4()) total_size = os.path.getsize(zip_path) total_chunks = (total_size + chunk_size - 1) // chunk_size with open(zip_path, 'rb') as f: for chunk_num in range(total_chunks): chunk = f.read(chunk_size) files = { 'file': (os.path.basename(zip_path), chunk, 'application/zip'), } params = { 'chunk_number': int(chunk_num), 'total_chunks': int(total_chunks), 'file_id': file_id, 'model_name': model_name, } response = requests.post( "http://47.239.99.255/A2Bench_evaluation/update_zip/", files=files, params=params ) data = response.json() print(f"Uploaded chunk {chunk_num+1}/{total_chunks} - {data['progress']}") print("Final upload status:", response.json()) assert 'unzip_video_path' in response.json(), "Upload failed" assert 'unzip_status' in response.json(), "Upload failed" unzip_video_path = response.json()['unzip_video_path'] unzip_status = response.json()['unzip_status'] if unzip_status == "success": return unzip_video_path else: raise gr.Error("Upload failed") def eval_request(model_name, org_link, result_path): params = { "model_name": model_name, "org_link": org_link, "result_path": result_path } response = requests.post("http://47.239.99.255/A2Bench_evaluation/eval", params=params) return response.json() def evaluation(zip_path, model_name, org_link): try: unzip_video_path = upload_large_zip_stream(zip_path, model_name, org_link) if org_link=="": org_link = None eval_request(model_name, org_link, unzip_video_path) return "Evaluation completed successfully!" except Exception as e: raise gr.Error(f"Evaluation failed: {str(e)}") def load_leaderboard(): leaderboard_list = [] file_list = requests.get("http://47.239.99.255/A2Bench_evaluation/load_leaderboard") for file in file_list.json(): leaderboard_list.append(ModelResult(file)) return leaderboard_list HEADER = ['model_name', 'comprehensive score', 'clip_score', 'human_face_similarity', 'env_clip', 'other_subject_clip', 'image_quality', 'dynamic_degree', 'aesthetic_quality', 'motion_smoothness'] def display_table(): leaderboard_list = load_leaderboard() data = {} for metric in HEADER: data[metric] = [] for model_result in leaderboard_list: result_dict = model_result.to_dict() for metric in HEADER: data[metric].append(result_dict[metric]) df = pd.DataFrame(data) df = df.sort_values(by='comprehensive score', ascending=False) return df _HEADER_ = '''
Paper: SkyReels-A2 | Codes: GitHub | HugginceFace
Prompt: A man feeding a bird in the park.