Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files
assets/{index-5x5iLaUM.js → index-DOAQxHjz.js}
RENAMED
@@ -46,4 +46,4 @@ ${e.map(l=>R0(ii(l),2)).join(`,
|
|
46 |
`);let i=!1,o=[],c=!1,a=[];for(let U=0;U<d.length;U++){const u=d[U];if(u.startsWith("```")){i?(r.push(p.jsx("pre",{children:o.join(`
|
47 |
`)},`code-${U}`)),i=!1,o=[]):i=!0;continue}if(i){o.push(u);continue}if(u.includes("**")){const W=u.split("**");r.push(p.jsx("p",{children:W.map((N,R)=>R%2?p.jsx("strong",{children:N},R):N)},U));continue}if(u.includes("*")){const W=u.split("*");r.push(p.jsx("p",{children:W.map((N,R)=>R%2?p.jsx("em",{children:N},R):N)},U));continue}if(u.startsWith("#")){const W=u.split(" ")[0].length,N=u.slice(W+1),R=`h${W}`;r.push(p.jsx(R,{children:N},U));continue}const Z=/!\[(.*?)\]\((.*?)\)/.exec(u);if(Z){const[,W,N]=Z;r.push(p.jsx("img",{src:N,alt:W},U));continue}if(u.includes("[")&&u.includes("]")&&u.includes("(")&&u.includes(")")){const W=u.replace(/\[(.*?)\]\((.*?)\)/g,(N,R,h)=>`<a href="${h}">${R}</a>`);r.push(p.jsx("p",{dangerouslySetInnerHTML:{__html:W}},U));continue}if(u.startsWith("-")||u.startsWith("*")||u.startsWith("+")){const W=u.slice(1).trim();a.push(p.jsx("li",{children:W},`list-item-${U}`)),c=!0;continue}c&&a.length>0&&(r.push(p.jsx("ul",{children:a},`list-${U}`)),a=[],c=!1),r.push(p.jsx("p",{children:u},U))}return i&&o.length>0&&r.push(p.jsx("pre",{children:o.join(`
|
48 |
`)},`code-${d.length}`)),c&&a.length>0&&r.push(p.jsx("ul",{children:a},`list-${d.length}`)),p.jsx("div",{className:l,children:r})}return t(e)}function S0({source:e,setError:l}){const[t,n]=k.useState(0),[r,d]=k.useState(),{resolveUrl:i,requestInit:o}=e;return k.useEffect(()=>{async function c(){try{const a=await fetch(i,o),U=await a.text(),u=rc(a.headers)??U.length;if(a.status===401){l(new Error(U)),d(void 0);return}l(void 0),d({text:U,fileSize:u})}catch(a){l(a),d(void 0)}finally{n(2)}}n(a=>a!==0?a:(c().catch(()=>{}),1))},[i,o,l]),p.jsxs(Nn,{content:r,children:[p.jsx(M0,{className:"markdown",text:(r==null?void 0:r.text)??""}),t===1&&p.jsx(Wn,{className:"center"})]})}function y0(e,l){const t=new URL(location.href);if(l!=null&&l.appendOnly||(t.search=""),e!==void 0)for(const[n,r]of Object.entries(e))t.searchParams.set(n,r);return t.toString()}function k0(e){return y0(e,{appendOnly:!0})}function Q0({df:e,row:l,col:t,setProgress:n,setError:r,onClose:d}){const[i,o]=k.useState();k.useEffect(()=>{async function a(){try{n(.5);const U=e.rows(l,l+1),u=await Ir(U,1,e.header)[0][e.header[t]].then(hr);o(u)}catch(U){r(U)}finally{n(1)}}a().catch(()=>{})},[e,t,l,n,r]);const c=p.jsxs(p.Fragment,{children:[p.jsx("button",{className:"slideClose",onClick:d,children:" "}),p.jsxs("span",{children:["column `",e.header[t],"`"]}),p.jsxs("span",{children:["row ",l+1]})]});return p.jsx(Nn,{headers:c,children:p.jsx("code",{className:"text",children:i})})}const Go={MIN:100,DEFAULT:400};function G0({mainContent:e,panelContent:l,isPanelOpen:t,config:n}){var r,d;const i=(r=n==null?void 0:n.slidePanel)!=null&&r.minWidth&&n.slidePanel.minWidth>0?n.slidePanel.minWidth:Go.MIN;function o(R){if(R&&i<=R)return R}const c=o((d=n==null?void 0:n.slidePanel)==null?void 0:d.defaultWidth)??Go.DEFAULT,[a,U]=k.useState(c),[u,Z]=k.useState(-1),W=Bo.createRef();k.useEffect(()=>{function R(V){u!==-1&&U(Math.max(i,u-V.clientX))}function h(){u!==-1&&Z(-1)}return u!==-1&&(document.addEventListener("mousemove",R),document.addEventListener("mouseup",h)),()=>{document.removeEventListener("mousemove",R),document.removeEventListener("mouseup",h)}},[u,i]);const N=k.useCallback(R=>{W.current&&W.current.offsetWidth<a?(U(W.current.offsetWidth),Z(R.clientX+W.current.offsetWidth)):Z(R.clientX+a)},[W,a]);return p.jsxs("div",{className:"slideContainer",children:[p.jsx("div",{className:"slideMain",children:e}),t&&p.jsx("div",{className:"resizer",onMouseDown:N}),p.jsx("div",{className:u===-1?"slidePanel":"slidePanel slideDragging",ref:W,style:t?{width:a}:void 0,children:l})]})}function b0({source:e,setProgress:l,setError:t,config:n}){const[r,d]=k.useState(0),[i,o]=k.useState(),[c,a]=k.useState(),{resolveUrl:U,requestInit:u,sourceId:Z}=e;k.useEffect(()=>{async function m(){try{l(.33);const T=await $a({url:U,requestInit:u}),M={url:U,byteLength:T.byteLength,requestInit:u};l(.66);const S=await qa(T);let G=nu(M,S);G=gZ(G);const b=T.byteLength;o({dataframe:G,fileSize:b})}catch(T){t(T)}finally{d(2),l(1)}}r===0&&(d(1),m().catch(()=>{}))},[r,U,u,t,l]),k.useEffect(()=>{d(0)},[e]),k.useEffect(()=>{if(!c)return;function m(T){T.key==="Escape"&&a(void 0)}return window.addEventListener("keydown",m),()=>{window.removeEventListener("keydown",m)}},[c]);const W=k.useCallback(({col:m,row:T})=>{var M,S;return((S=(M=n==null?void 0:n.routes)==null?void 0:M.getCellRouteUrl)==null?void 0:S.call(M,{sourceId:Z,col:m,row:T}))||k0({col:m.toString(),row:T.toString()})},[n,Z]),N=k.useCallback((m,T)=>{(c==null?void 0:c.col)===m&&c.row===T?a(void 0):a({row:T,col:m})},[c]),R=k.useCallback((m,T,M)=>{m.button===1&&(m.preventDefault(),window.open(W({row:M,col:T}),"_blank"))},[W]),h=p.jsxs("span",{children:[(i==null?void 0:i.dataframe.numRows.toLocaleString())??"..."," rows"]}),V=p.jsxs(Nn,{content:i,headers:h,children:[(i==null?void 0:i.dataframe)&&p.jsx(CZ,{cacheKey:U,data:i.dataframe,onDoubleClickCell:N,onMouseDownCell:R,onError:t}),r===1&&p.jsx(Wn,{className:"center"})]});let s;return i!=null&&i.dataframe&&c&&(s=p.jsx(Q0,{col:c.col,df:i.dataframe,onClose:()=>{a(void 0)},row:c.row,setError:t,setProgress:l})),p.jsx(G0,{isPanelOpen:!!(i!=null&&i.dataframe&&c),mainContent:V,panelContent:s,config:n})}function E0({source:e,setError:l}){const[t,n]=k.useState(0),[r,d]=k.useState(),{resolveUrl:i,requestInit:o}=e;k.useEffect(()=>{async function a(){try{const U=await fetch(i,o),u=await U.text(),Z=rc(U.headers)??u.length;if(U.status===401){l(new Error(u)),d(void 0);return}l(void 0),d({text:u,fileSize:Z})}catch(U){l(U),d(void 0)}finally{n(2)}}n(U=>U!==0?U:(a().catch(()=>{}),1))},[i,o,l]);const c=p.jsx(p.Fragment,{children:p.jsxs("span",{children:[w0((r==null?void 0:r.text)??"")," lines"]})});return p.jsxs(Nn,{content:r,headers:c,children:[p.jsx("code",{className:"text",children:r==null?void 0:r.text}),t&&p.jsx(Wn,{className:"center"})]})}function w0(e){let l=0;for(const t of e)t===`
|
49 |
-
`&&l++;return l.toLocaleString("en-US")}function X0({source:e,setError:l,setProgress:t,config:n}){const{fileName:r}=e;return r.endsWith(".md")?p.jsx(S0,{source:e,setError:l}):r.endsWith(".parquet")?p.jsx(b0,{source:e,setError:l,setProgress:t,config:n}):W0.some(d=>r.endsWith(d))?p.jsx(T0,{source:e,setError:l}):p.jsx(E0,{source:e,setError:l,setProgress:t})}function f0({source:e,config:l}){const[t,n]=k.useState(),[r,d]=k.useState();return p.jsxs(dc,{progress:t,error:r,title:e.fileName,children:[p.jsx(lc,{source:e,config:l}),p.jsx(X0,{source:e,setProgress:n,setError:d,config:l})]})}function x0({source:e,config:l}){const[t,n]=k.useState(),[r,d]=k.useState();return k.useEffect(()=>{e.listFiles().then(n).catch(i=>{n([]),d(i instanceof Error?i:new Error(`Failed to fetch files - ${i}`))})},[e]),p.jsxs(dc,{error:r,title:e.prefix,children:[p.jsx(lc,{source:e,config:l}),t&&t.length>0&&p.jsx("ul",{className:"file-list",children:t.map((i,o)=>{var c,a;return p.jsx("li",{children:p.jsxs("a",{href:((a=(c=l==null?void 0:l.routes)==null?void 0:c.getSourceRouteUrl)==null?void 0:a.call(c,{sourceId:i.sourceId}))??location.href,children:[p.jsx("span",{className:Fr("file-name","file",i.kind==="directory"&&"folder"),children:i.name}),i.kind==="file"&&p.jsxs(p.Fragment,{children:[i.size!==void 0&&p.jsx("span",{className:"file-size",title:i.size.toLocaleString()+" bytes",children:ru(i.size)}),p.jsx("span",{className:"file-date",title:U0(i),children:Z0(i)})]})]})},o)})}),(t==null?void 0:t.length)===0&&p.jsx("div",{className:"center",children:"No files"}),t===void 0&&p.jsx(Wn,{className:"center"})]})}function Y0({source:e,navigation:l,config:t}){return e.kind==="directory"?p.jsx(x0,{source:e,config:t}):(l==null?void 0:l.row)!==void 0&&l.col!==void 0?p.jsx(p0,{source:e,row:l.row,col:l.col,config:t}):p.jsx(f0,{source:e,config:t})}function ic(e){const l=e.replace(/\?.*$/,"").split("/").at(-1);if(!l)throw new Error("Cannot extract a filename");return l}function K0(e,l){if(URL.canParse(e))return{kind:"file",sourceId:e,sourceParts:[{text:e,sourceId:e}],fileName:ic(e),resolveUrl:e,requestInit:void 0}}var J0=Object.defineProperty,z0=(e,l,t)=>l in e?J0(e,l,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[l]=t,Jn=(e,l,t)=>(z0(e,typeof l!="symbol"?l+"":l,t),t),Lr="https://huggingface.co";async function Vt(e,l){var t,n;const r=new I0(e.url,e.status,(t=e.headers.get("X-Request-Id"))!=null?t:void 0);r.message=`Api error with status ${r.statusCode}`;const d=[`URL: ${r.url}`,r.requestId?`Request ID: ${r.requestId}`:void 0].filter(Boolean).join(". ");if((n=e.headers.get("Content-Type"))!=null&&n.startsWith("application/json")){const i=await e.json();r.message=i.error||i.message||r.message,r.data=i}else r.data={message:await e.text()};throw r.message+=`. ${d}`,r}var I0=class extends Error{constructor(e,l,t,n){super(n),Jn(this,"statusCode"),Jn(this,"url"),Jn(this,"requestId"),Jn(this,"data"),this.statusCode=l,this.requestId=t,this.url=e}};function bo(e){if(!e.startsWith("hf_"))throw new TypeError("Your access token must start with 'hf_'")}function du(e){var l;if(e.accessToken)return bo(e.accessToken),e.accessToken;if((l=e.credentials)!=null&&l.accessToken)return bo(e.credentials.accessToken),e.credentials.accessToken}function L0(e){if(typeof e!="string")return e;if(e.startsWith("model/")||e.startsWith("models/"))throw new TypeError("A repo designation for a model should not start with 'models/', directly specify the model namespace / name");if(e.startsWith("space/"))throw new TypeError("Spaces should start with 'spaces/', plural, not 'space/'");if(e.startsWith("dataset/"))throw new TypeError("Datasets should start with 'dataset/', plural, not 'dataset/'");const l=e.split("/").length-1;if(e.startsWith("spaces/")){if(l!==2)throw new TypeError("Space Id must include namespace and name of the space");return{type:"space",name:e.slice(7)}}if(e.startsWith("datasets/")){if(l>2)throw new TypeError("Too many slashes in repo designation: "+e);return{type:"dataset",name:e.slice(9)}}if(l>1)throw new TypeError("Too many slashes in repo designation: "+e);return{type:"model",name:e}}new Promise(e=>{});function D0(e){if(globalThis.Buffer)return globalThis.Buffer.from(e).toString("base64");{const l=[];return e.forEach(t=>{l.push(String.fromCharCode(t))}),globalThis.btoa(l.join(""))}}function g0(e,l){return Object.assign({},...l.map(t=>{if(e[t]!==void 0)return{[t]:e[t]}}))}function iu(e){const l=/<(https?:[/][/][^>]+)>;\s+rel="([^"]+)"/g;return Object.fromEntries([...e.matchAll(l)].map(([,t,n])=>[n,t]))}var B0=["private","downloads","gated","likes","lastModified"];async function*v0(e){var l,t,n,r,d,i,o,c,a;const U=e&&du(e);let u=(l=e==null?void 0:e.limit)!=null?l:1/0;const Z=new URLSearchParams([...Object.entries({limit:String(Math.min(u,500)),...(t=e==null?void 0:e.search)!=null&&t.owner?{author:e.search.owner}:void 0,...(n=e==null?void 0:e.search)!=null&&n.query?{search:e.search.query}:void 0}),...(i=(d=(r=e==null?void 0:e.search)==null?void 0:r.tags)==null?void 0:d.map(N=>["filter",N]))!=null?i:[],...B0.map(N=>["expand",N]),...(c=(o=e==null?void 0:e.additionalFields)==null?void 0:o.map(N=>["expand",N]))!=null?c:[]]).toString();let W=`${(e==null?void 0:e.hubUrl)||Lr}/api/datasets`+(Z?"?"+Z:"");for(;W;){const N=await((a=e==null?void 0:e.fetch)!=null?a:fetch)(W,{headers:{accept:"application/json",...e!=null&&e.credentials?{Authorization:`Bearer ${U}`}:void 0}});if(!N.ok)throw await Vt(N);const R=await N.json();for(const V of R)if(yield{...(e==null?void 0:e.additionalFields)&&g0(V,e.additionalFields),id:V._id,name:V.id,private:V.private,downloads:V.downloads,likes:V.likes,gated:V.gated,updatedAt:new Date(V.lastModified)},u--,u<=0)return;const h=N.headers.get("Link");W=h?iu(h).next:void 0}}async function*C0(e){var l;const t=du(e),n=L0(e.repo);let r=`${e.hubUrl||Lr}/api/${n.type}s/${n.name}/tree/${e.revision||"main"}${e.path?"/"+e.path:""}?recursive=${!!e.recursive}&expand=${!!e.expand}`;for(;r;){const d=await((l=e.fetch)!=null?l:fetch)(r,{headers:{accept:"application/json",...t?{Authorization:`Bearer ${t}`}:void 0}});if(!d.ok)throw await Vt(d);const i=await d.json();for(const c of i)yield c;const o=d.headers.get("Link");r=o?iu(o).next:void 0}}async function Eo(e){var l,t;if(typeof window>"u")throw new Error("oauthHandleRedirect is only available in the browser");const n=new URLSearchParams(window.location.search),[r,d]=[n.get("error"),n.get("error_description")];if(r)throw new Error(`${r}: ${d}`);const i=n.get("code"),o=localStorage.getItem("huggingface.co:oauth:nonce");if(!i)throw new Error("Missing oauth code from query parameters in redirected URL");if(!o)throw new Error("Missing oauth nonce from localStorage");const c=localStorage.getItem("huggingface.co:oauth:code_verifier");if(!c)throw new Error("Missing oauth code_verifier from localStorage");const a=n.get("state");if(!a)throw new Error("Missing oauth state from query parameters in redirected URL");let U;try{U=JSON.parse(a)}catch{throw new Error("Invalid oauth state in redirected URL, unable to parse JSON: "+a)}if(U.nonce!==o)throw new Error("Invalid oauth state in redirected URL");const u=Lr,Z=`${new URL(u).origin}/.well-known/openid-configuration`,W=await fetch(Z,{headers:{Accept:"application/json"}});if(!W.ok)throw await Vt(W);const N=await W.json(),R=await fetch(N.token_endpoint,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"authorization_code",code:i,redirect_uri:U.redirectUri,code_verifier:c}).toString()});if(localStorage.removeItem("huggingface.co:oauth:code_verifier"),localStorage.removeItem("huggingface.co:oauth:nonce"),!R.ok)throw await Vt(R);const h=await R.json(),V=new Date(Date.now()+h.expires_in*1e3),s=await fetch(N.userinfo_endpoint,{headers:{Authorization:`Bearer ${h.access_token}`}});if(!s.ok)throw await Vt(s);const m=await s.json();return{accessToken:h.access_token,accessTokenExpiresAt:V,userInfo:{id:m.sub,name:m.name,fullname:m.preferred_username,email:m.email,emailVerified:m.email_verified,avatarUrl:m.picture,websiteUrl:m.website,isPro:m.isPro,orgs:(t=(l=m.orgs)==null?void 0:l.map(T=>({id:T.sub,name:T.name,fullname:T.name,isEnterprise:T.isEnterprise,canPay:T.canPay,avatarUrl:T.picture,roleInOrg:T.roleInOrg})))!=null?t:[]},state:U.state,scope:h.scope}}async function j0(e){if(typeof window>"u")throw new Error("oauthHandleRedirect is only available in the browser");const l=new URLSearchParams(window.location.search);return l.has("error")?Eo():l.has("code")?localStorage.getItem("huggingface.co:oauth:nonce")?Eo():(console.warn("Missing oauth nonce from localStorage. This can happen when the user refreshes the page after logging in, without changing the URL."),!1):!1}async function H0(e){var l,t;if(typeof window>"u")throw new Error("oauthLogin is only available in the browser");const n=(e==null?void 0:e.hubUrl)||Lr,r=`${new URL(n).origin}/.well-known/openid-configuration`,d=await fetch(r,{headers:{Accept:"application/json"}});if(!d.ok)throw await Vt(d);const i=await d.json(),o=globalThis.crypto.randomUUID(),c=globalThis.crypto.randomUUID()+globalThis.crypto.randomUUID();localStorage.setItem("huggingface.co:oauth:nonce",o),localStorage.setItem("huggingface.co:oauth:code_verifier",c);const a=(e==null?void 0:e.redirectUrl)||window.location.href,U=JSON.stringify({nonce:o,redirectUri:a,state:e==null?void 0:e.state}),u=(t=(l=window==null?void 0:window.huggingface)==null?void 0:l.variables)!=null?t:null,Z=(e==null?void 0:e.clientId)||(u==null?void 0:u.OAUTH_CLIENT_ID);if(!Z)throw u?new Error("Missing clientId, please add hf_oauth: true to the README.md's metadata in your static Space"):new Error("Missing clientId");const W=D0(new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256",new TextEncoder().encode(c)))).replace(/[+]/g,"-").replace(/[/]/g,"_").replace(/=/g,"");return`${i.authorization_endpoint}?${new URLSearchParams({client_id:Z,scope:(e==null?void 0:e.scopes)||(u==null?void 0:u.OAUTH_SCOPES)||"openid profile",response_type:"code",redirect_uri:a,state:U,code_challenge:W,code_challenge_method:"S256"}).toString()}`}function cu(e){if(e.state)try{const l=JSON.parse(e.state);if(typeof l!="object"||l===null||!("urlBeforeLogin"in l))throw new Error("Invalid state");const{urlBeforeLogin:t}=l;if(typeof t!="string")throw new Error("Invalid redirect URL: not a string");const n=new URL(t);if(n.origin!==window.location.origin)throw new Error("Invalid redirect URL: different origin");localStorage.setItem("oauth",JSON.stringify({...e,state:null})),window.location.href=n.href}catch(l){console.error(l)}}function ou(e){const l=e.accessTokenExpiresAt>=new Date;return l||localStorage.removeItem("oauth"),l}function O0(){const e=localStorage.getItem("oauth");if(!e)return;const l=JSON.parse(e),t={...l,accessTokenExpiresAt:new Date(l.accessTokenExpiresAt)};if(ou(t))return cu(t),t}async function P0(){const e=await j0();if(!(!e||!ou(e)))return localStorage.setItem("oauth",JSON.stringify(e)),cu(e),e}async function A0(){const e=JSON.stringify({urlBeforeLogin:window.location.href}),l="huggingface"in window?{state:e}:{state:e,redirectUrl:new URL(window.location.href).origin+"/",clientId:"9c9ac5a3-b324-4df8-a70c-7a8055ff8421",scopes:"openid profile read-repos"},t=await H0(l)+"&prompt=consent";window.location.href=t}function _0(){localStorage.removeItem("oauth"),window.location.reload()}const Kt="https://huggingface.co/datasets";function su(e){const l=new URL(window.location.href);l.search=e,window.parent.postMessage({queryString:e},"https://huggingface.co"),window.location.assign(l)}function wo(e){const l=[{sourceId:`${Kt}/${e.repo}/tree/${e.branch}/`,text:`${Kt}/${e.repo}/${e.action}/${e.branch}/`}],t=e.path.split("/").filter(r=>r.length>0),n=t.at(-1);if(n){for(let r=0;r<t.length-1;r++)l.push({sourceId:`${Kt}/${e.repo}/tree/${e.branch}/${t.slice(0,r+1).join("/")}`,text:t[r]+"/"});l.push({sourceId:`${Kt}/${e.repo}/${e.action}/${e.branch}${e.path}`,text:n})}return l}function q0(e){return`${e.origin}/datasets/${e.repo}/tree/${e.branch}${e.path}`.replace(/\/$/,"")}async function $0(e,l){var r,d;const t=C0({repo:`datasets/${e.repo}`,revision:e.branch,path:"path"in e?e.path.replace(/^\//,""):"",expand:!0,accessToken:l==null?void 0:l.accessToken}),n=[];for await(const i of t)n.push({name:ic(i.path),eTag:(r=i.lastCommit)==null?void 0:r.id,size:i.size,lastModified:(d=i.lastCommit)==null?void 0:d.date,sourceId:`${e.origin}/datasets/${e.repo}/${i.type==="file"?"blob":"tree"}/${e.branch}/${i.path}`.replace(/\/$/,""),kind:i.type==="file"?"file":"directory"});return n}function eU(e,l){try{const t=lU(e);return t.kind==="file"?{kind:"file",sourceId:e,sourceParts:wo(t),fileName:ic(t.path),resolveUrl:t.resolveUrl,requestInit:l==null?void 0:l.requestInit}:{kind:"directory",sourceId:e,sourceParts:wo(t),prefix:q0(t),listFiles:()=>$0(t,l)}}catch(t){console.error(t);return}}function lU(e){var d,i,o;const l=new URL(e);if(l.protocol!=="https:"&&l.protocol!=="http:")throw new Error("url must be a HTTP URL");if(!["huggingface.co","huggingface.co","hf.co"].includes(l.host)||l.protocol!=="https:")throw new Error("Not a Hugging Face URL");const t=(d=/^\/datasets\/(?<namespace>[^/]+)\/(?<dataset>[^/]+)\/?$/.exec(l.pathname))==null?void 0:d.groups;if(t&&["namespace","dataset"].every(c=>c in t))return{kind:"directory",source:e,origin:l.origin,repo:t.namespace+"/"+t.dataset,action:"tree",branch:"main",path:""};const n=(i=/^\/datasets\/(?<namespace>[^/]+)\/(?<dataset>[^/]+)\/(?<action>tree)\/(?<branch>(refs\/(convert|pr)\/)?[^/]+)(?<path>(\/[^/]+)*)\/?$/.exec(l.pathname))==null?void 0:i.groups;if(n&&["namespace","dataset","action","branch","path"].every(c=>c in n)&&n.branch!=="refs"){const c=n.branch.replace(/\//g,"%2F");return{kind:"directory",source:`${l.origin}/datasets/${n.namespace}/${n.dataset}/${n.action}/${c}${n.path}`,origin:l.origin,repo:n.namespace+"/"+n.dataset,action:"tree",branch:c,path:n.path}}const r=(o=/^\/datasets\/(?<namespace>[^/]+)\/(?<dataset>[^/]+)\/(?<action>blob|resolve)\/(?<branch>(refs\/(convert|pr)\/)?[^/]+)(?<path>(\/[^/]+)+)$/.exec(l.pathname))==null?void 0:o.groups;if(r&&["namespace","dataset","action","branch","path"].every(c=>c in r)&&r.branch!=="refs"){const c=r.branch.replace(/\//g,"%2F");return{kind:"file",source:`${l.origin}/datasets/${r.namespace}/${r.dataset}/${r.action}/${c}${r.path}`,origin:l.origin,repo:r.namespace+"/"+r.dataset,action:r.action==="blob"?"blob":"resolve",branch:c,path:r.path,resolveUrl:`${l.origin}/datasets/${r.namespace}/${r.dataset}/resolve/${c}${r.path}`}}throw new Error("Unsupported Hugging Face URL")}const tU=""+new URL("sign-in-with-huggingface-lg-qDcc3w-B.svg",import.meta.url).href;function Jt({url:e,children:l,className:t}){const n=e?`?url=${e}`:"";return p.jsx("a",{className:t,href:`/${n}`,onClick:r=>{r.preventDefault(),r.stopPropagation(),su(n)},children:l})}function nU({accessToken:e}){const[l,t]=k.useState(),[n,r]=k.useState([]);k.useEffect(()=>{async function i(){const o=[];for await(const c of v0({search:{query:l},limit:10,credentials:e?{accessToken:e}:void 0}))o.push(c);r(o)}i().catch(o=>{r([]),console.error(o)})},[l,e]);function d(i){t(i.target.value)}return p.jsxs(p.Fragment,{children:[p.jsx("input",{type:"search",onChange:d}),p.jsx("ul",{className:"ref-list",children:n.map(i=>p.jsx("li",{style:{fontSize:"0.9rem"},children:p.jsx(Jt,{url:`${Kt}/${i.name}`,children:i.name})},i.name))})]})}function rU({auth:e}){const l=k.useRef(null);function t(n){n.preventDefault();const r=new FormData(n.currentTarget).get("url");su(`?url=${r}`)}return p.jsxs("div",{id:"welcome",children:[p.jsx("h1",{children:"hyparquet"}),p.jsxs("sub",{children:["/haɪ pɑːrˈkeɪ/",p.jsx("img",{src:"audio.svg",alt:"play hyparquet pronunciation",height:"18",width:"18",onClick:()=>{var n;(n=l.current)==null||n.play().catch(()=>{})}})]}),p.jsx("audio",{ref:l,src:"hyparquet.mp3"}),p.jsx("h2",{children:"in-browser parquet file reader"}),p.jsxs("p",{children:[p.jsx("a",{href:"https://www.npmjs.com/package/hyparquet",children:p.jsx("img",{src:"https://img.shields.io/npm/v/hyparquet",alt:"npm hyparquet"})})," ",p.jsx("a",{href:"https://github.com/hyparam/hyparquet",children:p.jsx("img",{src:"https://img.shields.io/github/stars/hyparam/hyparquet?style=social",alt:"star hyparquet"})})]}),p.jsxs("p",{children:["Online demo of"," ",p.jsx("a",{href:"https://github.com/hyparam/hyparquet",children:"hyparquet"}),": a parser for apache parquet files. Uses"," ",p.jsx("a",{href:"https://github.com/hyparam/hightable",children:"hightable"})," for high performance windowed table viewing."]}),p.jsxs("section",{children:[p.jsx("h3",{children:"Select a dataset on Hugging Face"}),e?p.jsxs("p",{children:["Logged in as",p.jsx("img",{src:e.userInfo.avatarUrl,alt:e.userInfo.name,style:{width:"1rem",height:"1rem",borderRadius:"50%",margin:"0 0.5rem"}}),e.userInfo.name," (",p.jsx("a",{onClick:()=>{_0()},children:"Log out"}),"). You can search your private and gated datasets."]}):p.jsxs(p.Fragment,{children:[p.jsx("p",{children:"Log in to search your private and gated datasets"}),p.jsx("p",{children:p.jsx("a",{onClick:()=>{A0().catch(()=>{})},children:p.jsx("img",{src:tU,alt:"Sign in with Hugging Face"})})})]}),p.jsx("p",{children:"Search for dataset:"}),p.jsx(nU,{accessToken:e==null?void 0:e.accessToken})]}),p.jsxs("section",{children:[p.jsx("h3",{children:"Parquet URL"}),p.jsx("p",{children:"You can also set a url to see your parquet data. 👀"}),p.jsxs("form",{onSubmit:t,style:{display:"flex",gap:"1rem"},children:[p.jsx("label",{htmlFor:"url",children:"URL"}),p.jsx("input",{name:"url",defaultValue:"https://huggingface.co/datasets/codeparrot/github-code/resolve/main/data/train-00000-of-01126.parquet",style:{width:"100%"},type:"url"}),p.jsx("button",{style:{fontSize:"1rem",padding:"0 0.5rem"},type:"submit",children:"Open"})]}),p.jsxs("p",{children:[p.jsx("p",{children:"Example files:"}),p.jsxs("ul",{className:"quick-links",children:[p.jsx("li",{children:p.jsx(Jt,{className:"aws",url:"https://hyperparam-public.s3.amazonaws.com/wiki-en-00000-of-00041.parquet",children:"s3://wiki-en-00000-of-00041.parquet"})}),p.jsx("li",{children:p.jsx(Jt,{className:"azure",url:"https://hyperparam.blob.core.windows.net/hyperparam/starcoderdata-js-00000-of-00065.parquet",children:"azure://starcoderdata-js-00000-of-00065.parquet"})}),p.jsx("li",{children:p.jsx(Jt,{className:"huggingface",url:"https://huggingface.co/datasets/codeparrot/github-code/resolve/main/data/train-00000-of-01126.parquet",children:"huggingface://github-code-00000-of-01126.parquet"})}),p.jsx("li",{children:p.jsx(Jt,{className:"github",url:"https://raw.githubusercontent.com/hyparam/hyparquet/master/test/files/rowgroups.parquet",children:"github://rowgroups.parquet"})})]})]})]})]})}function Xo(e){if(e)return{headers:{Authorization:`Bearer ${e}`}}}function dU(){const e=O0(),[l,t]=k.useState(e),[n,r]=k.useState(e==null?void 0:e.accessToken),[d,i]=k.useState(Xo(e==null?void 0:e.accessToken));k.useEffect(()=>{l||P0().then(Z=>{t(Z),Z&&(r(Z.accessToken),i(Xo(Z.accessToken)))}).catch(Z=>{console.error("Error fetching OAuth"),console.error(Z)})},[l]);const o=new URLSearchParams(location.search),c=o.get("url"),a=o.get("row")===null?void 0:Number(o.get("row")),U=o.get("col")===null?void 0:Number(o.get("col"));if(c===null)return p.jsx(rU,{auth:l});const u=eU(c,{requestInit:d,accessToken:n})??K0(c);if(!u){const Z="/?url=https://huggingface.co/datasets/severo/test-parquet/resolve/main/parquet/csv-train-00000-of-00001.parquet";return p.jsxs("div",{children:["Could not load a data source. You have to pass a valid source in the url, eg: ",p.jsx("a",{href:Z,children:Z}),"."]})}return p.jsx(Y0,{source:u,navigation:{row:a,col:U},config:{routes:{getSourceRouteUrl:({sourceId:Z})=>`/?url=${Z}`,getCellRouteUrl:({sourceId:Z,col:W,row:N})=>`/?url=${Z}&col=${W}&row=${N}`}}})}const au=document.getElementById("app");if(!au)throw new Error("No app element");Ha(au).render(p.jsx(k.StrictMode,{children:p.jsx(dU,{})}));
|
|
|
46 |
`);let i=!1,o=[],c=!1,a=[];for(let U=0;U<d.length;U++){const u=d[U];if(u.startsWith("```")){i?(r.push(p.jsx("pre",{children:o.join(`
|
47 |
`)},`code-${U}`)),i=!1,o=[]):i=!0;continue}if(i){o.push(u);continue}if(u.includes("**")){const W=u.split("**");r.push(p.jsx("p",{children:W.map((N,R)=>R%2?p.jsx("strong",{children:N},R):N)},U));continue}if(u.includes("*")){const W=u.split("*");r.push(p.jsx("p",{children:W.map((N,R)=>R%2?p.jsx("em",{children:N},R):N)},U));continue}if(u.startsWith("#")){const W=u.split(" ")[0].length,N=u.slice(W+1),R=`h${W}`;r.push(p.jsx(R,{children:N},U));continue}const Z=/!\[(.*?)\]\((.*?)\)/.exec(u);if(Z){const[,W,N]=Z;r.push(p.jsx("img",{src:N,alt:W},U));continue}if(u.includes("[")&&u.includes("]")&&u.includes("(")&&u.includes(")")){const W=u.replace(/\[(.*?)\]\((.*?)\)/g,(N,R,h)=>`<a href="${h}">${R}</a>`);r.push(p.jsx("p",{dangerouslySetInnerHTML:{__html:W}},U));continue}if(u.startsWith("-")||u.startsWith("*")||u.startsWith("+")){const W=u.slice(1).trim();a.push(p.jsx("li",{children:W},`list-item-${U}`)),c=!0;continue}c&&a.length>0&&(r.push(p.jsx("ul",{children:a},`list-${U}`)),a=[],c=!1),r.push(p.jsx("p",{children:u},U))}return i&&o.length>0&&r.push(p.jsx("pre",{children:o.join(`
|
48 |
`)},`code-${d.length}`)),c&&a.length>0&&r.push(p.jsx("ul",{children:a},`list-${d.length}`)),p.jsx("div",{className:l,children:r})}return t(e)}function S0({source:e,setError:l}){const[t,n]=k.useState(0),[r,d]=k.useState(),{resolveUrl:i,requestInit:o}=e;return k.useEffect(()=>{async function c(){try{const a=await fetch(i,o),U=await a.text(),u=rc(a.headers)??U.length;if(a.status===401){l(new Error(U)),d(void 0);return}l(void 0),d({text:U,fileSize:u})}catch(a){l(a),d(void 0)}finally{n(2)}}n(a=>a!==0?a:(c().catch(()=>{}),1))},[i,o,l]),p.jsxs(Nn,{content:r,children:[p.jsx(M0,{className:"markdown",text:(r==null?void 0:r.text)??""}),t===1&&p.jsx(Wn,{className:"center"})]})}function y0(e,l){const t=new URL(location.href);if(l!=null&&l.appendOnly||(t.search=""),e!==void 0)for(const[n,r]of Object.entries(e))t.searchParams.set(n,r);return t.toString()}function k0(e){return y0(e,{appendOnly:!0})}function Q0({df:e,row:l,col:t,setProgress:n,setError:r,onClose:d}){const[i,o]=k.useState();k.useEffect(()=>{async function a(){try{n(.5);const U=e.rows(l,l+1),u=await Ir(U,1,e.header)[0][e.header[t]].then(hr);o(u)}catch(U){r(U)}finally{n(1)}}a().catch(()=>{})},[e,t,l,n,r]);const c=p.jsxs(p.Fragment,{children:[p.jsx("button",{className:"slideClose",onClick:d,children:" "}),p.jsxs("span",{children:["column `",e.header[t],"`"]}),p.jsxs("span",{children:["row ",l+1]})]});return p.jsx(Nn,{headers:c,children:p.jsx("code",{className:"text",children:i})})}const Go={MIN:100,DEFAULT:400};function G0({mainContent:e,panelContent:l,isPanelOpen:t,config:n}){var r,d;const i=(r=n==null?void 0:n.slidePanel)!=null&&r.minWidth&&n.slidePanel.minWidth>0?n.slidePanel.minWidth:Go.MIN;function o(R){if(R&&i<=R)return R}const c=o((d=n==null?void 0:n.slidePanel)==null?void 0:d.defaultWidth)??Go.DEFAULT,[a,U]=k.useState(c),[u,Z]=k.useState(-1),W=Bo.createRef();k.useEffect(()=>{function R(V){u!==-1&&U(Math.max(i,u-V.clientX))}function h(){u!==-1&&Z(-1)}return u!==-1&&(document.addEventListener("mousemove",R),document.addEventListener("mouseup",h)),()=>{document.removeEventListener("mousemove",R),document.removeEventListener("mouseup",h)}},[u,i]);const N=k.useCallback(R=>{W.current&&W.current.offsetWidth<a?(U(W.current.offsetWidth),Z(R.clientX+W.current.offsetWidth)):Z(R.clientX+a)},[W,a]);return p.jsxs("div",{className:"slideContainer",children:[p.jsx("div",{className:"slideMain",children:e}),t&&p.jsx("div",{className:"resizer",onMouseDown:N}),p.jsx("div",{className:u===-1?"slidePanel":"slidePanel slideDragging",ref:W,style:t?{width:a}:void 0,children:l})]})}function b0({source:e,setProgress:l,setError:t,config:n}){const[r,d]=k.useState(0),[i,o]=k.useState(),[c,a]=k.useState(),{resolveUrl:U,requestInit:u,sourceId:Z}=e;k.useEffect(()=>{async function m(){try{l(.33);const T=await $a({url:U,requestInit:u}),M={url:U,byteLength:T.byteLength,requestInit:u};l(.66);const S=await qa(T);let G=nu(M,S);G=gZ(G);const b=T.byteLength;o({dataframe:G,fileSize:b})}catch(T){t(T)}finally{d(2),l(1)}}r===0&&(d(1),m().catch(()=>{}))},[r,U,u,t,l]),k.useEffect(()=>{d(0)},[e]),k.useEffect(()=>{if(!c)return;function m(T){T.key==="Escape"&&a(void 0)}return window.addEventListener("keydown",m),()=>{window.removeEventListener("keydown",m)}},[c]);const W=k.useCallback(({col:m,row:T})=>{var M,S;return((S=(M=n==null?void 0:n.routes)==null?void 0:M.getCellRouteUrl)==null?void 0:S.call(M,{sourceId:Z,col:m,row:T}))||k0({col:m.toString(),row:T.toString()})},[n,Z]),N=k.useCallback((m,T)=>{(c==null?void 0:c.col)===m&&c.row===T?a(void 0):a({row:T,col:m})},[c]),R=k.useCallback((m,T,M)=>{m.button===1&&(m.preventDefault(),window.open(W({row:M,col:T}),"_blank"))},[W]),h=p.jsxs("span",{children:[(i==null?void 0:i.dataframe.numRows.toLocaleString())??"..."," rows"]}),V=p.jsxs(Nn,{content:i,headers:h,children:[(i==null?void 0:i.dataframe)&&p.jsx(CZ,{cacheKey:U,data:i.dataframe,onDoubleClickCell:N,onMouseDownCell:R,onError:t}),r===1&&p.jsx(Wn,{className:"center"})]});let s;return i!=null&&i.dataframe&&c&&(s=p.jsx(Q0,{col:c.col,df:i.dataframe,onClose:()=>{a(void 0)},row:c.row,setError:t,setProgress:l})),p.jsx(G0,{isPanelOpen:!!(i!=null&&i.dataframe&&c),mainContent:V,panelContent:s,config:n})}function E0({source:e,setError:l}){const[t,n]=k.useState(0),[r,d]=k.useState(),{resolveUrl:i,requestInit:o}=e;k.useEffect(()=>{async function a(){try{const U=await fetch(i,o),u=await U.text(),Z=rc(U.headers)??u.length;if(U.status===401){l(new Error(u)),d(void 0);return}l(void 0),d({text:u,fileSize:Z})}catch(U){l(U),d(void 0)}finally{n(2)}}n(U=>U!==0?U:(a().catch(()=>{}),1))},[i,o,l]);const c=p.jsx(p.Fragment,{children:p.jsxs("span",{children:[w0((r==null?void 0:r.text)??"")," lines"]})});return p.jsxs(Nn,{content:r,headers:c,children:[p.jsx("code",{className:"text",children:r==null?void 0:r.text}),t&&p.jsx(Wn,{className:"center"})]})}function w0(e){let l=0;for(const t of e)t===`
|
49 |
+
`&&l++;return l.toLocaleString("en-US")}function X0({source:e,setError:l,setProgress:t,config:n}){const{fileName:r}=e;return r.endsWith(".md")?p.jsx(S0,{source:e,setError:l}):r.endsWith(".parquet")?p.jsx(b0,{source:e,setError:l,setProgress:t,config:n}):W0.some(d=>r.endsWith(d))?p.jsx(T0,{source:e,setError:l}):p.jsx(E0,{source:e,setError:l,setProgress:t})}function f0({source:e,config:l}){const[t,n]=k.useState(),[r,d]=k.useState();return p.jsxs(dc,{progress:t,error:r,title:e.fileName,children:[p.jsx(lc,{source:e,config:l}),p.jsx(X0,{source:e,setProgress:n,setError:d,config:l})]})}function x0({source:e,config:l}){const[t,n]=k.useState(),[r,d]=k.useState();return k.useEffect(()=>{e.listFiles().then(n).catch(i=>{n([]),d(i instanceof Error?i:new Error(`Failed to fetch files - ${i}`))})},[e]),p.jsxs(dc,{error:r,title:e.prefix,children:[p.jsx(lc,{source:e,config:l}),t&&t.length>0&&p.jsx("ul",{className:"file-list",children:t.map((i,o)=>{var c,a;return p.jsx("li",{children:p.jsxs("a",{href:((a=(c=l==null?void 0:l.routes)==null?void 0:c.getSourceRouteUrl)==null?void 0:a.call(c,{sourceId:i.sourceId}))??location.href,children:[p.jsx("span",{className:Fr("file-name","file",i.kind==="directory"&&"folder"),children:i.name}),i.kind==="file"&&p.jsxs(p.Fragment,{children:[i.size!==void 0&&p.jsx("span",{className:"file-size",title:i.size.toLocaleString()+" bytes",children:ru(i.size)}),p.jsx("span",{className:"file-date",title:U0(i),children:Z0(i)})]})]})},o)})}),(t==null?void 0:t.length)===0&&p.jsx("div",{className:"center",children:"No files"}),t===void 0&&p.jsx(Wn,{className:"center"})]})}function Y0({source:e,navigation:l,config:t}){return e.kind==="directory"?p.jsx(x0,{source:e,config:t}):(l==null?void 0:l.row)!==void 0&&l.col!==void 0?p.jsx(p0,{source:e,row:l.row,col:l.col,config:t}):p.jsx(f0,{source:e,config:t})}function ic(e){const l=e.replace(/\?.*$/,"").split("/").at(-1);if(!l)throw new Error("Cannot extract a filename");return l}function K0(e,l){if(URL.canParse(e))return{kind:"file",sourceId:e,sourceParts:[{text:e,sourceId:e}],fileName:ic(e),resolveUrl:e,requestInit:void 0}}var J0=Object.defineProperty,z0=(e,l,t)=>l in e?J0(e,l,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[l]=t,Jn=(e,l,t)=>(z0(e,typeof l!="symbol"?l+"":l,t),t),Lr="https://huggingface.co";async function Vt(e,l){var t,n;const r=new I0(e.url,e.status,(t=e.headers.get("X-Request-Id"))!=null?t:void 0);r.message=`Api error with status ${r.statusCode}`;const d=[`URL: ${r.url}`,r.requestId?`Request ID: ${r.requestId}`:void 0].filter(Boolean).join(". ");if((n=e.headers.get("Content-Type"))!=null&&n.startsWith("application/json")){const i=await e.json();r.message=i.error||i.message||r.message,r.data=i}else r.data={message:await e.text()};throw r.message+=`. ${d}`,r}var I0=class extends Error{constructor(e,l,t,n){super(n),Jn(this,"statusCode"),Jn(this,"url"),Jn(this,"requestId"),Jn(this,"data"),this.statusCode=l,this.requestId=t,this.url=e}};function bo(e){if(!e.startsWith("hf_"))throw new TypeError("Your access token must start with 'hf_'")}function du(e){var l;if(e.accessToken)return bo(e.accessToken),e.accessToken;if((l=e.credentials)!=null&&l.accessToken)return bo(e.credentials.accessToken),e.credentials.accessToken}function L0(e){if(typeof e!="string")return e;if(e.startsWith("model/")||e.startsWith("models/"))throw new TypeError("A repo designation for a model should not start with 'models/', directly specify the model namespace / name");if(e.startsWith("space/"))throw new TypeError("Spaces should start with 'spaces/', plural, not 'space/'");if(e.startsWith("dataset/"))throw new TypeError("Datasets should start with 'dataset/', plural, not 'dataset/'");const l=e.split("/").length-1;if(e.startsWith("spaces/")){if(l!==2)throw new TypeError("Space Id must include namespace and name of the space");return{type:"space",name:e.slice(7)}}if(e.startsWith("datasets/")){if(l>2)throw new TypeError("Too many slashes in repo designation: "+e);return{type:"dataset",name:e.slice(9)}}if(l>1)throw new TypeError("Too many slashes in repo designation: "+e);return{type:"model",name:e}}new Promise(e=>{});function D0(e){if(globalThis.Buffer)return globalThis.Buffer.from(e).toString("base64");{const l=[];return e.forEach(t=>{l.push(String.fromCharCode(t))}),globalThis.btoa(l.join(""))}}function g0(e,l){return Object.assign({},...l.map(t=>{if(e[t]!==void 0)return{[t]:e[t]}}))}function iu(e){const l=/<(https?:[/][/][^>]+)>;\s+rel="([^"]+)"/g;return Object.fromEntries([...e.matchAll(l)].map(([,t,n])=>[n,t]))}var B0=["private","downloads","gated","likes","lastModified"];async function*v0(e){var l,t,n,r,d,i,o,c,a;const U=e&&du(e);let u=(l=e==null?void 0:e.limit)!=null?l:1/0;const Z=new URLSearchParams([...Object.entries({limit:String(Math.min(u,500)),...(t=e==null?void 0:e.search)!=null&&t.owner?{author:e.search.owner}:void 0,...(n=e==null?void 0:e.search)!=null&&n.query?{search:e.search.query}:void 0}),...(i=(d=(r=e==null?void 0:e.search)==null?void 0:r.tags)==null?void 0:d.map(N=>["filter",N]))!=null?i:[],...B0.map(N=>["expand",N]),...(c=(o=e==null?void 0:e.additionalFields)==null?void 0:o.map(N=>["expand",N]))!=null?c:[]]).toString();let W=`${(e==null?void 0:e.hubUrl)||Lr}/api/datasets`+(Z?"?"+Z:"");for(;W;){const N=await((a=e==null?void 0:e.fetch)!=null?a:fetch)(W,{headers:{accept:"application/json",...e!=null&&e.credentials?{Authorization:`Bearer ${U}`}:void 0}});if(!N.ok)throw await Vt(N);const R=await N.json();for(const V of R)if(yield{...(e==null?void 0:e.additionalFields)&&g0(V,e.additionalFields),id:V._id,name:V.id,private:V.private,downloads:V.downloads,likes:V.likes,gated:V.gated,updatedAt:new Date(V.lastModified)},u--,u<=0)return;const h=N.headers.get("Link");W=h?iu(h).next:void 0}}async function*C0(e){var l;const t=du(e),n=L0(e.repo);let r=`${e.hubUrl||Lr}/api/${n.type}s/${n.name}/tree/${e.revision||"main"}${e.path?"/"+e.path:""}?recursive=${!!e.recursive}&expand=${!!e.expand}`;for(;r;){const d=await((l=e.fetch)!=null?l:fetch)(r,{headers:{accept:"application/json",...t?{Authorization:`Bearer ${t}`}:void 0}});if(!d.ok)throw await Vt(d);const i=await d.json();for(const c of i)yield c;const o=d.headers.get("Link");r=o?iu(o).next:void 0}}async function Eo(e){var l,t;if(typeof window>"u")throw new Error("oauthHandleRedirect is only available in the browser");const n=new URLSearchParams(window.location.search),[r,d]=[n.get("error"),n.get("error_description")];if(r)throw new Error(`${r}: ${d}`);const i=n.get("code"),o=localStorage.getItem("huggingface.co:oauth:nonce");if(!i)throw new Error("Missing oauth code from query parameters in redirected URL");if(!o)throw new Error("Missing oauth nonce from localStorage");const c=localStorage.getItem("huggingface.co:oauth:code_verifier");if(!c)throw new Error("Missing oauth code_verifier from localStorage");const a=n.get("state");if(!a)throw new Error("Missing oauth state from query parameters in redirected URL");let U;try{U=JSON.parse(a)}catch{throw new Error("Invalid oauth state in redirected URL, unable to parse JSON: "+a)}if(U.nonce!==o)throw new Error("Invalid oauth state in redirected URL");const u=Lr,Z=`${new URL(u).origin}/.well-known/openid-configuration`,W=await fetch(Z,{headers:{Accept:"application/json"}});if(!W.ok)throw await Vt(W);const N=await W.json(),R=await fetch(N.token_endpoint,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"authorization_code",code:i,redirect_uri:U.redirectUri,code_verifier:c}).toString()});if(localStorage.removeItem("huggingface.co:oauth:code_verifier"),localStorage.removeItem("huggingface.co:oauth:nonce"),!R.ok)throw await Vt(R);const h=await R.json(),V=new Date(Date.now()+h.expires_in*1e3),s=await fetch(N.userinfo_endpoint,{headers:{Authorization:`Bearer ${h.access_token}`}});if(!s.ok)throw await Vt(s);const m=await s.json();return{accessToken:h.access_token,accessTokenExpiresAt:V,userInfo:{id:m.sub,name:m.name,fullname:m.preferred_username,email:m.email,emailVerified:m.email_verified,avatarUrl:m.picture,websiteUrl:m.website,isPro:m.isPro,orgs:(t=(l=m.orgs)==null?void 0:l.map(T=>({id:T.sub,name:T.name,fullname:T.name,isEnterprise:T.isEnterprise,canPay:T.canPay,avatarUrl:T.picture,roleInOrg:T.roleInOrg})))!=null?t:[]},state:U.state,scope:h.scope}}async function j0(e){if(typeof window>"u")throw new Error("oauthHandleRedirect is only available in the browser");const l=new URLSearchParams(window.location.search);return l.has("error")?Eo():l.has("code")?localStorage.getItem("huggingface.co:oauth:nonce")?Eo():(console.warn("Missing oauth nonce from localStorage. This can happen when the user refreshes the page after logging in, without changing the URL."),!1):!1}async function H0(e){var l,t;if(typeof window>"u")throw new Error("oauthLogin is only available in the browser");const n=(e==null?void 0:e.hubUrl)||Lr,r=`${new URL(n).origin}/.well-known/openid-configuration`,d=await fetch(r,{headers:{Accept:"application/json"}});if(!d.ok)throw await Vt(d);const i=await d.json(),o=globalThis.crypto.randomUUID(),c=globalThis.crypto.randomUUID()+globalThis.crypto.randomUUID();localStorage.setItem("huggingface.co:oauth:nonce",o),localStorage.setItem("huggingface.co:oauth:code_verifier",c);const a=(e==null?void 0:e.redirectUrl)||window.location.href,U=JSON.stringify({nonce:o,redirectUri:a,state:e==null?void 0:e.state}),u=(t=(l=window==null?void 0:window.huggingface)==null?void 0:l.variables)!=null?t:null,Z=(e==null?void 0:e.clientId)||(u==null?void 0:u.OAUTH_CLIENT_ID);if(!Z)throw u?new Error("Missing clientId, please add hf_oauth: true to the README.md's metadata in your static Space"):new Error("Missing clientId");const W=D0(new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256",new TextEncoder().encode(c)))).replace(/[+]/g,"-").replace(/[/]/g,"_").replace(/=/g,"");return`${i.authorization_endpoint}?${new URLSearchParams({client_id:Z,scope:(e==null?void 0:e.scopes)||(u==null?void 0:u.OAUTH_SCOPES)||"openid profile",response_type:"code",redirect_uri:a,state:U,code_challenge:W,code_challenge_method:"S256"}).toString()}`}function cu(e){if(e.state)try{const l=JSON.parse(e.state);if(typeof l!="object"||l===null||!("urlBeforeLogin"in l))throw new Error("Invalid state");const{urlBeforeLogin:t}=l;if(typeof t!="string")throw new Error("Invalid redirect URL: not a string");const n=new URL(t);if(n.origin!==window.location.origin)throw new Error("Invalid redirect URL: different origin");localStorage.setItem("oauth",JSON.stringify({...e,state:null})),window.location.href=n.href}catch(l){console.error(l)}}function ou(e){const l=e.accessTokenExpiresAt>=new Date;return l||localStorage.removeItem("oauth"),l}function O0(){const e=localStorage.getItem("oauth");if(!e)return;const l=JSON.parse(e),t={...l,accessTokenExpiresAt:new Date(l.accessTokenExpiresAt)};if(ou(t))return cu(t),t}async function P0(){const e=await j0();if(!(!e||!ou(e)))return localStorage.setItem("oauth",JSON.stringify(e)),cu(e),e}async function A0(){const e=JSON.stringify({urlBeforeLogin:window.location.href}),l="huggingface"in window?{state:e}:{state:e,redirectUrl:new URL(window.location.href).origin+"/",clientId:"9c9ac5a3-b324-4df8-a70c-7a8055ff8421",scopes:"openid profile read-repos"},t=await H0(l)+"&prompt=consent";window.location.href=t}function _0(){localStorage.removeItem("oauth"),window.location.reload()}const Kt="https://huggingface.co/datasets";function su(e){const l=new URL(window.location.href);l.search=e,window.parent.postMessage({queryString:e},"https://huggingface.co"),window.location.assign(l)}function wo(e){const l=[{sourceId:`${Kt}/${e.repo}/tree/${e.branch}/`,text:`${Kt}/${e.repo}/${e.action}/${e.branch}/`}],t=e.path.split("/").filter(r=>r.length>0),n=t.at(-1);if(n){for(let r=0;r<t.length-1;r++)l.push({sourceId:`${Kt}/${e.repo}/tree/${e.branch}/${t.slice(0,r+1).join("/")}`,text:t[r]+"/"});l.push({sourceId:`${Kt}/${e.repo}/${e.action}/${e.branch}${e.path}`,text:n})}return l}function q0(e){return`${e.origin}/datasets/${e.repo}/tree/${e.branch}${e.path}`.replace(/\/$/,"")}async function $0(e,l){var r,d;const t=C0({repo:`datasets/${e.repo}`,revision:e.branch,path:"path"in e?e.path.replace(/^\//,""):"",expand:!0,accessToken:l==null?void 0:l.accessToken}),n=[];for await(const i of t)n.push({name:ic(i.path),eTag:(r=i.lastCommit)==null?void 0:r.id,size:i.size,lastModified:(d=i.lastCommit)==null?void 0:d.date,sourceId:`${e.origin}/datasets/${e.repo}/${i.type==="file"?"blob":"tree"}/${e.branch}/${i.path}`.replace(/\/$/,""),kind:i.type==="file"?"file":"directory"});return n}function eU(e,l){try{const t=lU(e);return t.kind==="file"?{kind:"file",sourceId:e,sourceParts:wo(t),fileName:ic(t.path),resolveUrl:t.resolveUrl,requestInit:l==null?void 0:l.requestInit}:{kind:"directory",sourceId:e,sourceParts:wo(t),prefix:q0(t),listFiles:()=>$0(t,l)}}catch(t){console.error(t);return}}function lU(e){var d,i,o;const l=new URL(e);if(l.protocol!=="https:"&&l.protocol!=="http:")throw new Error("url must be a HTTP URL");if(!["huggingface.co","huggingface.co","hf.co"].includes(l.host)||l.protocol!=="https:")throw new Error("Not a Hugging Face URL");const t=(d=/^\/datasets\/(?<namespace>[^/]+)\/(?<dataset>[^/]+)\/?$/.exec(l.pathname))==null?void 0:d.groups;if(t&&["namespace","dataset"].every(c=>c in t))return{kind:"directory",source:e,origin:l.origin,repo:t.namespace+"/"+t.dataset,action:"tree",branch:"main",path:""};const n=(i=/^\/datasets\/(?<namespace>[^/]+)\/(?<dataset>[^/]+)\/(?<action>tree)\/(?<branch>(refs\/(convert|pr)\/)?[^/]+)(?<path>(\/[^/]+)*)\/?$/.exec(l.pathname))==null?void 0:i.groups;if(n&&["namespace","dataset","action","branch","path"].every(c=>c in n)&&n.branch!=="refs"){const c=n.branch.replace(/\//g,"%2F");return{kind:"directory",source:`${l.origin}/datasets/${n.namespace}/${n.dataset}/${n.action}/${c}${n.path}`,origin:l.origin,repo:n.namespace+"/"+n.dataset,action:"tree",branch:c,path:n.path}}const r=(o=/^\/datasets\/(?<namespace>[^/]+)\/(?<dataset>[^/]+)\/(?<action>blob|resolve)\/(?<branch>(refs\/(convert|pr)\/)?[^/]+)(?<path>(\/[^/]+)+)$/.exec(l.pathname))==null?void 0:o.groups;if(r&&["namespace","dataset","action","branch","path"].every(c=>c in r)&&r.branch!=="refs"){const c=r.branch.replace(/\//g,"%2F");return{kind:"file",source:`${l.origin}/datasets/${r.namespace}/${r.dataset}/${r.action}/${c}${r.path}`,origin:l.origin,repo:r.namespace+"/"+r.dataset,action:r.action==="blob"?"blob":"resolve",branch:c,path:r.path,resolveUrl:`${l.origin}/datasets/${r.namespace}/${r.dataset}/resolve/${c}${r.path}`}}throw new Error("Unsupported Hugging Face URL")}const tU=""+new URL("sign-in-with-huggingface-lg-qDcc3w-B.svg",import.meta.url).href;function Jt({url:e,children:l,className:t}){const n=e?`?url=${e}`:"";return p.jsx("a",{className:t,href:`/${n}`,onClick:r=>{r.preventDefault(),su(n)},children:l})}function nU({accessToken:e}){const[l,t]=k.useState(),[n,r]=k.useState([]);k.useEffect(()=>{async function i(){const o=[];for await(const c of v0({search:{query:l},limit:10,credentials:e?{accessToken:e}:void 0}))o.push(c);r(o)}i().catch(o=>{r([]),console.error(o)})},[l,e]);function d(i){t(i.target.value)}return p.jsxs(p.Fragment,{children:[p.jsx("input",{type:"search",onChange:d}),p.jsx("ul",{className:"ref-list",children:n.map(i=>p.jsx("li",{style:{fontSize:"0.9rem"},children:p.jsx(Jt,{url:`${Kt}/${i.name}`,children:i.name})},i.name))})]})}function rU({auth:e}){const l=k.useRef(null);function t(n){n.preventDefault();const r=new FormData(n.currentTarget).get("url");su(`?url=${r}`)}return p.jsxs("div",{id:"welcome",children:[p.jsx("h1",{children:"hyparquet"}),p.jsxs("sub",{children:["/haɪ pɑːrˈkeɪ/",p.jsx("img",{src:"audio.svg",alt:"play hyparquet pronunciation",height:"18",width:"18",onClick:()=>{var n;(n=l.current)==null||n.play().catch(()=>{})}})]}),p.jsx("audio",{ref:l,src:"hyparquet.mp3"}),p.jsx("h2",{children:"in-browser parquet file reader"}),p.jsxs("p",{children:[p.jsx("a",{href:"https://www.npmjs.com/package/hyparquet",children:p.jsx("img",{src:"https://img.shields.io/npm/v/hyparquet",alt:"npm hyparquet"})})," ",p.jsx("a",{href:"https://github.com/hyparam/hyparquet",children:p.jsx("img",{src:"https://img.shields.io/github/stars/hyparam/hyparquet?style=social",alt:"star hyparquet"})})]}),p.jsxs("p",{children:["Online demo of"," ",p.jsx("a",{href:"https://github.com/hyparam/hyparquet",children:"hyparquet"}),": a parser for apache parquet files. Uses"," ",p.jsx("a",{href:"https://github.com/hyparam/hightable",children:"hightable"})," for high performance windowed table viewing."]}),p.jsxs("section",{children:[p.jsx("h3",{children:"Select a dataset on Hugging Face"}),e?p.jsxs("p",{children:["Logged in as",p.jsx("img",{src:e.userInfo.avatarUrl,alt:e.userInfo.name,style:{width:"1rem",height:"1rem",borderRadius:"50%",margin:"0 0.5rem"}}),e.userInfo.name," (",p.jsx("a",{onClick:()=>{_0()},children:"Log out"}),"). You can search your private and gated datasets."]}):p.jsxs(p.Fragment,{children:[p.jsx("p",{children:"Log in to search your private and gated datasets"}),p.jsx("p",{children:p.jsx("a",{onClick:()=>{A0().catch(()=>{})},children:p.jsx("img",{src:tU,alt:"Sign in with Hugging Face"})})})]}),p.jsx("p",{children:"Search for dataset:"}),p.jsx(nU,{accessToken:e==null?void 0:e.accessToken})]}),p.jsxs("section",{children:[p.jsx("h3",{children:"Parquet URL"}),p.jsx("p",{children:"You can also set a url to see your parquet data. 👀"}),p.jsxs("form",{onSubmit:t,style:{display:"flex",gap:"1rem"},children:[p.jsx("label",{htmlFor:"url",children:"URL"}),p.jsx("input",{name:"url",defaultValue:"https://huggingface.co/datasets/codeparrot/github-code/resolve/main/data/train-00000-of-01126.parquet",style:{width:"100%"},type:"url"}),p.jsx("button",{style:{fontSize:"1rem",padding:"0 0.5rem"},type:"submit",children:"Open"})]}),p.jsxs("p",{children:[p.jsx("p",{children:"Example files:"}),p.jsxs("ul",{className:"quick-links",children:[p.jsx("li",{children:p.jsx(Jt,{className:"aws",url:"https://hyperparam-public.s3.amazonaws.com/wiki-en-00000-of-00041.parquet",children:"s3://wiki-en-00000-of-00041.parquet"})}),p.jsx("li",{children:p.jsx(Jt,{className:"azure",url:"https://hyperparam.blob.core.windows.net/hyperparam/starcoderdata-js-00000-of-00065.parquet",children:"azure://starcoderdata-js-00000-of-00065.parquet"})}),p.jsx("li",{children:p.jsx(Jt,{className:"huggingface",url:"https://huggingface.co/datasets/codeparrot/github-code/resolve/main/data/train-00000-of-01126.parquet",children:"huggingface://github-code-00000-of-01126.parquet"})}),p.jsx("li",{children:p.jsx(Jt,{className:"github",url:"https://raw.githubusercontent.com/hyparam/hyparquet/master/test/files/rowgroups.parquet",children:"github://rowgroups.parquet"})})]})]})]})]})}function Xo(e){if(e)return{headers:{Authorization:`Bearer ${e}`}}}function dU(){const e=O0(),[l,t]=k.useState(e),[n,r]=k.useState(e==null?void 0:e.accessToken),[d,i]=k.useState(Xo(e==null?void 0:e.accessToken));k.useEffect(()=>{l||P0().then(Z=>{t(Z),Z&&(r(Z.accessToken),i(Xo(Z.accessToken)))}).catch(Z=>{console.error("Error fetching OAuth"),console.error(Z)})},[l]);const o=new URLSearchParams(location.search),c=o.get("url"),a=o.get("row")===null?void 0:Number(o.get("row")),U=o.get("col")===null?void 0:Number(o.get("col"));if(c===null)return p.jsx(rU,{auth:l});const u=eU(c,{requestInit:d,accessToken:n})??K0(c);if(!u){const Z="/?url=https://huggingface.co/datasets/severo/test-parquet/resolve/main/parquet/csv-train-00000-of-00001.parquet";return p.jsxs("div",{children:["Could not load a data source. You have to pass a valid source in the url, eg: ",p.jsx("a",{href:Z,children:Z}),"."]})}return p.jsx(Y0,{source:u,navigation:{row:a,col:U},config:{routes:{getSourceRouteUrl:({sourceId:Z})=>`/?url=${Z}`,getCellRouteUrl:({sourceId:Z,col:W,row:N})=>`/?url=${Z}&col=${W}&row=${N}`}}})}const au=document.getElementById("app");if(!au)throw new Error("No app element");Ha(au).render(p.jsx(k.StrictMode,{children:p.jsx(dU,{})}));
|
index.html
CHANGED
@@ -9,7 +9,7 @@
|
|
9 |
<link rel="icon" type="image/svg+xml" href="./logo.svg" />
|
10 |
<meta name="theme-color" content="#6b00ff">
|
11 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
12 |
-
<script type="module" crossorigin src="./assets/index-
|
13 |
<link rel="stylesheet" crossorigin href="./assets/index-CbrjafeG.css">
|
14 |
</head>
|
15 |
<body>
|
|
|
9 |
<link rel="icon" type="image/svg+xml" href="./logo.svg" />
|
10 |
<meta name="theme-color" content="#6b00ff">
|
11 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
12 |
+
<script type="module" crossorigin src="./assets/index-DOAQxHjz.js"></script>
|
13 |
<link rel="stylesheet" crossorigin href="./assets/index-CbrjafeG.css">
|
14 |
</head>
|
15 |
<body>
|