bano1 commited on
Commit
ab847ec
·
verified ·
1 Parent(s): c068eb6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -1
app.py CHANGED
@@ -37,6 +37,26 @@ def extract_text_from_pdf(pdf_file):
37
  for page in doc:
38
  text += page.get_text()
39
  return text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  def extract_metadata(text):
42
  # Very naive metadata extractor (replace with actual if needed)
@@ -167,12 +187,13 @@ with tabs[0]:
167
  for file in uploaded_files:
168
  text = extract_text_from_pdf(file)
169
  meta = extract_metadata(text)
 
 
170
  meta["summary"] = get_summary(meta["abstract"])
171
  meta["limitations"] = get_limitations(meta["abstract"])
172
  # Extract only keywords, not scores, and join into string
173
  keywords = kw_model.extract_keywords(meta["abstract"], top_n=5)
174
  meta["keywords"] = ", ".join([kw[0] for kw in keywords]) if keywords else ""
175
- meta["authors"] = ["Author A", "Author B"] # Dummy authors
176
  st.session_state.papers.append(meta)
177
  st.success("Papers processed and added!")
178
 
 
37
  for page in doc:
38
  text += page.get_text()
39
  return text
40
+ def extract_authors_from_pdf(pdf_file):
41
+ doc = fitz.open(stream=pdf_file.read(), filetype="pdf")
42
+ first_page_text = doc[0].get_text("text")
43
+
44
+ # simple heuristic: authors are usually after title but before abstract
45
+ lines = first_page_text.split("\n")
46
+ authors = []
47
+
48
+ for line in lines[1:15]: # scan first 15 lines after title
49
+ if "abstract" in line.lower():
50
+ break
51
+ # avoid very long lines (likely affiliations)
52
+ if 2 <= len(line.split()) <= 8:
53
+ authors.append(line.strip())
54
+
55
+ # fallback if nothing found
56
+ if not authors:
57
+ authors = ["Unknown"]
58
+
59
+ return authors
60
 
61
  def extract_metadata(text):
62
  # Very naive metadata extractor (replace with actual if needed)
 
187
  for file in uploaded_files:
188
  text = extract_text_from_pdf(file)
189
  meta = extract_metadata(text)
190
+ file.seek(0) # reset pointer because we already read it
191
+ meta["authors"] = extract_authors_from_pdf(file)
192
  meta["summary"] = get_summary(meta["abstract"])
193
  meta["limitations"] = get_limitations(meta["abstract"])
194
  # Extract only keywords, not scores, and join into string
195
  keywords = kw_model.extract_keywords(meta["abstract"], top_n=5)
196
  meta["keywords"] = ", ".join([kw[0] for kw in keywords]) if keywords else ""
 
197
  st.session_state.papers.append(meta)
198
  st.success("Papers processed and added!")
199