File size: 832 Bytes
f29b7af
 
 
 
 
 
 
 
 
51a527c
 
 
f29b7af
 
51a527c
 
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
25
26
27
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 "Please upload a file."

    # file.name is the uploaded filename
    # file is a NamedString -> use file to read content directly
    file_path = os.path.join(UPLOAD_DIR, file.name)
    with open(file_path, "wb") as f:
        f.write(file)  # just write the bytes

    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()