Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -44,22 +44,30 @@ hf_writer_incorrect = gr.HuggingFaceDatasetSaver(
|
|
44 |
# return function(*args, **kwargs)
|
45 |
|
46 |
|
47 |
-
def display_file(
|
48 |
-
global
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
51 |
return gr.HTML.update(visible=False), gr.Image.update(visible=False)
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
58 |
else:
|
59 |
-
# image
|
60 |
-
|
61 |
-
|
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):
|