Spaces:
Running
Running
| 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() |