Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -163,6 +163,25 @@ def _open_images_from_paths(paths: List[str]) -> List[Image.Image]:
|
|
| 163 |
pass
|
| 164 |
return imgs
|
| 165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
@spaces.GPU(duration=_gpu_duration_gallery)
|
| 167 |
def batch_similarity(files: List[str], model_name: str, pooling: str):
|
| 168 |
# files is a list of filepaths from gr.Files
|
|
|
|
| 163 |
pass
|
| 164 |
return imgs
|
| 165 |
|
| 166 |
+
def _to_html_table(S: np.ndarray, names: List[str]) -> str:
|
| 167 |
+
# simple accessible HTML table render
|
| 168 |
+
names_safe = [os.path.basename(n) for n in names]
|
| 169 |
+
header = "<tr><th></th>" + "".join(f"<th style='padding:6px 8px;text-align:center'>{n}</th>" for n in names_safe) + "</tr>"
|
| 170 |
+
rows = []
|
| 171 |
+
for i, r in enumerate(S):
|
| 172 |
+
cells = "".join(f"<td style='padding:6px 8px;text-align:center'>{v:.3f}</td>" for v in r)
|
| 173 |
+
rows.append(f"<tr><th style='padding:6px 8px;text-align:left'>{names_safe[i]}</th>{cells}</tr>")
|
| 174 |
+
table = f"""
|
| 175 |
+
<div style="overflow:auto; max-height:380px; border:1px solid #ddd">
|
| 176 |
+
<table style="border-collapse:collapse; width:100%">
|
| 177 |
+
{header}
|
| 178 |
+
{''.join(rows)}
|
| 179 |
+
</table>
|
| 180 |
+
</div>
|
| 181 |
+
"""
|
| 182 |
+
return table
|
| 183 |
+
|
| 184 |
+
|
| 185 |
@spaces.GPU(duration=_gpu_duration_gallery)
|
| 186 |
def batch_similarity(files: List[str], model_name: str, pooling: str):
|
| 187 |
# files is a list of filepaths from gr.Files
|