|
1 | 1 | import gradio as gr
|
2 | 2 |
|
3 |
| -from modules import ui_common, shared, script_callbacks, scripts, sd_models, sysinfo, timer, shared_items |
| 3 | +from modules import ui_common, shared, script_callbacks, scripts, sd_models, sysinfo, timer, shared_items, paths_internal, util |
4 | 4 | from modules.call_queue import wrap_gradio_call_no_job
|
5 | 5 | from modules.options import options_section
|
6 | 6 | from modules.shared import opts
|
7 | 7 | from modules.ui_components import FormRow
|
8 | 8 | from modules.ui_gradio_extensions import reload_javascript
|
9 | 9 | from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 10 | +from pathlib import Path |
10 | 11 |
|
11 | 12 |
|
12 | 13 | def get_value_for_setting(key):
|
@@ -170,7 +171,28 @@ def create_ui(self, loadsave, dummy_component):
|
170 | 171 | loadsave.create_ui()
|
171 | 172 |
|
172 | 173 | with gr.TabItem("Sysinfo", id="sysinfo", elem_id="settings_tab_sysinfo"):
|
173 |
| - gr.HTML('<a href="./internal/sysinfo-download" class="sysinfo_big_link" download>Download system info</a><br /><a href="./internal/sysinfo" target="_blank">(or open as text in a new page)</a>', elem_id="sysinfo_download") |
| 174 | + download_sysinfo = gr.Button(value='Download system info', elem_id="internal-download-sysinfo", visible=False) |
| 175 | + open_sysinfo = gr.Button(value='Open as text in a new page', elem_id="internal-open-sysinfo", visible=False) |
| 176 | + sysinfo_html = gr.HTML('''<a class="sysinfo_big_link" onclick="gradioApp().getElementById('internal-download-sysinfo').click();">Download system info</a><br/><a onclick="gradioApp().getElementById('internal-open-sysinfo').click();">(or open as text in a new page)</a>''', elem_id="sysinfo_download") |
| 177 | + sysinfo_textbox = gr.Textbox(label='Sysinfo textarea', elem_id="internal-sysinfo-textbox", visible=False) |
| 178 | + |
| 179 | + def create_sysinfo(): |
| 180 | + sysinfo_str = sysinfo.get() |
| 181 | + if len(sysinfo_utf8 := sysinfo_str.encode('utf8')) > 2 ** 20: # 1MB |
| 182 | + sysinfo_path = Path(paths_internal.script_path) / 'tmp' / 'sysinfo.json' |
| 183 | + sysinfo_path.parent.mkdir(parents=True, exist_ok=True) |
| 184 | + sysinfo_path.write_bytes(sysinfo_utf8) |
| 185 | + return gr.update(), gr.update(value=f'file={util.truncate_path(sysinfo_path)}') |
| 186 | + return gr.update(), gr.update(value=sysinfo_str) |
| 187 | + |
| 188 | + download_sysinfo.click( |
| 189 | + fn=create_sysinfo, outputs=[sysinfo_html, sysinfo_textbox], show_progress=True).success( |
| 190 | + fn=None, _js='downloadSysinfo' |
| 191 | + ) |
| 192 | + open_sysinfo.click( |
| 193 | + fn=create_sysinfo, outputs=[sysinfo_html, sysinfo_textbox], show_progress=True).success( |
| 194 | + fn=None, _js='openTabSysinfo' |
| 195 | + ) |
174 | 196 |
|
175 | 197 | with gr.Row():
|
176 | 198 | with gr.Column(scale=1):
|
|
0 commit comments