mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-18 10:44:33 +08:00
Add orig_name to serialized file repr (#2145)
This commit is contained in:
parent
eb81fa2cf2
commit
9b4bf627f2
@ -1,4 +1,3 @@
|
||||
import time
|
||||
import gradio as gr
|
||||
import os
|
||||
|
||||
|
@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import os
|
||||
from abc import ABC, abstractmethod
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict
|
||||
|
||||
from gradio import processing_utils
|
||||
@ -110,6 +111,7 @@ class FileSerializable(Serializable):
|
||||
"data": processing_utils.encode_url_or_file_to_base64(
|
||||
filename, encryption_key=encryption_key
|
||||
),
|
||||
"orig_name": Path(filename).name,
|
||||
"is_file": False,
|
||||
}
|
||||
|
||||
|
@ -850,10 +850,12 @@ class TestFile(unittest.TestCase):
|
||||
file_input = gr.File()
|
||||
output = file_input.preprocess(x_file)
|
||||
self.assertIsInstance(output, tempfile._TemporaryFileWrapper)
|
||||
serialized = file_input.serialize("test/test_files/sample_file.pdf")
|
||||
assert filecmp.cmp(
|
||||
file_input.serialize("test/test_files/sample_file.pdf")["name"],
|
||||
serialized["name"],
|
||||
"test/test_files/sample_file.pdf",
|
||||
)
|
||||
assert serialized["orig_name"] == "sample_file.pdf"
|
||||
assert output.orig_name == "test/test_files/sample_file.pdf"
|
||||
|
||||
self.assertIsInstance(file_input.generate_sample(), dict)
|
||||
|
Loading…
Reference in New Issue
Block a user