サムネイルの表示に対応
Browse files- app.py +20 -7
- autov22fileid.json +2 -2
- fileid2json.json +2 -2
- filename2fileid.json +2 -2
- name2fileid.json +2 -2
app.py
CHANGED
@@ -1,8 +1,10 @@
|
|
1 |
import gradio as gr
|
2 |
import json
|
3 |
from pathlib import Path
|
|
|
4 |
|
5 |
fileid2json = json.loads(Path("fileid2json.json").read_text())
|
|
|
6 |
|
7 |
autov22fileid = json.loads(Path("autov22fileid.json").read_text())
|
8 |
filename2fileid = json.loads(Path("filename2fileid.json").read_text())
|
@@ -12,17 +14,28 @@ name2fileid = json.loads(Path("name2fileid.json").read_text())
|
|
12 |
def greet(query):
|
13 |
result = "Not found"
|
14 |
fileid = query
|
|
|
15 |
|
16 |
-
if query in autov22fileid:
|
17 |
-
fileid = str(autov22fileid[query])
|
18 |
-
|
19 |
-
|
|
|
|
|
20 |
if query in name2fileid:
|
21 |
fileid = str(name2fileid[query])
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
if fileid in fileid2json:
|
24 |
result = json.dumps(fileid2json[fileid.strip()])
|
25 |
-
|
|
|
|
|
|
|
26 |
|
27 |
-
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
28 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import json
|
3 |
from pathlib import Path
|
4 |
+
import re
|
5 |
|
6 |
fileid2json = json.loads(Path("fileid2json.json").read_text())
|
7 |
+
fileid2image = json.loads(Path("fileid2image.json").read_text())
|
8 |
|
9 |
autov22fileid = json.loads(Path("autov22fileid.json").read_text())
|
10 |
filename2fileid = json.loads(Path("filename2fileid.json").read_text())
|
|
|
14 |
def greet(query):
|
15 |
result = "Not found"
|
16 |
fileid = query
|
17 |
+
hit = None
|
18 |
|
19 |
+
if query.upper() in autov22fileid:
|
20 |
+
fileid = str(autov22fileid[query.upper()])
|
21 |
+
hit = True
|
22 |
+
if re.sub(r'\..*$', "", query) in filename2fileid:
|
23 |
+
fileid = str(filename2fileid[re.sub(r'\..*$', "", query)])
|
24 |
+
hit = True
|
25 |
if query in name2fileid:
|
26 |
fileid = str(name2fileid[query])
|
27 |
+
hit = True
|
28 |
+
if hit is not True:
|
29 |
+
for k, v in [(k.lower(), v) for k, v in name2fileid.items()]:
|
30 |
+
if re.search(re.compile(query), k):
|
31 |
+
fileid = str(v)
|
32 |
|
33 |
if fileid in fileid2json:
|
34 |
result = json.dumps(fileid2json[fileid.strip()])
|
35 |
+
src = "https://huggingface.co/front/assets/huggingface_logo-noborder.svg"
|
36 |
+
if fileid in fileid2image:
|
37 |
+
src = fileid2image[fileid.strip()]
|
38 |
+
return result, '<img src="{}" style="max-height: 240px">'.format(src)
|
39 |
|
40 |
+
iface = gr.Interface(fn=greet, inputs="text", outputs=["text", "html"])
|
41 |
+
iface.launch(server_name="0.0.0.0")
|
autov22fileid.json
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7fb788ad61bb22f9c096a8175ecb85d31a66a706a2f3b2dd23bb63796b63b3c1
|
3 |
+
size 1501802
|
fileid2json.json
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:84cd1f5579aa81770e4b0942b825c8fe793b06fd68f2d279b770143dcaeb7ca6
|
3 |
+
size 83064973
|
filename2fileid.json
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ba9093d95e56df976930868251890024795330c3472190522784d947af865fc3
|
3 |
+
size 2045049
|
name2fileid.json
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:407b0c945e24d7dd3b0775d2494be9e96d0686d264a2114022977d55e6919c0b
|
3 |
+
size 2298256
|