import React, { useState, useEffect, useRef } from 'react'; import { DataTable } from 'primereact/datatable'; import { Column } from 'primereact/column'; import Table from '../styled_components/Table'; import { Button } from 'primereact/button'; import { Tooltip } from 'primereact/tooltip'; import jsPDF from 'jspdf'; import autoTable from 'jspdf-autotable'; import axios from "axios"; import { useContext } from "react"; import { DataContext } from "../DataContext"; import { ProgressSpinner } from 'primereact/progressspinner'; import styled from 'styled-components'; export function Leaderboard({ baseUrl }) { const [products, setProducts] = useState(null); const dt = useRef(null); const { sharedData, setSharedData } = useContext(DataContext); let data = [ { Model: "OpenAi/whisper", WER: 0.15, FS: 0.87, FS_G: 8.41, FS_L: 0.85, FS_SEG: 0.8, FS_E: 0.8 }, { Model: "OpenAi/whisper-mini", WER: 0.25, FS: 0.8, FS_G: 0.85, FS_L: 0.75, FS_SEG: 0.65, FS_E: 0.8 } ] useEffect(() => { if (!(sharedData && sharedData.Leaderboard)) { const fetchData = async () => { const headers = { 'ngrok-skip-browser-warning': "10008" }; const res = await axios.get(`${baseUrl}/fetch`, { headers }); let Data = res.data.data; // Await the promise const uniqueData = Data.filter((value, index, self) => index === self.findIndex((t) => t.Model === value.Model) ); setProducts(uniqueData); // Set the resolved data to state setSharedData({ ...sharedData, Leaderboard: uniqueData }) } fetchData(); } else { setProducts(sharedData.Leaderboard); } }, [sharedData, setSharedData, baseUrl]); const exportCSV = (selectionOnly) => { dt.current.exportCSV({ selectionOnly }); }; const exportPdf = () => { // const doc = new jsPDF(); const doc = new jsPDF({ orientation: 'landscape' }); // Add heading // Set font size and get page width doc.setFontSize(16); const pageWidth = doc.internal.pageSize.width; // Get page width const text = 'Leaderboard Report'; const textWidth = doc.getTextWidth(text); // Get text width const xPosition = (pageWidth - textWidth) / 2; // Center position // Add centered heading doc.text(text, xPosition, 15); // Define table headers const columns = [ { header: 'Model Name', dataKey: 'Model' }, { header: 'Fairness Adjusted ASR Score', dataKey: 'FAAS' }, { header: 'Average WER', dataKey: 'WER' }, { header: 'Average RTFX', dataKey: 'RTFX' }, { header: 'Overall Fairness Score', dataKey: 'FS' }, { header: 'Fairness Score (Gender)', dataKey: 'FS_G' }, { header: 'Fairness Score (First Language)', dataKey: 'FS_L' }, { header: 'Fairness Score (Socioeconomic Background)', dataKey: 'FS_SEG' }, { header: 'Fairness Score (Ethnicity)', dataKey: 'FS_E' } ]; // Convert data into row format const rows = products.map(row => columns.map(col => row[col.dataKey])); // Call autoTable properly autoTable(doc, { theme: 'grid', head: [columns.map(col => col.header)], // Table headers body: rows, // Table data startY: 20, // Set Y position after the heading styles: { lineWidth: 0.15 }, // Ensure grid lines are visible headStyles: { textColor: 255, lineWidth: 0.15 } // Ensure header has grid lines }); doc.save('Leaderboard.pdf'); }; const header = (
); //! For making the model name hyperlinks const [selectedCell, setSelectedCell] = useState(null); const onCellClick = (event) => { if(event.field!="Model") return ; const url = `https://huggingface.co/${event.value}`; // Replace with your URL window.open(url, "_blank", "noopener,noreferrer"); }; return (<> {/*

Leaderboard

*/} {/*

Track Top performing models

*/}

Leaderboard of the ASR models audited on this platform :

{products ? (
setSelectedCell(e.value)} metaKeySelection={false} onCellClick={onCellClick} >
) : ()}

) } const H3 = styled.h3` color: #515458 !important `