sujyo commited on
Commit
6b605ca
·
verified ·
1 Parent(s): 23d0d10

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -6,6 +6,12 @@
6
  """
7
  import os, sys, tempfile, shutil
8
  from pathlib import Path
 
 
 
 
 
 
9
  import gradio as gr
10
  import numpy as np
11
  from PIL import Image, ImageOps
@@ -33,9 +39,7 @@ ensure_model()
33
  sys.path.insert(0, str(Path(__file__).parent))
34
  from pipeline import process as _pipeline_process
35
 
36
- OUTPUT_DIR = Path("/tmp/kyozai_output")
37
- OUTPUT_DIR.mkdir(exist_ok=True)
38
- os.environ["PIPELINE_OUT_DIR"] = str(OUTPUT_DIR)
39
 
40
 
41
  def scan_and_generate(image: Image.Image) -> tuple:
@@ -63,7 +67,9 @@ def scan_and_generate(image: Image.Image) -> tuple:
63
  pdf_b = candidate
64
  break
65
  if pdf_b is None:
66
- return None, "❌ PDF の生成に失敗しました。もう一度撮影してください。"
 
 
67
  return str(pdf_b), "✅ PDF 生成完了!下のボタンからダウンロードしてください"
68
  except Exception as e:
69
  import traceback
 
6
  """
7
  import os, sys, tempfile, shutil
8
  from pathlib import Path
9
+
10
+ # ── 出力先を pipeline インポート前に設定 (インポート時に読まれるため) ──────
11
+ _OUT = Path("/tmp/kyozai_output")
12
+ _OUT.mkdir(exist_ok=True)
13
+ os.environ["PIPELINE_OUT_DIR"] = str(_OUT)
14
+
15
  import gradio as gr
16
  import numpy as np
17
  from PIL import Image, ImageOps
 
39
  sys.path.insert(0, str(Path(__file__).parent))
40
  from pipeline import process as _pipeline_process
41
 
42
+ OUTPUT_DIR = _OUT # 上で設定済み
 
 
43
 
44
 
45
  def scan_and_generate(image: Image.Image) -> tuple:
 
67
  pdf_b = candidate
68
  break
69
  if pdf_b is None:
70
+ files = list(OUTPUT_DIR.glob(f"{name}*.pdf"))
71
+ debug = f"OUT={OUTPUT_DIR}, files={[f.name for f in files]}"
72
+ return None, f"❌ PDF 生成失敗。{debug}"
73
  return str(pdf_b), "✅ PDF 生成完了!下のボタンからダウンロードしてください"
74
  except Exception as e:
75
  import traceback