Add orig_name to serialized file repr (#2145)

This commit is contained in:
Freddy Boulton 2022-09-06 10:40:59 -04:00 committed by GitHub
parent eb81fa2cf2
commit 9b4bf627f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 2 deletions

View File

@ -1,4 +1,3 @@
import time
import gradio as gr
import os

View File

@ -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,
}

View File

@ -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)