File size: 2,938 Bytes
cd3e0b8
93c008b
50a43ab
cd3e0b8
 
93c008b
cd3e0b8
93c008b
cd3e0b8
 
 
 
93c008b
cd3e0b8
 
f1e5728
cd3e0b8
 
 
 
 
 
50a43ab
cd3e0b8
50a43ab
cd3e0b8
 
 
 
 
 
 
50a43ab
cd3e0b8
50a43ab
cd3e0b8
 
 
 
 
 
 
50a43ab
cd3e0b8
 
 
 
f1e5728
cd3e0b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93c008b
cd3e0b8
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# app.py
import streamlit as st
from textsumm import 摘要
from pdfsum import 提取_pdf摘要
import requests

st.set_page_config(page_title="PDF 工具箱", page_icon="📄", layout="wide")

# 側邊欄
st.sidebar.title("📄 PDF 工具箱")
st.sidebar.write("請輸入 OpenAI API 金鑰(非必填)")
api_key = st.sidebar.text_input("sk-...", type="password")

# GPT 模型選擇
model = st.sidebar.radio("選擇 GPT 模型", options=["gpt-4", "gpt-4.0", "gpt-4.1", "gpt-4.5"], index=0)

# 工具選擇
tool = st.sidebar.radio("選擇功能", options=["文字摘要", "PDF 摘要", "論文搜尋"])

st.title("PDF 工具箱")

if tool == "文字摘要":
    st.header("📝 文字摘要")
    user_text = st.text_area("請輸入要摘要的中文內容")
    if st.button("生成摘要"):
        with st.spinner("摘要生成中..."):
            if user_text.strip():
                summary = 摘要(user_text.strip())
                st.success("摘要結果:")
                st.write(summary)
            else:
                st.warning("請輸入內容!")

elif tool == "PDF 摘要":
    st.header("📄 PDF 摘要")
    uploaded_file = st.file_uploader("上傳你的 PDF 文件", type=["pdf"])
    if uploaded_file is not None and st.button("產生 PDF 摘要"):
        with st.spinner("摘要生成中..."):
            summary = 提取_pdf摘要(uploaded_file, 摘要)
            st.success("摘要結果:")
            st.write(summary)
elif tool == "論文搜尋":
    st.header("🔎 論文搜尋(arXiv)")
    keyword = st.text_input("輸入主題或關鍵字", "量子")
    max_results = st.slider("結果數量", 1, 20, 5)
    start_year = st.number_input("起始年份", min_value=1990, max_value=2025, value=2019)
    end_year = st.number_input("結束年份", min_value=1990, max_value=2025, value=2025)
    if st.button("搜尋論文"):
        st.info("搜尋中...")
        url = f"http://export.arxiv.org/api/query?search_query=all:{keyword}&start=0&max_results={max_results}"
        resp = requests.get(url)
        if resp.ok:
            import xml.etree.ElementTree as ET
            root = ET.fromstring(resp.content)
            found = False
            for entry in root.findall("{http://www.w3.org/2005/Atom}entry"):
                published = entry.find("{http://www.w3.org/2005/Atom}published").text[:4]
                if start_year <= int(published) <= end_year:
                    found = True
                    title = entry.find("{http://www.w3.org/2005/Atom}title").text.strip()
                    link = entry.find("{http://www.w3.org/2005/Atom}id").text.strip()
                    st.markdown(f"**[{title}]({link})**({published})")
            if not found:
                st.warning("在所選年份範圍內沒有找到相關論文。")
        else:
            st.error("arXiv 查詢失敗")