Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import os
|
| 3 |
-
import shutil
|
| 4 |
|
| 5 |
-
UPLOAD_DIR = "uploads"
|
| 6 |
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
if file is None:
|
| 11 |
return "❌ No file received."
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
with gr.Blocks() as demo:
|
| 18 |
-
gr.Markdown("## 🖼️ Anonymous
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import os, shutil
|
|
|
|
| 3 |
|
| 4 |
+
UPLOAD_DIR = "uploads" # permanent storage
|
| 5 |
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
| 6 |
|
| 7 |
+
def save_file(temp_path: str): # temp_path is *already* a str
|
| 8 |
+
if not temp_path:
|
|
|
|
| 9 |
return "❌ No file received."
|
| 10 |
|
| 11 |
+
filename = os.path.basename(temp_path)
|
| 12 |
+
dest_path = os.path.join(UPLOAD_DIR, filename)
|
| 13 |
+
shutil.copy(temp_path, dest_path) # copy from tmp → uploads/
|
| 14 |
+
return f"✅ `{filename}` saved!"
|
| 15 |
|
| 16 |
with gr.Blocks() as demo:
|
| 17 |
+
gr.Markdown("## 🖼️ Anonymous image upload (no login required)")
|
| 18 |
+
uploader = gr.File(
|
| 19 |
+
label="Upload image",
|
| 20 |
+
file_types=["image"], # or [".png", ".jpg", ".jpeg"]
|
| 21 |
+
type="filepath" # <‑‑ CRUCIAL
|
| 22 |
+
)
|
| 23 |
+
status = gr.Textbox(label="Status")
|
| 24 |
+
uploader.upload(save_file, uploader, status) # use .upload for clarity
|
| 25 |
|
| 26 |
+
demo.queue().launch()
|