import streamlit as st from main import read_pdf, extract_key_phrases, score_sentences, summarize_text import io # 設定 Streamlit 應用標題 st.title("PDF 條列式重點摘要工具 🗟 🔏") # 上傳 PDF 檔案元件 uploaded_file = st.file_uploader("請上傳您的 PDF 文件", type="pdf") # 摘要比例滑桿 summary_scale = st.slider("請選擇摘要比例(%)", min_value=1, max_value=100, value=20) # 產生摘要按鈕 submit_button = st.button("產生摘要") # 若按下按鈕且有上傳檔案 if submit_button and uploaded_file is not None: with st.spinner('正在處理中,請稍候...'): # 讀取 PDF 內容 text = read_pdf(io.BytesIO(uploaded_file.getvalue())) # 擷取關鍵詞 key_phrases = extract_key_phrases(text) # 句子評分 sentence_scores = score_sentences(text, key_phrases) # 計算要顯示的重點句數 total_sentences = len(list(sentence_scores.keys())) num_points = max(1, total_sentences * summary_scale // 100) # 產生條列式摘要 summary = summarize_text(sentence_scores, num_points=num_points) # 顯示摘要 st.subheader("摘要結果:") st.markdown(summary)