File size: 1,123 Bytes
eeb2b4b
 
c26ace6
 
eeb2b4b
 
 
 
 
 
 
c26ace6
 
 
 
 
 
eeb2b4b
c26ace6
eeb2b4b
c26ace6
eeb2b4b
 
 
 
c26ace6
 
 
 
eeb2b4b
c26ace6
eeb2b4b
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
import gradio as gr
import pandas as pd
import ppp as pp  # 你的处理逻辑模块
import os

def process_csv(file):
    try:
        df = pd.read_csv(file.name)
        if 'PMCID' in df.columns:
            pmcid_list = df['PMCID'].dropna().astype(str).tolist()
            pmcid_str = ','.join(pmcid_list)
            zip_path = pp.main(pmcid_str)  # 调用主逻辑并返回 zip 路径

            if os.path.exists(zip_path):
                return f"成功处理 {len(pmcid_list)} 个 PMCID。", zip_path
            else:
                return "处理完成,但未找到打包后的文件。", None
        else:
            return "CSV 文件中没有名为 'PMCID' 的列。", None
    except Exception as e:
        return f"处理文件时出错: {e}", None

gr.Interface(
    fn=process_csv,
    inputs=gr.File(label="上传 CSV 文件"),
    outputs=[
        gr.Textbox(label="处理结果"),
        gr.File(label="下载 PDF ZIP")
    ],
    title="PubMed PDF 下载器",
    description="上传包含 PMCID 列的 CSV 文件,自动下载对应的 PubMed PDF,并打包为 ZIP 文件。"
).launch()