Spaces:
Runtime error
Runtime error
add try/except to display image
Browse files
app.py
CHANGED
@@ -12,12 +12,14 @@ wit_index_path = f"./models/wit_faiss.idx"
|
|
12 |
model_name = f"./models/distilbert-base-wit"
|
13 |
wit_dataset_path = "./models/wit_dataset.pkl"
|
14 |
|
|
|
15 |
@st.cache(suppress_st_warning=True, allow_output_mutation=True)
|
16 |
def get_wit_index():
|
17 |
st.write("Loading the WIT index, dataset and the DistillBERT model..")
|
18 |
wit_index = WitIndex(wit_index_path, model_name, wit_dataset_path, gpu=False)
|
19 |
return wit_index
|
20 |
|
|
|
21 |
# @st.cache(suppress_st_warning=True)
|
22 |
def process(text: str, top_k: int = 10):
|
23 |
# st.write("Cache miss: process")
|
@@ -74,7 +76,10 @@ if st.button("Run"):
|
|
74 |
print(f"Search in {time_diff} seconds")
|
75 |
st.markdown(f"*Search in {time_diff:.5f} seconds*")
|
76 |
for i, distance in enumerate(distances):
|
77 |
-
|
|
|
|
|
|
|
78 |
st.write(f"{image_info[i][1]}. (D: {distance:.2f})")
|
79 |
|
80 |
# Reset state
|
|
|
12 |
model_name = f"./models/distilbert-base-wit"
|
13 |
wit_dataset_path = "./models/wit_dataset.pkl"
|
14 |
|
15 |
+
|
16 |
@st.cache(suppress_st_warning=True, allow_output_mutation=True)
|
17 |
def get_wit_index():
|
18 |
st.write("Loading the WIT index, dataset and the DistillBERT model..")
|
19 |
wit_index = WitIndex(wit_index_path, model_name, wit_dataset_path, gpu=False)
|
20 |
return wit_index
|
21 |
|
22 |
+
# st.cache is disabled temporarily because the inference could take forever using newer streamlit version.
|
23 |
# @st.cache(suppress_st_warning=True)
|
24 |
def process(text: str, top_k: int = 10):
|
25 |
# st.write("Cache miss: process")
|
|
|
76 |
print(f"Search in {time_diff} seconds")
|
77 |
st.markdown(f"*Search in {time_diff:.5f} seconds*")
|
78 |
for i, distance in enumerate(distances):
|
79 |
+
try:
|
80 |
+
st.image(image_info[i][0].replace("http:", "https:"), width=400)
|
81 |
+
except FileNotFoundError:
|
82 |
+
st.write(f"{image_info[i][0]} can't be displayed")
|
83 |
st.write(f"{image_info[i][1]}. (D: {distance:.2f})")
|
84 |
|
85 |
# Reset state
|