Update app.py
Browse files
app.py
CHANGED
|
@@ -76,7 +76,7 @@ def embed(pil_img):
|
|
| 76 |
processed_inputs = proc(images=clean_image, return_tensors="pt")
|
| 77 |
with torch.no_grad():
|
| 78 |
feats = model.get_image_features(**processed_inputs)
|
| 79 |
-
user_vector = feats.squeeze().cpu().numpy()
|
| 80 |
return normalize(user_vector.reshape(1, -1))[0]
|
| 81 |
|
| 82 |
def recommend(query_image):
|
|
@@ -115,10 +115,9 @@ def recommend(query_image):
|
|
| 115 |
emj = ACTION_EMOJI.get(label, "")
|
| 116 |
real_idx = DS_INDICES[int(idx)]
|
| 117 |
try:
|
| 118 |
-
|
| 119 |
-
except
|
| 120 |
-
|
| 121 |
-
img = Image.new("RGB", (120,120), (60,60,60))
|
| 122 |
gallery.append((img, f"#{rank} {emj} {label.replace('_',' ')} 路 {score:.4f}"))
|
| 123 |
pct = min(int(score * 100), 100)
|
| 124 |
bars += f"""
|
|
@@ -221,6 +220,4 @@ with gr.Blocks(title="Human Action Recommender") as demo:
|
|
| 221 |
</div>""")
|
| 222 |
|
| 223 |
if __name__ == "__main__":
|
| 224 |
-
demo.launch(
|
| 225 |
-
|
| 226 |
-
|
|
|
|
| 76 |
processed_inputs = proc(images=clean_image, return_tensors="pt")
|
| 77 |
with torch.no_grad():
|
| 78 |
feats = model.get_image_features(**processed_inputs)
|
| 79 |
+
user_vector = feats.pooler_output.squeeze().cpu().numpy()
|
| 80 |
return normalize(user_vector.reshape(1, -1))[0]
|
| 81 |
|
| 82 |
def recommend(query_image):
|
|
|
|
| 115 |
emj = ACTION_EMOJI.get(label, "")
|
| 116 |
real_idx = DS_INDICES[int(idx)]
|
| 117 |
try:
|
| 118 |
+
img = ds[int(real_idx)]["image"].convert("RGB")
|
| 119 |
+
except:
|
| 120 |
+
img = Image.new("RGB", (120,120), (60,60,60))
|
|
|
|
| 121 |
gallery.append((img, f"#{rank} {emj} {label.replace('_',' ')} 路 {score:.4f}"))
|
| 122 |
pct = min(int(score * 100), 100)
|
| 123 |
bars += f"""
|
|
|
|
| 220 |
</div>""")
|
| 221 |
|
| 222 |
if __name__ == "__main__":
|
| 223 |
+
demo.launch()
|
|
|
|
|
|