import gradio as gr from typing import Dict import base64 def encode_file_to_base64(f): with open(f, "rb") as file: encoded_string = base64.b64encode(file.read()) base64_str = str(encoded_string, "utf-8") return base64_str class CustomFile(gr.File): def get_block_name(self) -> str: return "file" def postprocess(self, y: str) -> Dict: res = super().postprocess(y) if res is not None: for file in res: file['data'] = encode_file_to_base64(file['name']) return res