Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)
Python
retrieve model files from folder
Abi Rajada1d4d5b55ff
diff --git a/backend/routes/evals.py b/backend/routes/evals.pyindex 84714cfd..cfd4b5cf 100644--- a/backend/routes/evals.py+++ b/backend/routes/evals.py@@ -9,7 +9,6 @@ from typing import List, Dictfrom llm import Llmfrom prompts.types import Stackfrom pathlib import Path-import base64router = APIRouter()@@ -32,14 +31,16 @@ async def get_eval_input_files():"""Get a list of all input files available for evaluations"""input_dir = os.path.join(EVALS_DIR, "inputs")try:- files = []+ files: list[InputFile] = []for filename in os.listdir(input_dir):if filename.endswith(".png"):file_path = os.path.join(input_dir, filename)files.append(InputFile(name=filename, path=file_path))return sorted(files, key=lambda x: x.name)except Exception as e:- raise HTTPException(status_code=500, detail=f"Error reading input files: {str(e)}")+ raise HTTPException(+ status_code=500, detail=f"Error reading input files: {str(e)}"+ )@router.get("/evals", response_model=list[Eval])@@ -185,9 +186,7 @@ async def run_evals(request: RunEvalsRequest) -> List[str]:for model in request.models:output_files = await run_image_evals(- model=model,- stack=request.stack,- input_files=request.files+ model=model, stack=request.stack, input_files=request.files)all_output_files.extend(output_files)@@ -223,7 +222,7 @@ async def get_best_of_n_evals(request: Request):query_params = dict(request.query_params)# Extract all folder paths (folder1, folder2, folder3, etc.)- folders = []+ folders: list[str] = []i = 1while f"folder{i}" in query_params:folders.append(query_params[f"folder{i}"])@@ -277,9 +276,9 @@ async def get_best_of_n_evals(request: Request):input_image = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="# Get HTML contents from all folders- outputs = []+ outputs: list[str] = []for folder_files in files_by_folder:- output_content = None+ output_content: str | None = Nonefor filename in folder_files.keys():if filename.startswith(base_name):with open(folder_files[filename], "r") as f:@@ -294,3 +293,34 @@ async def get_best_of_n_evals(request: Request):evals.append(Eval(input=input_image, outputs=outputs))return BestOfNEvalsResponse(evals=evals, folder_names=folder_names)+++class OutputFolder(BaseModel):+ name: str+ path: str+ modified_time: float++[email protected]("/output_folders", response_model=List[OutputFolder])+async def get_output_folders():+ """Get a list of all output folders available for evaluations, sorted by recently modified"""+ output_dir = os.path.join(EVALS_DIR, "results")+ try:+ folders: list[OutputFolder] = []+ for folder_name in os.listdir(output_dir):+ folder_path = os.path.join(output_dir, folder_name)+ if os.path.isdir(folder_path) and not folder_name.startswith("."):+ # Get modification time+ modified_time = os.path.getmtime(folder_path)+ folders.append(+ OutputFolder(+ name=folder_name, path=folder_path, modified_time=modified_time+ )+ )++ # Sort by modified time, most recent first+ return sorted(folders, key=lambda x: x.modified_time, reverse=True)+ except Exception as e:+ raise HTTPException(+ status_code=500, detail=f"Error reading output folders: {str(e)}"+ )diff --git a/frontend/src/components/evals/BestOfNEvalsPage.tsx b/frontend/src/components/evals/BestOfNEvalsPage.tsxindex a5952e60..28f45a10 100644--- a/frontend/src/components/evals/BestOfNEvalsPage.tsx+++ b/frontend/src/components/evals/BestOfNEvalsPage.tsx@@ -16,6 +16,12 @@ interface BestOfNEvalsResponse {folder_names: string[];}+interface OutputFolder {+ name: string;+ path: string;+ modified_time: number;+}+function BestOfNEvalsPage() {const [evals, setEvals] = React.useState<Eval[]>([]);const [outcomes, setOutcomes] = React.useState<Outcome[]>([]);@@ -25,6 +31,9 @@ function BestOfNEvalsPage() {const [isLoading, setIsLoading] = useState(false);const [selectedHtml, setSelectedHtml] = useState<string>("");+ // Available folders from backend+ const [availableFolders, setAvailableFolders] = useState<OutputFolder[]>([]);+// Navigation stateconst [currentComparisonIndex, setCurrentComparisonIndex] = useState(0);const [currentModelIndex, setCurrentModelIndex] = useState(0);@@ -35,6 +44,20 @@ function BestOfNEvalsPage() {// Refs for synchronized scrollingconst iframeRefs = useRef<(HTMLIFrameElement | null)[]>([]);+ // Fetch available folders on mount+ useEffect(() => {+ const fetchFolders = async () => {+ try {+ const response = await fetch(`${HTTP_BACKEND_URL}/output_folders`);+ const folders: OutputFolder[] = await response.json();+ setAvailableFolders(folders);+ } catch (error) {+ console.error("Error fetching folders:", error);+ }+ };+ fetchFolders();+ }, []);+// Synchronized scrolling effectuseEffect(() => {const setupSyncScrolling = () => {@@ -188,7 +211,7 @@ function BestOfNEvalsPage() {const loadEvals = async () => {if (folderPaths.some((path) => !path)) {- alert("Please enter all folder paths");+ alert("Please select all folder paths");return;}@@ -198,7 +221,7 @@ function BestOfNEvalsPage() {folderPaths.forEach((path, index) => {queryParams.append(`folder${index + 1}`,- `/Users/abi/Downloads/${path}`+ path);});@@ -234,6 +257,23 @@ function BestOfNEvalsPage() {const stats = calculateStats();const currentEval = evals[currentComparisonIndex];++ // Format time helper+ const formatTimeAgo = (timestamp: number) => {+ const now = Date.now() / 1000;+ const diff = now - timestamp;++ if (diff < 3600) {+ const minutes = Math.floor(diff / 60);+ return `${minutes}m ago`;+ } else if (diff < 86400) {+ const hours = Math.floor(diff / 3600);+ return `${hours}h ago`;+ } else {+ const days = Math.floor(diff / 86400);+ return `${days}d ago`;+ }+ };// Copy results as CSV to clipboardconst copyResultsAsCSV = async () => {@@ -269,17 +309,42 @@ function BestOfNEvalsPage() {{evals.length === 0 ? (/* Setup Section */<div className="flex flex-col gap-4 max-w-5xl mx-auto px-6">- <h2 className="text-xl font-semibold text-gray-200 mb-2">Configure Model Comparison</h2>+ <div className="flex items-center justify-between mb-2">+ <h2 className="text-xl font-semibold text-gray-200">Configure Model Comparison</h2>+ <button+ onClick={async () => {+ try {+ const response = await fetch(`${HTTP_BACKEND_URL}/output_folders`);+ const folders: OutputFolder[] = await response.json();+ setAvailableFolders(folders);+ } catch (error) {+ console.error("Error fetching folders:", error);+ }+ }}+ className="bg-gray-600 hover:bg-gray-700 text-white px-3 py-1.5 rounded-lg text-sm transition-colors flex items-center gap-2"+ title="Refresh folder list"+ >+ <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />+ </svg>+ Refresh+ </button>+ </div><div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3">{folderPaths.map((path, index) => (<div key={index} className="flex gap-2">- <input- type="text"+ <selectvalue={path}onChange={(e) => updateFolderPath(index, e.target.value)}- placeholder="Enter folder name in Downloads"- className="flex-1 px-4 py-2 rounded-lg bg-gray-700 text-white placeholder-gray-400 border border-gray-600 focus:border-blue-500 focus:outline-none transition-colors text-sm"- />+ className="flex-1 px-4 py-2 rounded-lg bg-gray-700 text-white border border-gray-600 focus:border-blue-500 focus:outline-none transition-colors text-sm"+ >+ <option value="">Select a folder...</option>+ {availableFolders.map((folder) => (+ <option key={folder.path} value={folder.path}>+ {folder.name} ({formatTimeAgo(folder.modified_time)})+ </option>+ ))}+ </select>{index > 0 && (<buttononClick={() => removeFolderInput(index)}