Duskfallcrew commited on
Commit
b9bc2dd
·
verified ·
1 Parent(s): e6add39

Update app.py

Browse files

Combined Output :

def increment_filename(filename):
"""
If a file exists, add a number to the filename to make it unique.
Example: if test.txt exists, return test(1).txt
"""
if not os.path.exists(filename):
return filename

directory = os.path.dirname(filename)
name, ext = os.path.splitext(os.path.basename(filename))
counter = 1

while True:
new_name = os.path.join(directory, f"{name}({counter}){ext}")
if not os.path.exists(new_name):
return new_name
counter += 1

Files changed (1) hide show
  1. app.py +18 -0
app.py CHANGED
@@ -410,6 +410,24 @@ def main(model_to_load, save_precision_as, epoch, global_step, reference_model,
410
  # Return a combined output
411
  return f"{conversion_output}\n\n{upload_output}"
412
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
413
  with gr.Blocks() as demo:
414
 
415
  # Add initial warnings (only once)
 
410
  # Return a combined output
411
  return f"{conversion_output}\n\n{upload_output}"
412
 
413
+ def increment_filename(filename):
414
+ """
415
+ If a file exists, add a number to the filename to make it unique.
416
+ Example: if test.txt exists, return test(1).txt
417
+ """
418
+ if not os.path.exists(filename):
419
+ return filename
420
+
421
+ directory = os.path.dirname(filename)
422
+ name, ext = os.path.splitext(os.path.basename(filename))
423
+ counter = 1
424
+
425
+ while True:
426
+ new_name = os.path.join(directory, f"{name}({counter}){ext}")
427
+ if not os.path.exists(new_name):
428
+ return new_name
429
+ counter += 1
430
+
431
  with gr.Blocks() as demo:
432
 
433
  # Add initial warnings (only once)