enzostvs HF staff commited on
Commit
fe56e1a
·
1 Parent(s): 2081a7c

fetch model card data if no instance prompt

Browse files
Files changed (1) hide show
  1. src/routes/api/models/+server.ts +11 -3
src/routes/api/models/+server.ts CHANGED
@@ -81,8 +81,13 @@ 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
- const hugging_face_request2 = await fetch(`https://huggingface.co/api/models/${model.id}`)
85
- const hugging_face_model2 = await hugging_face_request2.json()?.catch(() => {})
 
 
 
 
 
86
 
87
  if (!hugging_face_model?.[0]) {
88
  continue;
@@ -96,7 +101,10 @@ export async function PATCH({ request } : RequestEvent) {
96
  downloads: hugging_face_model?.[0]?.downloads,
97
  likes7d: hugging_face_model?.[0]?.trendingScore,
98
  id: hugging_face_model?.[0]?.id,
99
- instance_prompt: hugging_face_model2?.cardData?.instance_prompt,
 
 
 
100
  }
101
  })
102
  .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
+ let hugging_face_model2 = undefined;
85
+
86
+ if (!model.instance_prompt) {
87
+ const hugging_face_request2 = await fetch(`https://huggingface.co/api/models/${model.id}`)
88
+ hugging_face_model2 = await hugging_face_request2.json()?.catch(() => {})
89
+
90
+ }
91
 
92
  if (!hugging_face_model?.[0]) {
93
  continue;
 
101
  downloads: hugging_face_model?.[0]?.downloads,
102
  likes7d: hugging_face_model?.[0]?.trendingScore,
103
  id: hugging_face_model?.[0]?.id,
104
+ ...(hugging_face_model2?.cardData?.instance_prompt ? {
105
+ instance_prompt: hugging_face_model2?.cardData?.instance_prompt,
106
+ } : {}
107
+ )
108
  }
109
  })
110
  .then(() => {