-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_gui.py
More file actions
71 lines (57 loc) · 2.51 KB
/
run_gui.py
File metadata and controls
71 lines (57 loc) · 2.51 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
import tkinter as tk
from tkinter import filedialog, messagebox
import threading
from pidmini.steps import step1_text_classifier, step2_add_extracted, step3_final_output
def run_pipeline(pdf, text, page, log_widget):
try:
# Extract PDF to TXT files if PDF provided
import os
if pdf and os.path.isfile(pdf):
log_widget.insert(tk.END, "PDF 텍스트 추출 중...\n")
log_widget.update_idletasks()
from pidmini.pdf import extract_pdf_to_txt
import pidmini.cfg as cfg
txt_folder = extract_pdf_to_txt(pdf)
cfg.INPUT_FOLDER = txt_folder
log_widget.insert(tk.END, f"→ {txt_folder}에 추출 완료\n\n")
log_widget.update_idletasks()
out1 = step1_text_classifier()
out2 = step2_add_extracted(pdf, text, page, out1)
out3 = step3_final_output(out2)
log_widget.insert(tk.END, f"\n✅ 완료! 결과 파일: {out3}\n")
except Exception as e:
import traceback
log_widget.insert(tk.END, f"\n❌ 오류: {e}\n{traceback.format_exc()}\n")
def start_run():
pdf = pdf_entry.get().strip()
text = text_entry.get().strip()
try:
page = int(page_entry.get().strip())
except:
messagebox.showerror("오류", "기준 페이지는 숫자여야 합니다.")
return
if not pdf or not text:
messagebox.showerror("오류", "PDF와 기준 텍스트를 입력하세요.")
return
log.delete("1.0", tk.END)
threading.Thread(target=run_pipeline, args=(pdf, text, page, log), daemon=True).start()
root = tk.Tk()
root.title("P&ID 텍스트 추출기 (Tkinter GUI)")
root.geometry("700x500")
# UI 구성
tk.Label(root, text="PDF 파일:").pack(anchor="w", padx=10, pady=5)
pdf_entry = tk.Entry(root, width=80)
pdf_entry.pack(anchor="w", padx=10)
tk.Button(root, text="찾기", command=lambda: pdf_entry.insert(0, filedialog.askopenfilename(filetypes=[("PDF", "*.pdf")]))).pack(anchor="w", padx=10)
tk.Label(root, text="기준 텍스트:").pack(anchor="w", padx=10, pady=5)
text_entry = tk.Entry(root, width=40)
text_entry.insert(0, "LINE NO")
text_entry.pack(anchor="w", padx=10)
tk.Label(root, text="기준 페이지:").pack(anchor="w", padx=10, pady=5)
page_entry = tk.Entry(root, width=10)
page_entry.insert(0, "1")
page_entry.pack(anchor="w", padx=10)
tk.Button(root, text="실행", command=start_run, bg="#4CAF50", fg="white").pack(anchor="center", pady=10)
log = tk.Text(root, height=15, width=80)
log.pack(padx=10, pady=5)
root.mainloop()