Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -197,54 +197,54 @@ if fetch_data:
|
|
197 |
incomplete_mask = metadata_df.map(is_incomplete).any(axis=1)
|
198 |
incomplete_records = metadata_df[incomplete_mask]
|
199 |
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
|
206 |
-
if len(incomplete_with_desc) > 1 and len(reference_df) > 1:
|
207 |
-
try:
|
208 |
-
suggestions = []
|
209 |
-
tfidf_matrix = tfidf.fit_transform(reference_df['description'])
|
210 |
|
211 |
-
|
212 |
-
|
213 |
-
desc_vec = tfidf.transform([str(row['description'])])
|
214 |
-
sims = cosine_similarity(desc_vec, tfidf_matrix).flatten()
|
215 |
-
top_idx = sims.argmax()
|
216 |
-
suggested_subject = reference_df.iloc[top_idx]['subject']
|
217 |
-
if pd.notna(suggested_subject) and suggested_subject:
|
218 |
-
suggestions.append((row['title'], suggested_subject))
|
219 |
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
<b>ℹ️ No metadata enhancement suggestions available.</b>
|
227 |
-
</div>
|
228 |
-
""", unsafe_allow_html=True)
|
229 |
-
|
230 |
-
except Exception as e:
|
231 |
-
st.error(f"Error generating metadata suggestions: {e}")
|
232 |
-
else:
|
233 |
-
st.markdown("""
|
234 |
-
<div class='custom-table'>
|
235 |
-
<b>ℹ️ Not enough descriptive data to generate metadata suggestions.</b>
|
236 |
-
</div>
|
237 |
-
""", unsafe_allow_html=True)
|
238 |
-
|
239 |
-
|
240 |
-
except Exception as e:
|
241 |
-
st.error(f"Error generating metadata suggestions: {e}")
|
242 |
-
|
243 |
-
else:
|
244 |
-
st.markdown("""
|
245 |
-
<div class='custom-table'>
|
246 |
-
<b>ℹ️ Not enough descriptive data to generate metadata suggestions.</b>
|
247 |
-
</div>
|
248 |
-
""", unsafe_allow_html=True)
|
249 |
else:
|
250 |
st.warning("⚠️ No metadata records found for this collection. Try selecting another one.")
|
|
|
197 |
incomplete_mask = metadata_df.map(is_incomplete).any(axis=1)
|
198 |
incomplete_records = metadata_df[incomplete_mask]
|
199 |
|
200 |
+
st.subheader("✨ Suggested Metadata Enhancements")
|
201 |
+
|
202 |
+
incomplete_with_desc = incomplete_records[incomplete_records['description'].notnull()]
|
203 |
+
reference_df = metadata_df[metadata_df['subject'].notnull() & metadata_df['description'].notnull()]
|
204 |
+
tfidf = TfidfVectorizer(stop_words='english')
|
205 |
+
|
206 |
+
if len(incomplete_with_desc) > 1 and len(reference_df) > 1:
|
207 |
+
try:
|
208 |
+
suggestions = []
|
209 |
+
tfidf_matrix = tfidf.fit_transform(reference_df['description'])
|
210 |
+
|
211 |
+
for idx, row in incomplete_with_desc.iterrows():
|
212 |
+
if pd.isna(row['subject']) and pd.notna(row['description']):
|
213 |
+
desc_vec = tfidf.transform([str(row['description'])])
|
214 |
+
sims = cosine_similarity(desc_vec, tfidf_matrix).flatten()
|
215 |
+
top_idx = sims.argmax()
|
216 |
+
suggested_subject = reference_df.iloc[top_idx]['subject']
|
217 |
+
if pd.notna(suggested_subject) and suggested_subject:
|
218 |
+
suggestions.append((row['title'], suggested_subject))
|
219 |
+
|
220 |
+
if suggestions:
|
221 |
+
suggestions_df = pd.DataFrame(suggestions, columns=["Title", "Suggested Subject"])
|
222 |
+
st.markdown("<div class='custom-table'>" + suggestions_df.to_markdown(index=False) + "</div>", unsafe_allow_html=True)
|
223 |
+
else:
|
224 |
+
st.markdown("""
|
225 |
+
<div class='custom-table'>
|
226 |
+
<b>ℹ️ No metadata enhancement suggestions available.</b>
|
227 |
+
</div>
|
228 |
+
""", unsafe_allow_html=True)
|
229 |
+
|
230 |
+
except Exception as e:
|
231 |
+
st.error(f"Error generating metadata suggestions: {e}")
|
232 |
+
else:
|
233 |
+
st.markdown("""
|
234 |
+
<div class='custom-table'>
|
235 |
+
<b>ℹ️ Not enough descriptive data to generate metadata suggestions.</b>
|
236 |
+
</div>
|
237 |
+
""", unsafe_allow_html=True)
|
238 |
|
|
|
|
|
|
|
|
|
239 |
|
240 |
+
except Exception as e:
|
241 |
+
st.error(f"Error generating metadata suggestions: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
|
243 |
+
else:
|
244 |
+
st.markdown("""
|
245 |
+
<div class='custom-table'>
|
246 |
+
<b>ℹ️ Not enough descriptive data to generate metadata suggestions.</b>
|
247 |
+
</div>
|
248 |
+
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
249 |
else:
|
250 |
st.warning("⚠️ No metadata records found for this collection. Try selecting another one.")
|