umuth commited on
Commit
93b7b4d
·
verified ·
1 Parent(s): d5b9b5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -178,14 +178,15 @@ def save_csv(*args):
178
  })
179
  df = pd.DataFrame(data)
180
  try:
181
- # Generate timestamp
182
  timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
183
  csv_filename = f'edited_metadata_{timestamp}.csv'
184
  df.to_csv(csv_filename, index=False)
185
- return f"Data saved successfully to '{csv_filename}'!"
186
  except Exception as e:
187
  return f"Error saving data: {e}"
188
 
 
189
  # Functions to update character and keyword counts
190
  def update_title_info(text):
191
  return f"{len(text)} characters"
@@ -273,6 +274,15 @@ with gr.Blocks(css="""
273
  save_metadata_button = gr.Button("Save Metadata to Images")
274
  save_csv_button = gr.Button("Save CSV")
275
  save_output = gr.Textbox(label="Save Status", interactive=False)
 
 
 
 
 
 
 
 
 
276
 
277
  # Collect all output components for extraction and saving
278
  all_outputs = []
 
178
  })
179
  df = pd.DataFrame(data)
180
  try:
181
+ # Generate timestamped CSV filename
182
  timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
183
  csv_filename = f'edited_metadata_{timestamp}.csv'
184
  df.to_csv(csv_filename, index=False)
185
+ return csv_filename # Return CSV path for download
186
  except Exception as e:
187
  return f"Error saving data: {e}"
188
 
189
+
190
  # Functions to update character and keyword counts
191
  def update_title_info(text):
192
  return f"{len(text)} characters"
 
274
  save_metadata_button = gr.Button("Save Metadata to Images")
275
  save_csv_button = gr.Button("Save CSV")
276
  save_output = gr.Textbox(label="Save Status", interactive=False)
277
+ csv_output = gr.File(label="Download CSV") # File download component
278
+
279
+ # Update click events
280
+ save_csv_button.click(
281
+ fn=save_csv,
282
+ inputs=all_outputs,
283
+ outputs=[csv_output, save_output] # Return both the file and status
284
+ )
285
+
286
 
287
  # Collect all output components for extraction and saving
288
  all_outputs = []