CoolFace
Apppublic

FebryanS/Danbooru

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py45 linesDownload Raw Back to root
1import requests2import gradio as gr3import os4 5def db(tags, limit):6    7    filter = os.getenv("filter")8    if filter in tags:9        tags = tags.replace(filter, "")10    else:11        tags = f"{tags} rating:g"12        13    url = "https://danbooru.donmai.us/posts/random.json"14    params = {15        'tags': tags16    }17    posts = []18    for i in range(int(limit)):19        post = requests.get(url, params=params).json()20        try:21            file = post['large_file_url']22        except KeyError:23            continue24        25        tag_string = post['tag_string_general'].replace(" ", ", ").replace("_", " ").title()26        tag_update = {27            "tag_update": tag_string28        }29        source = post['source']30        if "pximg" in source:31            pixiv_id = source.split("/")[-1].split("_")[0]32            pixiv_url = f"https://pixiv.net/artworks/{pixiv_id}"33            tag_update.update({'source': pixiv_url})34        35        post.update(tag_update)36        posts.append(post)37 38    return posts39 40iface = gr.Interface(41    fn=db,42    inputs = ["text", "number"],43    outputs = "list"44)45iface.launch()