Spaces:
Running
Running
return results as html
Browse files
app.py
CHANGED
@@ -68,7 +68,7 @@ def process_image(image):
|
|
68 |
# Read the index file and perform search of top 50 images
|
69 |
index = faiss.read_index("vector.index")
|
70 |
distances, indices = index.search(vector, 50)
|
71 |
-
matches =
|
72 |
for idx, matching_gamerpic in enumerate(indices[0]):
|
73 |
gamerpic = images[matching_gamerpic]
|
74 |
# Return the corresponding title with only the matched gamerpic
|
@@ -76,13 +76,29 @@ def process_image(image):
|
|
76 |
{"gamerpics.cdn": gamerpic},
|
77 |
{"name": 1, "type": 1, "url": 1, "gamerpics.$": 1},
|
78 |
)
|
79 |
-
|
80 |
title["rank"] = idx
|
81 |
title["score"] = str(round((1 / (distances[0][idx] + 1) * 100), 2)) + "%"
|
82 |
-
matches.append(title)
|
83 |
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
|
88 |
# Create a Gradio interface
|
|
|
68 |
# Read the index file and perform search of top 50 images
|
69 |
index = faiss.read_index("vector.index")
|
70 |
distances, indices = index.search(vector, 50)
|
71 |
+
matches = ""
|
72 |
for idx, matching_gamerpic in enumerate(indices[0]):
|
73 |
gamerpic = images[matching_gamerpic]
|
74 |
# Return the corresponding title with only the matched gamerpic
|
|
|
76 |
{"gamerpics.cdn": gamerpic},
|
77 |
{"name": 1, "type": 1, "url": 1, "gamerpics.$": 1},
|
78 |
)
|
79 |
+
print(title["name"])
|
80 |
title["rank"] = idx
|
81 |
title["score"] = str(round((1 / (distances[0][idx] + 1) * 100), 2)) + "%"
|
|
|
82 |
|
83 |
+
html = f"""
|
84 |
+
<h3 class="mr-4 inline align-middle text-3xl hover:underline">Matching gamerpics: Top 50 results</h3>
|
85 |
+
<div class="mt-8 flex flex-wrap gap-x-2">
|
86 |
+
<a href="{title['url']}" alt="{title['name']}" class="min-w-[130px] grow">
|
87 |
+
<div id="{title['_id']}" hx-swap="morph:innerHTML" class="mb-4 rounded-xl border border-black/5 p-2 hover:border-transparent hover:bg-black/5">
|
88 |
+
<div class="flex-grow items-center text-center">
|
89 |
+
<img src="https://assets.xboxgamer.pics{title['gamerpics'][0]['cdn']}" width="64" height="64" class="mx-auto" alt="Gamerpic" />
|
90 |
+
<span class="text-center align-middle text-lg">{title["name"]}</span>
|
91 |
+
<div class="inline-block rounded-2xl border border-stone-200 bg-white px-2 py-1 text-xs font-bold uppercase">
|
92 |
+
Score: {title["score"]}
|
93 |
+
</div>
|
94 |
+
</div>
|
95 |
+
</div>
|
96 |
+
</a>
|
97 |
+
</div>
|
98 |
+
"""
|
99 |
+
matches.append(html)
|
100 |
+
|
101 |
+
return matches
|
102 |
|
103 |
|
104 |
# Create a Gradio interface
|