Spaces:
Sleeping
Sleeping
import gradio as gr | |
import os, shutil | |
UPLOAD_DIR = "uploads" # permanent storage | |
os.makedirs(UPLOAD_DIR, exist_ok=True) | |
def save_file(temp_path: str): # temp_path is *already* a str | |
if not temp_path: | |
return "β No file received." | |
filename = os.path.basename(temp_path) | |
dest_path = os.path.join(UPLOAD_DIR, filename) | |
shutil.copy(temp_path, dest_path) # copy from tmp β uploads/ | |
return f"β `{filename}` saved!" | |
with gr.Blocks() as demo: | |
gr.Markdown("## πΌοΈ Anonymous image upload (no login required)") | |
uploader = gr.File( | |
label="Upload image", | |
file_types=["image"], # or [".png", ".jpg", ".jpeg"] | |
type="filepath" # <ββ CRUCIAL | |
) | |
status = gr.Textbox(label="Status") | |
uploader.upload(save_file, uploader, status) # use .upload for clarity | |
demo.queue().launch() |