File size: 1,415 Bytes
5ae5dcd a95df60 5ae5dcd a95df60 5ae5dcd cf85d3b 5ae5dcd cf85d3b a95df60 cf85d3b a95df60 cf85d3b 95e6d1e a95df60 cf85d3b c0a8798 a95df60 5ae5dcd a95df60 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
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")
|