Skip to content

Instantly share code, notes, and snippets.

@kargaranamir
Last active June 5, 2025 13:38
Show Gist options
  • Save kargaranamir/d50ba4d925c3593781db13386a5ae6d4 to your computer and use it in GitHub Desktop.
Save kargaranamir/d50ba4d925c3593781db13386a5ae6d4 to your computer and use it in GitHub Desktop.
simple share files with gradio
# Create a `static` folder and put everything you want there to share.
import os
import gradio as gr
path = "static/"
gr.set_static_paths(paths=[path])
def list_files():
files = os.listdir(path)
file_links = []
for file in files:
file_path = os.path.join(path, file)
if os.path.isfile(file_path):
file_path = file_path.replace('static', 'file=static')
file_links.append(f'<a href="{file_path}" download>{file}</a>')
if not file_links:
return "No files found in the specified path."
return "<br>".join(file_links)
iface = gr.Interface(
fn=list_files,
inputs=None, # No inputs required
outputs="html",
title="File Downloader",
description=f"Files in the directory: {path}. Click on a file to download it."
)
iface.launch(share=False, server_name="0.0.0.0", show_api=False, server_port=7778, inline=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment