bano1 commited on
Commit
be85bbd
·
verified ·
1 Parent(s): 13e6b3f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -7
app.py CHANGED
@@ -57,17 +57,39 @@ def generate_limitations_and_future(summary):
57
  # For simplicity we reuse summarizer as a text generator
58
  return summarizer(prompt, max_length=150, min_length=50, do_sample=False)[0]['summary_text']
59
 
 
 
 
 
 
 
 
 
60
  def lda_topic_modeling(papers):
61
- texts = [simple_preprocess(p["abstract"]) for p in papers if p["abstract"]]
 
 
 
 
 
62
  dictionary = corpora.Dictionary(texts)
63
  corpus = [dictionary.doc2bow(text) for text in texts]
64
  lda_model = models.LdaModel(corpus, num_topics=3, id2word=dictionary, passes=10)
65
- topics = lda_model.print_topics()
66
- return topics
67
 
 
 
 
 
 
 
 
 
 
 
 
68
  def generate_wordcloud(papers):
69
  text = " ".join([p["abstract"] for p in papers if p["abstract"]])
70
- wc = WordCloud(width=800, height=400).generate(text)
71
  fig, ax = plt.subplots()
72
  ax.imshow(wc, interpolation="bilinear")
73
  ax.axis("off")
@@ -156,9 +178,8 @@ with tabs[1]:
156
  with tabs[2]:
157
  st.header("Topic Modeling & Word Cloud")
158
  if st.session_state.papers:
159
- topics = lda_topic_modeling(st.session_state.papers)
160
- for t in topics:
161
- st.write(t)
162
  generate_wordcloud(st.session_state.papers)
163
  else:
164
  st.info("Upload papers first.")
 
57
  # For simplicity we reuse summarizer as a text generator
58
  return summarizer(prompt, max_length=150, min_length=50, do_sample=False)[0]['summary_text']
59
 
60
+ from nltk.corpus import stopwords
61
+
62
+ # Download NLTK stopwords if not already
63
+ import nltk
64
+ nltk.download('stopwords')
65
+ stop_words = set(stopwords.words("english"))
66
+
67
+ # ========== LDA TOPIC MODELING ==========
68
  def lda_topic_modeling(papers):
69
+ # Preprocess abstracts with stopword removal
70
+ texts = [
71
+ [word for word in simple_preprocess(p["abstract"]) if word not in stop_words]
72
+ for p in papers if p["abstract"]
73
+ ]
74
+
75
  dictionary = corpora.Dictionary(texts)
76
  corpus = [dictionary.doc2bow(text) for text in texts]
77
  lda_model = models.LdaModel(corpus, num_topics=3, id2word=dictionary, passes=10)
 
 
78
 
79
+ topics = lda_model.print_topics(num_words=6)
80
+
81
+ # Convert topics into a DataFrame
82
+ topic_data = []
83
+ for topic_id, words in topics:
84
+ topic_data.append({"Topic ID": topic_id, "Keywords": words})
85
+
86
+ df = pd.DataFrame(topic_data)
87
+ return df
88
+
89
+ # ========== WORDCLOUD ==========
90
  def generate_wordcloud(papers):
91
  text = " ".join([p["abstract"] for p in papers if p["abstract"]])
92
+ wc = WordCloud(width=800, height=400, stopwords=STOPWORDS).generate(text)
93
  fig, ax = plt.subplots()
94
  ax.imshow(wc, interpolation="bilinear")
95
  ax.axis("off")
 
178
  with tabs[2]:
179
  st.header("Topic Modeling & Word Cloud")
180
  if st.session_state.papers:
181
+ topics_df = lda_topic_modeling(st.session_state.papers)
182
+ st.dataframe(topics_df) # Display as DataFrame instead of CSV
 
183
  generate_wordcloud(st.session_state.papers)
184
  else:
185
  st.info("Upload papers first.")