This commit is contained in:
2026-05-18 11:21:13 +02:00
parent 6498c4e444
commit d5b630a793
5 changed files with 125 additions and 12 deletions
+45 -5
View File
@@ -11,16 +11,30 @@ Pouziti:
"""
import sys
import os
import json
import base64
import io
import copy
import tkinter as tk
from tkinter import filedialog
from pathlib import Path
from datetime import date
import fitz # pymupdf
import anthropic
def _load_env():
env_path = Path(__file__).resolve().parent.parent / "Medevio" / ".env"
if env_path.exists():
for line in env_path.read_text(encoding="utf-8").splitlines():
line = line.strip()
if "=" in line and not line.startswith("#"):
k, v = line.split("=", 1)
os.environ[k.strip()] = v.strip()
_load_env()
HISTORY_FILE = Path(__file__).parent / "pojmenovani_historie.json"
N_PAGES = 5
DPI = 120 # dostatecne pro cteni obsahu, nizke naklady na tokeny
@@ -151,12 +165,29 @@ def dialog(claude_suggestion: str) -> dict:
# ---------- hlavni logika ----------
def pick_file() -> Path | None:
"""Otevre dialog pro vyber PDF souboru."""
root = tk.Tk()
root.withdraw()
root.attributes("-topmost", True)
chosen = filedialog.askopenfilename(
title="Vyber PDF k pojmenovani",
filetypes=[("PDF soubory", "*.pdf"), ("Vsechny soubory", "*.*")],
initialdir=Path(__file__).parent / "vystup",
)
root.destroy()
return Path(chosen) if chosen else None
def main():
if len(sys.argv) < 2:
print(__doc__)
sys.exit(1)
pdf_path = pick_file()
if pdf_path is None:
print("Zadny soubor nebyl vybran.")
sys.exit(0)
else:
pdf_path = Path(sys.argv[1])
pdf_path = Path(sys.argv[1])
if not pdf_path.exists():
print(f"Soubor nenalezen: {pdf_path}")
sys.exit(1)
@@ -177,13 +208,22 @@ def main():
claude_name = ask_claude(images, history)
print(f" Claude navrhuje: {claude_name}")
res = dialog(claude_name)
# Pokud uz jsme tento soubor pojmenovavali (Claude navrhl stejne jmeno),
# predvyplnime dialog predchozi volbou uzivatele.
prefill = claude_name
for item in reversed(history):
if item["claude"] == claude_name:
prefill = item["user"]
print(f" Znamy dokument — predvyplnuji predchozi nazev: {prefill}")
break
res = dialog(prefill)
if res["cancelled"] or not res["name"]:
print("Zruseno — soubor nebyl prejmenovan.")
return
user_name = res["name"]
user_name = res["name"].replace("/", "-").replace("\\", "-").strip()
# uloz do historie
history.append({"claude": claude_name, "user": user_name})