lang03383 commited on
Commit
a69be1f
·
verified ·
1 Parent(s): 8f3c75b

Upload special/dl_display_results.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. special/dl_display_results.py +93 -0
special/dl_display_results.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ##~ Display Download Results Widgets | by: ANXETY ~##
2
+
3
+ from directory_setup import *
4
+
5
+ import re
6
+ import os
7
+ import json
8
+ import time
9
+ import ipywidgets as widgets
10
+ from ipywidgets import widgets, Layout, Label, Button, VBox, HBox
11
+ from IPython.display import display, HTML, Javascript, clear_output
12
+
13
+
14
+ # Setup Env
15
+ env = os.getenv('ENV_NAME')
16
+ root_path = os.getenv('ROOT_PATH')
17
+ webui_path = os.getenv('WEBUI_PATH')
18
+ free_plan = os.getenv('FREE_PLAN')
19
+
20
+
21
+ # ==================== CSS ====================
22
+ # Main CSS
23
+ css_file_path = f"{root_path}/CSS/dl_display_result.css"
24
+ with open(css_file_path , "r") as f:
25
+ CSS = f.read()
26
+ display(HTML(f"<style>{CSS}</style>"))
27
+
28
+
29
+ # ==================== WIDGETS ====================
30
+ # Constants
31
+ HR = widgets.HTML('<hr>')
32
+ HEADER_DL = 'DOWNLOAD RESULTS'
33
+ VERSION = 'v0.33'
34
+
35
+ ## Functions
36
+ def output_container_generator(header, items):
37
+ header_widget = widgets.HTML(value=f'<div class="header_outputs_dl">{header} ➤</div>')
38
+ content_widgets = [widgets.HTML(value=f'<div class="items_dl">{item}</div>') for item in items]
39
+ container_widget = widgets.VBox([header_widget, *content_widgets]).add_class("outputs_dl")
40
+ return container_widget
41
+
42
+ def get_files_list(directory, extensions):
43
+ return [file for file in os.listdir(directory) if file.endswith(extensions)]
44
+
45
+ def get_folders_list(directory):
46
+ return [folder for folder in os.listdir(extensions_dir) if os.path.isdir(os.path.join(extensions_dir, folder))]
47
+
48
+ def get_controlnets_list(directory, filter_pattern):
49
+ filter_name = re.compile(filter_pattern)
50
+ return [
51
+ filter_name.match(file).group(1) if filter_name.match(file) else file
52
+ for file in os.listdir(directory)
53
+ if not file.endswith(('.txt', '.yaml'))
54
+ ]
55
+
56
+ ## Widgets
57
+ header_widget = widgets.HTML(value=f'''
58
+ <div><span class="header_dl">{HEADER_DL}</span> <span style="color: grey; opacity: 0.25;">| {VERSION}</span></div>
59
+ ''')
60
+
61
+ # Models
62
+ models_list = get_files_list(models_dir, ('.safetensors', '.ckpt'))
63
+ models_widget = output_container_generator('Models', models_list)
64
+ # Vaes
65
+ vaes_list = get_files_list(vaes_dir, '.safetensors')
66
+ vaes_widget = output_container_generator('VAEs', vaes_list)
67
+ # Embeddings
68
+ embeddings_list = get_files_list(embeddings_dir, ('.safetensors', '.pt'))
69
+ embeddings_widget = output_container_generator('Embeddings', embeddings_list)
70
+ # LoRAs
71
+ loras_list = get_files_list(loras_dir, '.safetensors')
72
+ loras_widget = output_container_generator('LoRAs', loras_list)
73
+ # Extensions
74
+ extensions_list = get_folders_list(extensions_dir)
75
+ extensions_widget = output_container_generator('Extensions', extensions_list).add_class("extension") # for fix height
76
+ # ControlNet
77
+ controlnets_list = get_controlnets_list(control_dir, r'^[^_]*_[^_]*_[^_]*_(.*)_fp16\.safetensors')
78
+ controlnets_widget = output_container_generator('ControlNets', controlnets_list)
79
+
80
+ ## Sorting and Output
81
+ widgets_dict = {
82
+ models_widget: models_list,
83
+ vaes_widget: vaes_list,
84
+ embeddings_widget: embeddings_list,
85
+ loras_widget: loras_list,
86
+ extensions_widget: extensions_list,
87
+ controlnets_widget: controlnets_list
88
+ }
89
+ outputs_widgets_list = [widget for widget, widget_list in widgets_dict.items() if widget_list]
90
+ result_output_widget = widgets.HBox(outputs_widgets_list).add_class("result_output_dl")
91
+
92
+ container_widget = widgets.VBox([header_widget, HR, result_output_widget, HR]).add_class("container_dl")
93
+ display(container_widget)