forked from Shaier/arxiv_summarizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyze_local.py
More file actions
100 lines (80 loc) · 3.29 KB
/
Copy pathanalyze_local.py
File metadata and controls
100 lines (80 loc) · 3.29 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"""
analyze_local.py -- Analyze a folder of local PDF files with LLM.
Reads every .pdf in the given directory, extracts full text, sends to LLM
for deep structured analysis, and writes per-paper Markdown files plus an
optional cross-paper synthesis report.
Usage:
python analyze_local.py --dir path/to/pdfs
python analyze_local.py --dir path/to/pdfs --lang zh --synthesis
python analyze_local.py --dir path/to/pdfs --topic "CRISPR" --synthesis --pdf
Arguments:
--dir / -d Path to folder containing PDF files (required)
--topic / -t Topic label used in synthesis & index (default: folder name)
--lang / -l Report language: en or zh (default: en)
--synthesis Generate cross-paper synthesis report (default: off)
--pdf Render Markdown output to PDF via pandoc (default: off)
--model / -m LLM model (default: api_key.txt line 3)
--env Conda env name (default: DailyEssay)
"""
import argparse
import shutil
import subprocess
import sys
from datetime import datetime
from pathlib import Path
ENV_NAME = "DailyEssay"
HERE = Path(__file__).parent
SCRIPT = HERE / "analyze_local_runner.py"
def conda_exe() -> str:
exe = shutil.which("conda")
if not exe:
print("[ERROR] conda not found.")
sys.exit(1)
return exe
def env_exists(conda: str, name: str) -> bool:
result = subprocess.run([conda, "env", "list"], capture_output=True, text=True)
return any(part == name
for line in result.stdout.splitlines()
for part in line.split())
def wizard() -> list:
print("=" * 60)
print(" Local PDF Analyzer -- Interactive Wizard")
print("=" * 60)
pdf_dir = input("Path to PDF folder: ").strip()
if not pdf_dir:
print("[ERROR] Folder path cannot be empty.")
sys.exit(1)
default_topic = Path(pdf_dir).name
topic = input(f"Topic label [default: {default_topic!r}]: ").strip() or default_topic
lang = input("Report language [en/zh, default: en]: ").strip().lower() or "en"
if lang not in ("en", "zh"):
lang = "en"
do_syn = input("Generate cross-paper synthesis? [y/N]: ").strip().lower() == "y"
do_pdf = input("Render output to PDF? [y/N]: ").strip().lower() == "y"
args = ["--dir", pdf_dir, "--topic", topic, "--lang", lang]
if do_syn: args.append("--synthesis")
if do_pdf: args.append("--pdf")
return args
def main():
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument("--env", default=ENV_NAME)
known, passthrough = parser.parse_known_args()
conda = conda_exe()
if not env_exists(conda, known.env):
print(f"[ERROR] Conda env '{known.env}' not found.")
sys.exit(1)
extra_args = passthrough if passthrough else wizard()
cmd = [conda, "run", "--no-capture-output", "-n", known.env,
"python", str(SCRIPT)] + extra_args
print(f"\n[Run] python analyze_local_runner.py {' '.join(extra_args)}\n")
rc = subprocess.run(cmd).returncode
print()
if rc == 0:
print("=" * 60)
print(" Complete! Results saved in analysis_output/")
print("=" * 60)
else:
print(f"[!] Script exited with code {rc}.")
sys.exit(rc)
if __name__ == "__main__":
main()