qq1023 commited on
Commit
9b5fb59
·
1 Parent(s): 00ca9a0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -14
app.py CHANGED
@@ -44,22 +44,30 @@ hf_writer_incorrect = gr.HuggingFaceDatasetSaver(
44
  # return function(*args, **kwargs)
45
 
46
 
47
- def display_file(input_file):
48
- global current_file_path
49
- current_file_path = input_file.name if input_file else None
50
- if not input_file:
 
 
 
51
  return gr.HTML.update(visible=False), gr.Image.update(visible=False)
52
- if input_file.name.endswith(".pdf"):
53
- with open(input_file.name, "rb") as input_file:
54
- pdf_base64 = base64.b64encode(input_file.read()).decode()
55
- return gr.HTML.update(
56
- PDF_IFRAME.format(pdf_base64), visible=True
57
- ), gr.Image.update(visible=False)
 
 
 
 
 
58
  else:
59
- # image = Image.open(input_file.name)
60
- return gr.HTML.update(visible=False), gr.Image.update(
61
- input_file.name, visible=True
62
- )
63
 
64
 
65
  def show_intermediate_outputs(show_intermediate):
 
44
  # return function(*args, **kwargs)
45
 
46
 
47
+ def display_file(input_files):
48
+ global current_file_paths
49
+
50
+ # Initialize the list of current file paths
51
+ current_file_paths = [file.name for file in input_files]
52
+
53
+ if not input_files:
54
  return gr.HTML.update(visible=False), gr.Image.update(visible=False)
55
+
56
+ # Check if there's any PDF file among the uploaded files
57
+ pdf_base64 = None
58
+ for input_file in input_files:
59
+ if input_file.name.endswith(".pdf"):
60
+ with open(input_file.name, "rb") as pdf_file:
61
+ pdf_base64 = base64.b64encode(pdf_file.read()).decode()
62
+ break # Assuming only one PDF is present
63
+
64
+ if pdf_base64:
65
+ return gr.HTML.update(PDF_IFRAME.format(pdf_base64), visible=True), gr.Image.update(visible=False)
66
  else:
67
+ # You can choose to display the first image in the list or handle multiple images differently
68
+ image = Image.open(input_files[0].name)
69
+ return gr.HTML.update(visible=False), gr.Image.update(image, visible=True)
70
+
71
 
72
 
73
  def show_intermediate_outputs(show_intermediate):