ruilongli's picture
Update app.py
18a61d5 verified
raw
history blame
893 Bytes
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()