File size: 719 Bytes
f29b7af
 
 
 
 
 
db93248
f29b7af
 
bd7eee1
51a527c
db93248
 
f29b7af
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr
import os

UPLOAD_DIR = "uploads"
os.makedirs(UPLOAD_DIR, exist_ok=True)


def save_file(file):
    if file is None:
        return "❌ No file received."

    dest_path = os.path.join(UPLOAD_DIR, file.name)
    shutil.copy(file.path, dest_path)  # file.path is the temp file on disk
    return f"✅ File `{file.name}` uploaded successfully!"

with gr.Blocks() as demo:
    gr.Markdown("## 🖼️ Anonymous Image Upload\nDrop an image file below. No login required.")
    with gr.Row():
        uploader = gr.File(label="Upload Image", file_types=[".png", ".jpg", ".jpeg"])
    output = gr.Textbox(label="Status")
    uploader.change(fn=save_file, inputs=uploader, outputs=output)

demo.launch()