x
This commit is contained in:
@@ -106,13 +106,15 @@ async def process_pdf(file_obj, backend, lang, progress=gr.Progress()):
|
||||
|
||||
tmp_dir = tempfile.mkdtemp(prefix="mineru-client-")
|
||||
|
||||
# 兼容不同 Gradio 版本的 file 返回值
|
||||
if isinstance(file_obj, str):
|
||||
# Gradio 6.0 binary mode:file_obj 是 bytes
|
||||
if isinstance(file_obj, bytes):
|
||||
file_path = os.path.join(tmp_dir, "input.pdf")
|
||||
file_name = "input.pdf"
|
||||
with open(file_path, "wb") as f:
|
||||
f.write(file_obj)
|
||||
elif isinstance(file_obj, str):
|
||||
file_path = file_obj
|
||||
file_name = os.path.basename(file_path)
|
||||
elif hasattr(file_obj, 'name'):
|
||||
file_path = file_obj.name
|
||||
file_name = os.path.basename(file_path)
|
||||
else:
|
||||
return "Unsupported file object type", "", ""
|
||||
|
||||
@@ -208,7 +210,7 @@ def create_ui():
|
||||
file_input = gr.File(
|
||||
label="Upload PDF",
|
||||
file_types=[".pdf"],
|
||||
type="filepath",
|
||||
type="binary",
|
||||
)
|
||||
backend_dd = gr.Dropdown(
|
||||
label="Backend",
|
||||
|
||||
Reference in New Issue
Block a user