DeFactOfficial commited on
Commit
e5a1d97
1 Parent(s): 756962f

Upload 2 files

Browse files
Files changed (2) hide show
  1. diffusers-unfiltered.json +0 -0
  2. query_models_api.js +54 -0
diffusers-unfiltered.json ADDED
The diff for this file is too large to render. See raw diff
 
query_models_api.js ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
+ const fs = require('fs');
3
+ // Read and Parse JSON Data
4
+ const data = JSON.parse(fs.readFileSync('diffusers-unfiltered.json', 'utf8'));
5
+ const makeReadable=(data)=>{
6
+ return data.map(item=>{
7
+ return {
8
+ id: item.id,
9
+ class: item.class,
10
+ tags: item.meta.tags|| [],
11
+ activation_phrase: item.meta.instance_prompt || "not required",
12
+ example_prompts:item.meta.widget || "none provided"
13
+ }
14
+ })
15
+ }
16
+ // Sorting Function
17
+ function sortData(data, sortBy) {
18
+ return data.sort((a, b) => b[sortBy] - a[sortBy]);
19
+ }
20
+
21
+ // Filtering Functions
22
+ function filterData(data, filterBy, threshold=0.5) {
23
+ return data.filter(item => item["class"][filterBy] >= threshold);
24
+ }
25
+
26
+ function filterOptimizedOnly(data) {
27
+ data= data.filter(item => item.meta.inference)
28
+ sortData(data, "downloads");
29
+ return data
30
+ }
31
+
32
+ async function queryCommunityModels(req, res) {
33
+ let result = data;
34
+
35
+ if (req.query.sortBy) {
36
+ result = sortData(result, req.query.sortBy);
37
+ }
38
+
39
+ if (req.query.filterBy && req.query.threshold) {
40
+ result = filterData(result, req.query.filterBy, req.query.threshold ?
41
+ parseFloat(req.query.threshold)
42
+ :
43
+ 0.5
44
+ );
45
+ }
46
+
47
+ if (req.query.optimized_only === 'true') {
48
+ result = filterOptimizedOnly(result);
49
+ }
50
+ console.log(result.length, " items returned");
51
+ res.json(makeReadable(result));
52
+ }
53
+
54
+ module.exports={queryCommunityModels}