SenY commited on
Commit
a95df60
1 Parent(s): c0a8798

サムネイルの表示に対応

Browse files
Files changed (5) hide show
  1. app.py +20 -7
  2. autov22fileid.json +2 -2
  3. fileid2json.json +2 -2
  4. filename2fileid.json +2 -2
  5. 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
- if query in filename2fileid:
19
- fileid = str(filename2fileid[query])
 
 
20
  if query in name2fileid:
21
  fileid = str(name2fileid[query])
 
 
 
 
 
22
 
23
  if fileid in fileid2json:
24
  result = json.dumps(fileid2json[fileid.strip()])
25
- return result
 
 
 
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:83e8c2345358226015f46167b7db2b8679fe52a196bbdda5ffa732046d4eae1d
3
- size 1501256
 
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:1721d3cfc780d37437e5cdd46c47fc0614686a790bed4bd45e0e873e384361a0
3
- size 82846964
 
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:871cc43e3a31af8f08a8946c70878c1e5694af0af8e7a5c1026c87920919ad4e
3
- size 2044320
 
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:d7fe02437df0faa80dac8e1b0ecfaa327e2c0b087878d78b73b18b8680aea386
3
- size 2297509
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:407b0c945e24d7dd3b0775d2494be9e96d0686d264a2114022977d55e6919c0b
3
+ size 2298256