ankban commited on
Commit
42b0f48
·
verified ·
1 Parent(s): 8824402

Update file_viewer_panel.py

Browse files
Files changed (1) hide show
  1. file_viewer_panel.py +11 -3
file_viewer_panel.py CHANGED
@@ -3,10 +3,18 @@ import os
3
  import shutil
4
  import json
5
  import tempfile
 
6
  from pdf2image import convert_from_path
7
- from gradio.files import move_to_cache
8
  from file_utils import extract_text_from_file, call_llm, save_user_file, fetch_user_files
9
 
 
 
 
 
 
 
 
 
10
  def file_viewer_dashboard(nickname):
11
  with gr.Column(scale=4, elem_id="main-column") as file_panel:
12
  with gr.Row():
@@ -49,8 +57,8 @@ def file_viewer_dashboard(nickname):
49
  for i, img in enumerate(images):
50
  img_path = os.path.join(temp_dir, f"page_{i}.png")
51
  img.save(img_path, "PNG")
52
- gr_img_path = move_to_cache(img_path)
53
- paths.append(gr_img_path)
54
 
55
  initial_html = "".join([
56
  f"<img src='file={paths[i]}' style='width:100%; margin-bottom:12px; border-radius:8px;'/>"
 
3
  import shutil
4
  import json
5
  import tempfile
6
+ import uuid
7
  from pdf2image import convert_from_path
 
8
  from file_utils import extract_text_from_file, call_llm, save_user_file, fetch_user_files
9
 
10
+ def make_public_file(img_path):
11
+ public_dir = "/tmp/gradio-public"
12
+ os.makedirs(public_dir, exist_ok=True)
13
+ filename = f"{uuid.uuid4()}.png"
14
+ public_path = os.path.join(public_dir, filename)
15
+ shutil.copy(img_path, public_path)
16
+ return public_path
17
+
18
  def file_viewer_dashboard(nickname):
19
  with gr.Column(scale=4, elem_id="main-column") as file_panel:
20
  with gr.Row():
 
57
  for i, img in enumerate(images):
58
  img_path = os.path.join(temp_dir, f"page_{i}.png")
59
  img.save(img_path, "PNG")
60
+ public_path = make_public_file(img_path)
61
+ paths.append(public_path)
62
 
63
  initial_html = "".join([
64
  f"<img src='file={paths[i]}' style='width:100%; margin-bottom:12px; border-radius:8px;'/>"