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