Shekarss commited on
Commit
e35fe0b
·
verified ·
1 Parent(s): b1dd331

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -0
app.py CHANGED
@@ -33,6 +33,16 @@ def show_gallery():
33
  files = sorted(IMAGE_DIR.iterdir(), key=os.path.getmtime, reverse=True)
34
  return [str(f) for f in files]
35
 
 
 
 
 
 
 
 
 
 
 
36
  def upload_via_ui(image_from_ui):
37
  """
38
  Handles image uploads directly from the Gradio UI interface.
@@ -104,6 +114,9 @@ with gr.Blocks(title="Shekar's Portfolio Gallery") as demo:
104
  outputs=gallery
105
  )
106
 
 
 
 
107
  # --- Hidden components to create the API endpoints ---
108
  with gr.Row(visible=False):
109
  # Textbox to receive the base64 data URL from the JS client
@@ -117,6 +130,8 @@ with gr.Blocks(title="Shekar's Portfolio Gallery") as demo:
117
  outputs=gallery,
118
  api_name="upload_via_data_url"
119
  )
 
 
120
 
121
  # Load and refresh the gallery when the app starts.
122
  # This also creates the /show_gallery endpoint for the JS client.
 
33
  files = sorted(IMAGE_DIR.iterdir(), key=os.path.getmtime, reverse=True)
34
  return [str(f) for f in files]
35
 
36
+ def clear_gallery():
37
+ """Deletes all files in the image directory."""
38
+ if IMAGE_DIR.exists():
39
+ for file_path in IMAGE_DIR.iterdir():
40
+ if file_path.is_file():
41
+ file_path.unlink() # Deletes the file
42
+ print("Gallery cleared successfully.")
43
+ # Return an empty list to update the gallery UI
44
+ return []
45
+
46
  def upload_via_ui(image_from_ui):
47
  """
48
  Handles image uploads directly from the Gradio UI interface.
 
114
  outputs=gallery
115
  )
116
 
117
+ with gr.Accordion("Admin Controls", open=False):
118
+ clear_btn = gr.Button("⚠️ Clear All Gallery Images")
119
+
120
  # --- Hidden components to create the API endpoints ---
121
  with gr.Row(visible=False):
122
  # Textbox to receive the base64 data URL from the JS client
 
130
  outputs=gallery,
131
  api_name="upload_via_data_url"
132
  )
133
+
134
+ clear_btn.click(fn=clear_gallery, inputs=None, outputs=gallery)
135
 
136
  # Load and refresh the gallery when the app starts.
137
  # This also creates the /show_gallery endpoint for the JS client.