import os import shutil import time, random, string import gradio as gr def ulid(): timestamp = int(time.time()) rand = ''.join(random.choices(string.ascii_uppercase + string.digits, k=6)) return f"{timestamp}{rand}" def upload(file): if not file: return "No file uploaded." domain = "https://minhvh-toolkit.hf.space/file=" # domain = "http://localhost:7860/file=" links = [] ext = os.path.splitext(file.name)[1] name = '/tmp/' + ulid() + ext shutil.copy(file.name, name) links.append(f"{domain}{name}") return "\n".join(links) # Sử dụng gr.Blocks để có thêm control with gr.Blocks(title="File Upload Tool") as demo: gr.Markdown("# Upload Files and Get Links") files_input = gr.File(label="Files") output_code = gr.Code(label="Links", interactive=False, language="markdown") files_input.change( fn=upload, inputs=files_input, outputs=output_code ) if __name__ == "__main__": demo.launch(show_error=True,)