Civitai / app.py
SenY's picture
サムネイルの表示に対応
a95df60
raw
history blame
1.42 kB
import gradio as gr
import json
from pathlib import Path
import re
fileid2json = json.loads(Path("fileid2json.json").read_text())
fileid2image = json.loads(Path("fileid2image.json").read_text())
autov22fileid = json.loads(Path("autov22fileid.json").read_text())
filename2fileid = json.loads(Path("filename2fileid.json").read_text())
name2fileid = json.loads(Path("name2fileid.json").read_text())
def greet(query):
result = "Not found"
fileid = query
hit = None
if query.upper() in autov22fileid:
fileid = str(autov22fileid[query.upper()])
hit = True
if re.sub(r'\..*$', "", query) in filename2fileid:
fileid = str(filename2fileid[re.sub(r'\..*$', "", query)])
hit = True
if query in name2fileid:
fileid = str(name2fileid[query])
hit = True
if hit is not True:
for k, v in [(k.lower(), v) for k, v in name2fileid.items()]:
if re.search(re.compile(query), k):
fileid = str(v)
if fileid in fileid2json:
result = json.dumps(fileid2json[fileid.strip()])
src = "https://huggingface.co/front/assets/huggingface_logo-noborder.svg"
if fileid in fileid2image:
src = fileid2image[fileid.strip()]
return result, '<img src="{}" style="max-height: 240px">'.format(src)
iface = gr.Interface(fn=greet, inputs="text", outputs=["text", "html"])
iface.launch(server_name="0.0.0.0")