Spaces:
Sleeping
Sleeping
Update app.py
#7
by
Duskfallcrew
- opened
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)
|