File size: 885 Bytes
3bf0273 6cf5ede 3bf0273 |
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 |
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) |