Stereo0001 commited on
Commit
c26ace6
·
verified ·
1 Parent(s): 4749bad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -7
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import pandas as pd
3
- import ppp as pp
 
4
 
5
  def process_csv(file):
6
  try:
@@ -8,17 +9,24 @@ def process_csv(file):
8
  if 'PMCID' in df.columns:
9
  pmcid_list = df['PMCID'].dropna().astype(str).tolist()
10
  pmcid_str = ','.join(pmcid_list)
11
- pp.main(pmcid_str)
12
- return f"成功处理以下 PMCID:\n{pmcid_str}"
 
 
 
 
13
  else:
14
- return "CSV 文件中没有名为 'PMCID' 的列。"
15
  except Exception as e:
16
- return f"处理文件时出错: {e}"
17
 
18
  gr.Interface(
19
  fn=process_csv,
20
  inputs=gr.File(label="上传 CSV 文件"),
21
- outputs=gr.Textbox(label="处理结果"),
 
 
 
22
  title="PubMed PDF 下载器",
23
- description="上传包含 PMCID 列的 CSV 文件,自动下载对应的 PubMed PDF"
24
  ).launch()
 
1
  import gradio as gr
2
  import pandas as pd
3
+ import ppp as pp # 你的处理逻辑模块
4
+ import os
5
 
6
  def process_csv(file):
7
  try:
 
9
  if 'PMCID' in df.columns:
10
  pmcid_list = df['PMCID'].dropna().astype(str).tolist()
11
  pmcid_str = ','.join(pmcid_list)
12
+ zip_path = pp.main(pmcid_str) # 调用主逻辑并返回 zip 路径
13
+
14
+ if os.path.exists(zip_path):
15
+ return f"成功处理 {len(pmcid_list)} 个 PMCID。", zip_path
16
+ else:
17
+ return "处理完成,但未找到打包后的文件。", None
18
  else:
19
+ return "CSV 文件中没有名为 'PMCID' 的列。", None
20
  except Exception as e:
21
+ return f"处理文件时出错: {e}", None
22
 
23
  gr.Interface(
24
  fn=process_csv,
25
  inputs=gr.File(label="上传 CSV 文件"),
26
+ outputs=[
27
+ gr.Textbox(label="处理结果"),
28
+ gr.File(label="下载 PDF ZIP")
29
+ ],
30
  title="PubMed PDF 下载器",
31
+ description="上传包含 PMCID 列的 CSV 文件,自动下载对应的 PubMed PDF,并打包为 ZIP 文件。"
32
  ).launch()