tomo2chin2 commited on
Commit
f42c406
·
verified ·
1 Parent(s): 7dc0cef

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -18
app.py CHANGED
@@ -495,18 +495,24 @@ def process_pdf_url(pdf_url, duration_per_page, dpi, progress=gr.Progress()):
495
 
496
  # 2ページ目の画像を保存してアップロード
497
  page2_image_url = None
498
- page2_image_preview = None
499
  if total_pages >= 2:
500
  progress(0.9, desc="2ページ目の画像をアップロード中...")
501
  page2_image = images[1]
 
 
502
  with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as tmp_img:
503
  page2_image_path = tmp_img.name
504
  page2_image.save(page2_image_path, format='JPEG', quality=90)
505
 
506
  page2_image_url = video_uploader.upload_image(page2_image_path, prefix="pdf_page2")
507
- page2_image_preview = page2_image_path # Gradioプレビュー用
508
 
509
- # クリーンアップは後で行う
 
 
 
 
 
510
 
511
  # クリーンアップ
512
  if pdf_path and os.path.exists(pdf_path):
@@ -526,13 +532,12 @@ def process_pdf_url(pdf_url, duration_per_page, dpi, progress=gr.Progress()):
526
  video_url, # ビデオURL
527
  page2_image_url, # 2ページ目の画像URL
528
  message, # ステータスメッセージ
529
- video_url, # ビデオプレビュー
530
- page2_image_preview # 画像プレビュー
531
  )
532
 
533
  except Exception as e:
534
  logger.error(f"Gradio処理エラー: {e}", exc_info=True)
535
- return None, None, f"❌ エラー: {str(e)}", None, None
536
 
537
  # Gradio UI定義
538
  with gr.Blocks(title="PDF to Video Converter", theme=gr.themes.Soft()) as demo:
@@ -584,23 +589,17 @@ with gr.Blocks(title="PDF to Video Converter", theme=gr.themes.Soft()) as demo:
584
  )
585
 
586
  with gr.Row():
587
- with gr.Column():
588
- video_preview = gr.Video(
589
- label="動画プレビュー",
590
- interactive=False
591
- )
592
- with gr.Column():
593
- page2_image_preview = gr.Image(
594
- label="2ページ目プレビュー",
595
- interactive=False,
596
- type="filepath"
597
- )
598
 
599
  # イベント設定
600
  convert_btn.click(
601
  fn=process_pdf_url,
602
  inputs=[pdf_url_input, duration_slider, dpi_slider],
603
- outputs=[video_url_output, page2_image_url_output, status_output, video_preview, page2_image_preview]
604
  )
605
 
606
  # 使用例とサンプルURL
 
495
 
496
  # 2ページ目の画像を保存してアップロード
497
  page2_image_url = None
498
+ page2_image_pil = None
499
  if total_pages >= 2:
500
  progress(0.9, desc="2ページ目の画像をアップロード中...")
501
  page2_image = images[1]
502
+
503
+ # 一時ファイルに保存してアップロード
504
  with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as tmp_img:
505
  page2_image_path = tmp_img.name
506
  page2_image.save(page2_image_path, format='JPEG', quality=90)
507
 
508
  page2_image_url = video_uploader.upload_image(page2_image_path, prefix="pdf_page2")
 
509
 
510
+ # PIL.Imageオブジェトを直接Gradioに渡す
511
+ page2_image_pil = page2_image
512
+
513
+ # 一時ファイルを即座に削除(PIL経由で表示するため不要)
514
+ if os.path.exists(page2_image_path):
515
+ os.remove(page2_image_path)
516
 
517
  # クリーンアップ
518
  if pdf_path and os.path.exists(pdf_path):
 
532
  video_url, # ビデオURL
533
  page2_image_url, # 2ページ目の画像URL
534
  message, # ステータスメッセージ
535
+ page2_image_pil # 画像プレビュー(PIL.Image)
 
536
  )
537
 
538
  except Exception as e:
539
  logger.error(f"Gradio処理エラー: {e}", exc_info=True)
540
+ return None, None, f"❌ エラー: {str(e)}", None
541
 
542
  # Gradio UI定義
543
  with gr.Blocks(title="PDF to Video Converter", theme=gr.themes.Soft()) as demo:
 
589
  )
590
 
591
  with gr.Row():
592
+ page2_image_preview = gr.Image(
593
+ label="2ページ目プレビュー",
594
+ interactive=False,
595
+ type="pil"
596
+ )
 
 
 
 
 
 
597
 
598
  # イベント設定
599
  convert_btn.click(
600
  fn=process_pdf_url,
601
  inputs=[pdf_url_input, duration_slider, dpi_slider],
602
+ outputs=[video_url_output, page2_image_url_output, status_output, page2_image_preview]
603
  )
604
 
605
  # 使用例とサンプルURL