Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -19,7 +19,7 @@ st.set_page_config(
|
|
| 19 |
layout="wide"
|
| 20 |
)
|
| 21 |
|
| 22 |
-
debug =
|
| 23 |
|
| 24 |
#st.write("Available models:", open_clip.list_models())
|
| 25 |
|
|
@@ -60,6 +60,7 @@ def knn_get_score(knn, k, cat, vec):
|
|
| 60 |
kscores = scores[sortinds][:k]
|
| 61 |
if debug: st.write('kscores.shape', kscores.shape)
|
| 62 |
# Get actual sorted similiarity scores
|
|
|
|
| 63 |
ksims = cos_sim_table[np.expand_dims(np.arange(sortinds.shape[0]), axis=1), sortinds]
|
| 64 |
if debug: st.write('ksims.shape', ksims.shape)
|
| 65 |
# Apply normalization after exponential formula
|
|
@@ -111,8 +112,8 @@ def main():
|
|
| 111 |
if debug: st.write(vec.shape)
|
| 112 |
vec = vec.numpy()
|
| 113 |
k = 40
|
| 114 |
-
for cat in
|
| 115 |
-
st.write(cat, 'rating =
|
| 116 |
|
| 117 |
except Exception as e:
|
| 118 |
st.error(f"Error processing image: {str(e)}")
|
|
|
|
| 19 |
layout="wide"
|
| 20 |
)
|
| 21 |
|
| 22 |
+
debug = False
|
| 23 |
|
| 24 |
#st.write("Available models:", open_clip.list_models())
|
| 25 |
|
|
|
|
| 60 |
kscores = scores[sortinds][:k]
|
| 61 |
if debug: st.write('kscores.shape', kscores.shape)
|
| 62 |
# Get actual sorted similiarity scores
|
| 63 |
+
# (line copied from clip_retrieval_knn.py even though sortinds.shape[0] == 1 here)
|
| 64 |
ksims = cos_sim_table[np.expand_dims(np.arange(sortinds.shape[0]), axis=1), sortinds]
|
| 65 |
if debug: st.write('ksims.shape', ksims.shape)
|
| 66 |
# Apply normalization after exponential formula
|
|
|
|
| 112 |
if debug: st.write(vec.shape)
|
| 113 |
vec = vec.numpy()
|
| 114 |
k = 40
|
| 115 |
+
for cat in categories:
|
| 116 |
+
st.write(cat, f'rating = {knn_get_score(knn, k, cat, vec):.1f}')
|
| 117 |
|
| 118 |
except Exception as e:
|
| 119 |
st.error(f"Error processing image: {str(e)}")
|