CCockrum commited on
Commit
930f993
·
verified ·
1 Parent(s): a1888b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -36
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
- 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 = TfidfVectorizer(stop_words='english')
219
  tfidf_matrix = tfidf.fit_transform(reference_df['description'])
220
  for idx, row in incomplete_with_desc.iterrows():
221
- if pd.isna(row['subject']) and pd.notna(row['description']):
222
- desc_vec = tfidf.transform([str(row['description'])])
223
- sims = cosine_similarity(desc_vec, tfidf_matrix).flatten()
224
- top_idx = sims.argmax()
225
- suggested_subject = metadata_df.iloc[top_idx]['subject']
226
- if pd.notna(suggested_subject) and suggested_subject:
227
- suggestions.append((row['title'], suggested_subject))
228
- if suggestions:
229
- suggestions_df = pd.DataFrame(suggestions, columns=["Title", "Suggested Subject"])
230
- st.subheader("📋 Suggested Metadata Enhancements Table")
231
- st.table(suggestions_df)
232
-
233
- st.markdown("<div class='custom-table'>" + suggestions_df.to_markdown(index=True) + "</div>", unsafe_allow_html=True)
234
-
235
- else:
236
- st.markdown("""
237
- <div class='custom-table'>
238
- <b>ℹ️ No metadata enhancement suggestions available.</b>
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.warning("No metadata records found for this collection. Try selecting another one.")
 
 
 
 
 
 
 
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.")