File size: 1,047 Bytes
47c696c 58ff7c4 47c696c 58ff7c4 47c696c 58ff7c4 47c696c 58ff7c4 47c696c 58ff7c4 47c696c 58ff7c4 47c696c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | 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,) |