Spaces:
Runtime error
Runtime error
add tag filter
Browse files
app.py
CHANGED
@@ -289,7 +289,7 @@ class Style(str, Enum):
|
|
289 |
|
290 |
|
291 |
@ app.get("/api/models")
|
292 |
-
def get_page(page: int = 1, sort: Sort = Sort.trending, style: Style = Style.all):
|
293 |
page = page if page > 0 else 1
|
294 |
if sort == Sort.trending:
|
295 |
sort_query = "likes / MYPOWER((JULIANDAY('now') - JULIANDAY(datetime(json_extract(data, '$.lastModified')))) + 2, 2) DESC"
|
@@ -312,16 +312,24 @@ def get_page(page: int = 1, sort: Sort = Sort.trending, style: Style = Style.all
|
|
312 |
with database.get_db() as db:
|
313 |
cursor = db.cursor()
|
314 |
cursor.execute(f"""
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
325 |
results = cursor.fetchall()
|
326 |
total = results[0]['total'] if results else 0
|
327 |
total_pages = (total + MAX_PAGE_SIZE - 1) // MAX_PAGE_SIZE
|
|
|
289 |
|
290 |
|
291 |
@ app.get("/api/models")
|
292 |
+
def get_page(page: int = 1, sort: Sort = Sort.trending, style: Style = Style.all, tag: str = None):
|
293 |
page = page if page > 0 else 1
|
294 |
if sort == Sort.trending:
|
295 |
sort_query = "likes / MYPOWER((JULIANDAY('now') - JULIANDAY(datetime(json_extract(data, '$.lastModified')))) + 2, 2) DESC"
|
|
|
312 |
with database.get_db() as db:
|
313 |
cursor = db.cursor()
|
314 |
cursor.execute(f"""
|
315 |
+
SELECT *,
|
316 |
+
COUNT(*) OVER() AS total,
|
317 |
+
isNFSW
|
318 |
+
FROM (
|
319 |
+
SELECT *,
|
320 |
+
json_extract(data, '$.class.explicit') > 0.3 OR json_extract(data, '$.class.suggestive') > 0.3 AS isNFSW
|
321 |
+
FROM models
|
322 |
+
) AS subquery
|
323 |
+
WHERE (? IS NULL AND likes > 3 OR ? IS NOT NULL)
|
324 |
+
AND {style_query}
|
325 |
+
AND (? IS NULL OR EXISTS (
|
326 |
+
SELECT 1
|
327 |
+
FROM json_each(json_extract(data, '$.meta.tags'))
|
328 |
+
WHERE json_each.value = ?
|
329 |
+
))
|
330 |
+
ORDER BY {sort_query}
|
331 |
+
LIMIT {MAX_PAGE_SIZE} OFFSET {(page - 1) * MAX_PAGE_SIZE};
|
332 |
+
""", (tag, tag, tag, tag))
|
333 |
results = cursor.fetchall()
|
334 |
total = results[0]['total'] if results else 0
|
335 |
total_pages = (total + MAX_PAGE_SIZE - 1) // MAX_PAGE_SIZE
|