File size: 845 Bytes
82c1620
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import os
import shutil
import uuid

def generate_temp_url(file):
    if file is None:
        return None, "❌ No file uploaded"

    # Create a unique filename to avoid collisions
    file_id = str(uuid.uuid4())
    file_path = os.path.join(f"{file_id}_{os.path.basename(file.name)}")

    shutil.copy(file.name, file_path)

    return file_path, "File uploaded"

with gr.Blocks(title="temp_url_generator") as app:
    gr.Markdown("## Upload a file")

    file_input = gr.File(label="Upload your file")
    upload_btn = gr.Button("upload file")

    file_output = gr.File(label="Download File")
    status = gr.Textbox(label="Status", interactive=False)

    upload_btn.click(
        fn=generate_temp_url,
        inputs=file_input,
        outputs=[file_output, status]
    )

if __name__ == "__main__":
    app.launch()