import gradio as gr import json from typing import Dict, List import os class DatasetViewer: def __init__(self, json_path: str): with open(json_path, 'r', encoding='utf-8') as f: self.data = json.load(f) self.current_index = 0 self.total_items = len(self.data) def get_current_item(self) -> tuple: item = self.data[self.current_index] return ( item.get('corrected_description', ''), # Left Text item.get('pddl_domain_processed', ''), # Right Text f"{self.current_index + 1}. {item.get('file_name', '')}" # Current Location ) def next_item(self) -> tuple: self.current_index = (self.current_index + 1) % self.total_items return self.get_current_item() def prev_item(self) -> tuple: self.current_index = (self.current_index - 1) % self.total_items return self.get_current_item() def jump_to_index(self, selected_key: str) -> tuple: try: # Extract index from the selected text index = int(selected_key.split('.')[0]) - 1 if 0 <= index < self.total_items: self.current_index = index except: pass return self.get_current_item() def get_choices(self, search_term: str = '') -> List[str]: choices = [] for idx, item in enumerate(self.data): preview = f"{item.get('file_name', '')}" choice = f"{idx + 1}. {preview}" if search_term.lower() in choice.lower(): choices.append(choice) return choices def create_ui(): # Initialize dataset viewer viewer = DatasetViewer('our_benchmark_modified.json') with gr.Blocks(css=""" .container { margin: 15px; } .text-display { min-height: 200px; } .navigation { text-align: center; margin: 10px; } .hf-yellow-btn { background: #FFA726 !important; /* Hugging Face 黄色 */ border: none !important; } .hf-yellow-btn:hover { background: #FF9800 !important; /* 鼠标悬停时的颜色 */ box-shadow: 0 0 0 0.2rem rgba(255, 167, 38, 0.5) !important; } """) as demo: gr.HTML("