-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyake_Single_file_uploder.py
More file actions
46 lines (37 loc) · 1.51 KB
/
Copy pathyake_Single_file_uploder.py
File metadata and controls
46 lines (37 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import streamlit as st
import PyPDF2
import yake
import time
def extract_keywords_from_pdf(pdf_file):
pdf_reader = PyPDF2.PdfReader(pdf_file)
full_text = ""
for page in pdf_reader.pages:
content = page.extract_text()
if content:
full_text += content
if not full_text.strip():
return None
kw_extractor = yake.KeywordExtractor(lan="en", n=2, dedupLim=0.9, top=10, features=None)
keywords = kw_extractor.extract_keywords(full_text)
return keywords
st.set_page_config(page_title="YAKE! Keyword Extractor")
st.title("PDF Keyword Extractor (YAKE!)")
uploaded_file = st.file_uploader("Upload your 2-page PDF", type=["pdf"])
if uploaded_file is not None:
with st.spinner('Extracting keywords...'):
start_time = time.perf_counter()
results = extract_keywords_from_pdf(uploaded_file)
end_time = time.perf_counter()
execution_time = end_time - start_time
if results:
st.write(f"⏱️ **Execution Time:** {execution_time:.4f} seconds")
st.subheader("Top Extracted Keywords:")
st.write("Note: Lower score means higher relevance in YAKE!")
for kw, score in results:
col1, col2 = st.columns([2, 1])
with col1:
st.info(f"**{kw}**")
with col2:
st.write(f"Score: `{round(score, 4)}`")
else:
st.error("Could not extract text from this PDF. Please check the file.")