| import gradio as gr |
| import requests |
| from huggingface_hub import HfFileSystem |
|
|
| def download_to_bucket(url, bucket_path): |
| |
| fs = HfFileSystem() |
| |
| try: |
| |
| with requests.get(url, stream=True) as response: |
| response.raise_for_status() |
| |
| |
| with fs.open(bucket_path, "wb") as f: |
| |
| for chunk in response.iter_content(chunk_size=8 * 1024 * 1024): |
| if chunk: |
| f.write(chunk) |
| |
| return f"β
Successfully streamed into {bucket_path}" |
| |
| except Exception as e: |
| return f"β Error: {str(e)}" |
|
|
| |
| with gr.Blocks() as demo: |
| gr.Markdown("# π Stream URL directly to Hugging Face Bucket") |
| gr.Markdown("This tool streams files directly into an S3-like HF Storage Bucket without filling up this Space's disk.") |
| |
| with gr.Row(): |
| url_input = gr.Textbox( |
| label="Source URL", |
| placeholder="https://example.com/huge-dataset.zip" |
| ) |
| path_input = gr.Textbox( |
| label="Destination Path", |
| placeholder="hf://buckets/vish85521/videos" |
| ) |
| |
| download_btn = gr.Button("Download to Bucket", variant="primary") |
| output_text = gr.Textbox(label="Status") |
| |
| download_btn.click( |
| fn=download_to_bucket, |
| inputs=[url_input, path_input], |
| outputs=output_text |
| ) |
|
|
| demo.launch() |