Spaces:
Runtime error
Runtime error
feat: fix layout
Browse files
app.py
CHANGED
@@ -11,17 +11,22 @@ def get_article_text():
|
|
11 |
article = re.sub(r"^---.+---\s+", "", article, flags=re.MULTILINE + re.DOTALL)
|
12 |
return article
|
13 |
|
14 |
-
|
|
|
|
|
15 |
|
16 |
def find_matching_images(input_img, n_matches: int = 10):
|
|
|
17 |
results = analyze_image(input_img, annoy_index, n_matches=n_matches)
|
18 |
|
19 |
|
20 |
indexes = results[0]
|
21 |
-
|
22 |
|
23 |
images = []
|
24 |
|
|
|
|
|
25 |
for i in range(len(indexes)):
|
26 |
index = str(indexes[i])
|
27 |
|
@@ -31,7 +36,23 @@ def find_matching_images(input_img, n_matches: int = 10):
|
|
31 |
if url != "":
|
32 |
images.append(url)
|
33 |
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
iface = gr.Interface(
|
37 |
find_matching_images,
|
@@ -44,7 +65,8 @@ iface = gr.Interface(
|
|
44 |
inputs=[
|
45 |
gr.inputs.Image(shape=None, label="Your image"),
|
46 |
],
|
47 |
-
outputs=gr.Gallery(label="類似する貼り込み資料"),
|
|
|
48 |
examples=[
|
49 |
["images/025_0085.jpg"],
|
50 |
["images/046_0051.jpg"],
|
|
|
11 |
article = re.sub(r"^---.+---\s+", "", article, flags=re.MULTILINE + re.DOTALL)
|
12 |
return article
|
13 |
|
14 |
+
STYLE = """
|
15 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" integrity="sha256-YvdLHPgkqJ8DVUxjjnGVlMMJtNimJ6dYkowFFvp4kKs=" crossorigin="anonymous">
|
16 |
+
"""
|
17 |
|
18 |
def find_matching_images(input_img, n_matches: int = 10):
|
19 |
+
|
20 |
results = analyze_image(input_img, annoy_index, n_matches=n_matches)
|
21 |
|
22 |
|
23 |
indexes = results[0]
|
24 |
+
scores = results[1]
|
25 |
|
26 |
images = []
|
27 |
|
28 |
+
HTML = ""
|
29 |
+
|
30 |
for i in range(len(indexes)):
|
31 |
index = str(indexes[i])
|
32 |
|
|
|
36 |
if url != "":
|
37 |
images.append(url)
|
38 |
|
39 |
+
score = round(100 - scores[i], 1)
|
40 |
+
|
41 |
+
HTML += f"""<div class="card mb-3">
|
42 |
+
<div class="row g-0">
|
43 |
+
<div class="col-md-4 text-center">
|
44 |
+
<img style="max-height: 150px" src="{url}" alt="{mapping["name"]}">
|
45 |
+
</div>
|
46 |
+
<div class="col-md-8">
|
47 |
+
<div class="card-body">
|
48 |
+
<h5 class="card-title">{mapping["name"]}</h5>
|
49 |
+
<p class="card-text">{score} %</p>
|
50 |
+
</div>
|
51 |
+
</div>
|
52 |
+
</div>
|
53 |
+
</div>"""
|
54 |
+
|
55 |
+
return f"""{STYLE} <div style="height: 600px; overflow-y: auto;">{HTML}</div>"""
|
56 |
|
57 |
iface = gr.Interface(
|
58 |
find_matching_images,
|
|
|
65 |
inputs=[
|
66 |
gr.inputs.Image(shape=None, label="Your image"),
|
67 |
],
|
68 |
+
# outputs=gr.Gallery(label="類似する貼り込み資料").style(height="100px"),
|
69 |
+
outputs=gr.HTML(label="類似する貼り込み資料"),
|
70 |
examples=[
|
71 |
["images/025_0085.jpg"],
|
72 |
["images/046_0051.jpg"],
|