import gradio as gr import tempfile import os def upload_and_share(file): if file is None: return "No file uploaded" # Create a temporary directory to store the uploaded file temp_dir = tempfile.mkdtemp() file_path = os.path.join(temp_dir, file.name) # Save the uploaded file with open(file_path, "wb") as f: f.write(file.read()) # Generate a shareable link base_url = "https://coollsd-test.hf.space" relative_path = file_path.replace("/tmp", "") share_link = f"{base_url}/file={relative_path}" return share_link with gr.Blocks() as demo: file_input = gr.File(label="Upload File") output = gr.Textbox(label="Share Link") upload_btn = gr.Button("Upload and Share") upload_btn.click(fn=upload_and_share, inputs=file_input, outputs=output) if __name__ == "__main__": demo.launch(share=True)