30 lines
		
	
	
		
			897 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
		
			897 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| import datetime
 | |
| import random
 | |
| import os
 | |
| 
 | |
| 
 | |
| def remove_empty_str(items, default=None):
 | |
|     items = [x for x in items if x != ""]
 | |
|     if len(items) == 0 and default is not None:
 | |
|         return [default]
 | |
|     return items
 | |
| 
 | |
| 
 | |
| def join_prompts(*args, **kwargs):
 | |
|     prompts = [str(x) for x in args if str(x) != ""]
 | |
|     if len(prompts) == 0:
 | |
|         return ""
 | |
|     if len(prompts) == 1:
 | |
|         return prompts[0]
 | |
|     return ', '.join(prompts)
 | |
| 
 | |
| 
 | |
| def generate_temp_filename(folder='./outputs/', extension='png'):
 | |
|     current_time = datetime.datetime.now()
 | |
|     date_string = current_time.strftime("%Y-%m-%d")
 | |
|     time_string = current_time.strftime("%Y-%m-%d_%H-%M-%S")
 | |
|     random_number = random.randint(1000, 9999)
 | |
|     filename = f"{time_string}_{random_number}.{extension}"
 | |
|     result = os.path.join(folder, date_string, filename)
 | |
|     return date_string, os.path.abspath(os.path.realpath(result)), filename
 |