tomo2chin2 commited on
Commit
4d151db
·
verified ·
1 Parent(s): 005e80d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -81,29 +81,39 @@ def ocr_pdf_with_gemini(pdf_path):
81
  return f"エラーが発生しました: {e}" # ユーザー向けのエラーメッセージ
82
 
83
 
 
 
 
 
 
 
84
  def process_pdf(pdf_file):
85
  """PDFファイルを処理するメイン関数"""
 
 
86
  # 一時ディレクトリを作成
87
  with tempfile.TemporaryDirectory() as temp_dir:
88
- # アップロードされたPDFを一時ファイルとして保存
89
- temp_pdf_path = os.path.join(temp_dir, "uploaded.pdf")
90
- with open(temp_pdf_path, "wb") as f:
91
- f.write(pdf_file.read()) # bytesではなく、.read()で読み込んだ内容を書き込む
92
 
93
- # PDFを分割
 
 
 
94
  split_pdf_paths = split_pdf(temp_pdf_path, temp_dir)
 
95
 
96
  # 並列処理でOCR変換
97
  markdown_results = []
98
  with ThreadPoolExecutor() as executor:
99
  markdown_results = list(executor.map(ocr_pdf_with_gemini, split_pdf_paths))
 
100
 
101
  # 結果を結合
102
  combined_markdown = "\n\n".join(markdown_results)
103
 
104
  return combined_markdown
105
 
106
-
107
  # Gradioインターフェースの作成
108
  def create_interface():
109
  with gr.Blocks() as demo:
 
81
  return f"エラーが発生しました: {e}" # ユーザー向けのエラーメッセージ
82
 
83
 
84
+ import logging
85
+
86
+ # ロギング設定
87
+ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
88
+
89
+
90
  def process_pdf(pdf_file):
91
  """PDFファイルを処理するメイン関数"""
92
+ logging.info(f"Received file: {pdf_file.name if hasattr(pdf_file, 'name') else pdf_file}") # ファイル名/オブジェクトのログ
93
+
94
  # 一時ディレクトリを作成
95
  with tempfile.TemporaryDirectory() as temp_dir:
96
+ # Gradioから渡されるのはNamedStringオブジェクトなので、.nameでファイルパスを取得
97
+ temp_pdf_path = pdf_file.name
 
 
98
 
99
+
100
+ logging.info(f"Temporary PDF path: {temp_pdf_path}")
101
+
102
+ # PDFを分割 (split_pdf に渡すパスは変更なし)
103
  split_pdf_paths = split_pdf(temp_pdf_path, temp_dir)
104
+ logging.info(f"Split PDF paths: {split_pdf_paths}")
105
 
106
  # 並列処理でOCR変換
107
  markdown_results = []
108
  with ThreadPoolExecutor() as executor:
109
  markdown_results = list(executor.map(ocr_pdf_with_gemini, split_pdf_paths))
110
+ logging.info(f"Markdown results length: {len(markdown_results)}")
111
 
112
  # 結果を結合
113
  combined_markdown = "\n\n".join(markdown_results)
114
 
115
  return combined_markdown
116
 
 
117
  # Gradioインターフェースの作成
118
  def create_interface():
119
  with gr.Blocks() as demo: