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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -215,26 +215,30 @@ if fetch_data:
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'>
 
215
  tfidf = TfidfVectorizer(stop_words='english')
216
  try:
217
  suggestions = []
218
+ tfidf_matrix = tfidf.fit_transform(reference_df['description'])
219
+
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
+
229
  if suggestions:
230
  suggestions_df = pd.DataFrame(suggestions, columns=["Title", "Suggested Subject"])
231
+ st.table(suggestions_df)
232
  else:
233
  st.markdown("""
234
  <div class='custom-table'>
235
  <b>ℹ️ No metadata enhancement suggestions available.</b>
236
  </div>
237
  """, unsafe_allow_html=True)
238
+
239
  except Exception as e:
240
  st.error(f"Error generating metadata suggestions: {e}")
241
+
242
  else:
243
  st.markdown("""
244
  <div class='custom-table'>