File size: 893 Bytes
f29b7af
18a61d5
f29b7af
18a61d5
f29b7af
 
18a61d5
 
bd7eee1
51a527c
18a61d5
 
 
 
f29b7af
 
18a61d5
 
 
 
 
 
 
 
f29b7af
18a61d5
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
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()