throaway2854 commited on
Commit
ebe9224
·
verified ·
1 Parent(s): c80f72f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -53,14 +53,14 @@ def save_dataset_to_zip(dataset_name, dataset):
53
  zip_buffer.seek(0)
54
  return zip_buffer
55
 
56
- def load_dataset_from_zip(zip_file):
57
  temp_dir = tempfile.mkdtemp()
58
  try:
59
- with zipfile.ZipFile(zip_file.name, 'r') as zip_ref:
60
  zip_ref.extractall(temp_dir)
61
 
62
  # Get dataset name from zip file name
63
- dataset_name_guess = os.path.splitext(os.path.basename(zip_file.name))[0]
64
  dataset_path = os.path.join(temp_dir, dataset_name_guess)
65
 
66
  if os.path.exists(dataset_path):
@@ -142,7 +142,7 @@ with gr.Blocks() as demo:
142
  create_button = gr.Button("Create Dataset")
143
  with gr.Column():
144
  gr.Markdown("### Upload Existing Dataset")
145
- upload_input = gr.File(label="Upload Dataset Zip", type="file")
146
  upload_button = gr.Button("Upload Dataset")
147
 
148
  def create_dataset(name, datasets):
@@ -159,10 +159,10 @@ with gr.Blocks() as demo:
159
  outputs=[dataset_selector, message_box]
160
  )
161
 
162
- def upload_dataset(zip_file, datasets):
163
- if zip_file is None:
164
  return gr.update(), "Please upload a zip file."
165
- dataset_name, dataset = load_dataset_from_zip(zip_file)
166
  if dataset_name is None:
167
  return gr.update(), "Failed to load dataset from zip file."
168
  if dataset_name in datasets:
@@ -224,7 +224,7 @@ with gr.Blocks() as demo:
224
 
225
  with gr.Tab("Edit / Delete Entry"):
226
  with gr.Column():
227
- selected_image = gr.Image(label="Selected Image", interactive=False)
228
  selected_prompt = gr.Textbox(label="Current Prompt", interactive=False)
229
  new_prompt_input = gr.Textbox(label="New Prompt (for Edit)")
230
  with gr.Row():
 
53
  zip_buffer.seek(0)
54
  return zip_buffer
55
 
56
+ def load_dataset_from_zip(zip_file_path):
57
  temp_dir = tempfile.mkdtemp()
58
  try:
59
+ with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
60
  zip_ref.extractall(temp_dir)
61
 
62
  # Get dataset name from zip file name
63
+ dataset_name_guess = os.path.splitext(os.path.basename(zip_file_path))[0]
64
  dataset_path = os.path.join(temp_dir, dataset_name_guess)
65
 
66
  if os.path.exists(dataset_path):
 
142
  create_button = gr.Button("Create Dataset")
143
  with gr.Column():
144
  gr.Markdown("### Upload Existing Dataset")
145
+ upload_input = gr.File(label="Upload Dataset Zip", type="filepath")
146
  upload_button = gr.Button("Upload Dataset")
147
 
148
  def create_dataset(name, datasets):
 
159
  outputs=[dataset_selector, message_box]
160
  )
161
 
162
+ def upload_dataset(zip_file_path, datasets):
163
+ if not zip_file_path:
164
  return gr.update(), "Please upload a zip file."
165
+ dataset_name, dataset = load_dataset_from_zip(zip_file_path)
166
  if dataset_name is None:
167
  return gr.update(), "Failed to load dataset from zip file."
168
  if dataset_name in datasets:
 
224
 
225
  with gr.Tab("Edit / Delete Entry"):
226
  with gr.Column():
227
+ selected_image = gr.Image(label="Selected Image", interactive=False, type="numpy")
228
  selected_prompt = gr.Textbox(label="Current Prompt", interactive=False)
229
  new_prompt_input = gr.Textbox(label="New Prompt (for Edit)")
230
  with gr.Row():