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