abidlabs HF staff commited on
Commit
b4f3692
1 Parent(s): 067c5aa

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +28 -11
index.html CHANGED
@@ -109,25 +109,42 @@
109
  this.totalPages = data.totalPages;
110
  },
111
  async getThemes(page, sort, useTestData) {
112
- const filename = useTestData ? "test_data.json" : "subdomains.json"
113
- const res = await fetch(
114
- `https://huggingface.co/datasets/freddyaboulton/gradio-theme-subdomains/resolve/main/${filename}`
115
- );
116
- const data = await res.json();
117
- if(sort === 'likes') {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  data.sort((a, b) => (b.likes - a.likes));
119
- }else {
120
  data.sort((a, b) => (new Date(b.lastModified) - new Date(a.lastModified)));
121
  }
 
122
  const pageThemes = data.slice((page - 1) * 15, page * 15);
123
-
124
  console.log(pageThemes);
125
-
126
  return {
127
  themes: pageThemes,
128
- totalPages: Math.floor(data.length + 15 - 1, 15)
129
  };
130
- },
131
  async nextPage() {
132
  if (this.page < this.totalPages) {
133
  this.page += 1;
 
109
  this.totalPages = data.totalPages;
110
  },
111
  async getThemes(page, sort, useTestData) {
112
+ let data;
113
+ if (useTestData) {
114
+ const res = await fetch(
115
+ `https://huggingface.co/datasets/freddyaboulton/gradio-theme-subdomains/resolve/main/test_data.json`
116
+ );
117
+ data = await res.json();
118
+ } else {
119
+ const res = await fetch(
120
+ 'https://huggingface.co/api/spaces?limit=100&filter=gradio-theme&expand[]=subdomain&expand[]=lastModified&expand[]=likes&expand[]=runtime'
121
+ );
122
+ data = await res.json();
123
+ console.log(data)
124
+ // Transform the API response to match the expected format
125
+ data = data.filter(item => item.runtime?.stage === "RUNNING").map(item => ({
126
+ id: item.id,
127
+ subdomain: `https://${item.subdomain}.hf.space`,
128
+ likes: item.likes,
129
+ lastModified: item.lastModified
130
+ }));
131
+ }
132
+
133
+ if (sort === 'likes') {
134
  data.sort((a, b) => (b.likes - a.likes));
135
+ } else {
136
  data.sort((a, b) => (new Date(b.lastModified) - new Date(a.lastModified)));
137
  }
138
+
139
  const pageThemes = data.slice((page - 1) * 15, page * 15);
140
+
141
  console.log(pageThemes);
142
+
143
  return {
144
  themes: pageThemes,
145
+ totalPages: Math.ceil(data.length / 15)
146
  };
147
+ },
148
  async nextPage() {
149
  if (this.page < this.totalPages) {
150
  this.page += 1;