enzostvs HF staff commited on
Commit
79d0fc0
·
1 Parent(s): 58dc3d3

update trending score

Browse files
src/routes/api/models/+server.ts CHANGED
@@ -81,7 +81,7 @@ export async function PATCH({ request } : RequestEvent) {
81
  const hugging_face_request = await fetch(`https://huggingface.co/api/models?id=${model.id}&sort=likes7d`)
82
  const hugging_face_model = await hugging_face_request.json()?.catch(() => {})
83
 
84
- if (!hugging_face_model) {
85
  continue;
86
  }
87
  await prisma.model.update({
@@ -89,10 +89,10 @@ export async function PATCH({ request } : RequestEvent) {
89
  id: model.id
90
  },
91
  data: {
92
- likes: hugging_face_model.likes,
93
- downloads: hugging_face_model.downloads,
94
- likes7d: hugging_face_model.trendingScore,
95
- id: hugging_face_model.id,
96
  }
97
  })
98
  .then(() => {
 
81
  const hugging_face_request = await fetch(`https://huggingface.co/api/models?id=${model.id}&sort=likes7d`)
82
  const hugging_face_model = await hugging_face_request.json()?.catch(() => {})
83
 
84
+ if (!hugging_face_model?.[0]) {
85
  continue;
86
  }
87
  await prisma.model.update({
 
89
  id: model.id
90
  },
91
  data: {
92
+ likes: hugging_face_model?.[0]?.likes,
93
+ downloads: hugging_face_model?.[0]?.downloads,
94
+ likes7d: hugging_face_model?.[0]?.trendingScore,
95
+ id: hugging_face_model?.[0]?.id,
96
  }
97
  })
98
  .then(() => {
src/routes/api/models/[id]/+server.ts CHANGED
@@ -124,7 +124,7 @@ export async function POST({ params, cookies, fetch } : RequestEvent) {
124
  }, { status: 404 })
125
  }
126
 
127
- const data = await fetch(`https://huggingface.co/api/models?id=${model.id}&sort=likes7d`)
128
  const hf_model = await data.json()
129
 
130
  await prisma.model.update({
@@ -133,10 +133,6 @@ export async function POST({ params, cookies, fetch } : RequestEvent) {
133
  },
134
  data: {
135
  isPublic: true,
136
- likes: hf_model?.likes,
137
- downloads: hf_model?.downloads,
138
- likes7d: hf_model?.trendingScore,
139
- id: hf_model?.id,
140
  instance_prompt: hf_model?.cardData?.instance_prompt
141
  }
142
  })
 
124
  }, { status: 404 })
125
  }
126
 
127
+ const data = await fetch(`https://huggingface.co/api/models/${model.id}`)
128
  const hf_model = await data.json()
129
 
130
  await prisma.model.update({
 
133
  },
134
  data: {
135
  isPublic: true,
 
 
 
 
136
  instance_prompt: hf_model?.cardData?.instance_prompt
137
  }
138
  })
src/routes/api/models/submit/+server.ts CHANGED
@@ -30,7 +30,7 @@ export async function POST({ request, fetch, cookies }) {
30
  const res = await fetch(`https://huggingface.co/api/models?id=${model.id}&sort=likes7d`)
31
  const data = await res.json();
32
 
33
- if (data?.error) {
34
  return json({
35
  error: {
36
  id: "Model not found on Hugging Face"
@@ -56,9 +56,9 @@ export async function POST({ request, fetch, cookies }) {
56
  data: {
57
  id: model.id,
58
  image: model.image,
59
- likes: data.likes,
60
- downloads: data.downloads,
61
- likes7d: data.trendingScore,
62
  isPublic: false,
63
  }
64
  })
 
30
  const res = await fetch(`https://huggingface.co/api/models?id=${model.id}&sort=likes7d`)
31
  const data = await res.json();
32
 
33
+ if (data?.error || !data?.[0]) {
34
  return json({
35
  error: {
36
  id: "Model not found on Hugging Face"
 
56
  data: {
57
  id: model.id,
58
  image: model.image,
59
+ likes: data?.[0]?.likes,
60
+ downloads: data?.[0]?.downloads,
61
+ likes7d: data?.[0]?.trendingScore,
62
  isPublic: false,
63
  }
64
  })
src/routes/api/scrap-models/[slug]/+server.ts CHANGED
@@ -91,6 +91,10 @@ export async function PATCH({ request, params } : RequestEvent) {
91
  for (const model of models) {
92
  const hf_model = await fetch(`https://huggingface.co/api/models?id=${model.id}&sort=likes7d`)
93
  const new_model = await hf_model.json();
 
 
 
 
94
  const update_data = {
95
  instance_prompt: model.instance_prompt,
96
  image: model.image,
@@ -114,10 +118,10 @@ export async function PATCH({ request, params } : RequestEvent) {
114
  },
115
  data: {
116
  ...update_data,
117
- likes: new_model.likes,
118
- downloads: new_model.downloads,
119
- likes7d: new_model.trendingScore,
120
- id: new_model.id,
121
  }
122
  })
123
  }
 
91
  for (const model of models) {
92
  const hf_model = await fetch(`https://huggingface.co/api/models?id=${model.id}&sort=likes7d`)
93
  const new_model = await hf_model.json();
94
+
95
+ if (!new_model?.[0]) {
96
+ continue;
97
+ }
98
  const update_data = {
99
  instance_prompt: model.instance_prompt,
100
  image: model.image,
 
118
  },
119
  data: {
120
  ...update_data,
121
+ likes: new_model?.[0]?.likes,
122
+ downloads: new_model?.[0]?.downloads,
123
+ likes7d: new_model?.[0]?.trendingScore,
124
+ id: new_model?.[0]?.id,
125
  }
126
  })
127
  }