oceansweep commited on
Commit
6ed8460
1 Parent(s): c9938b2

Upload Config_tab.py

Browse files
App_Function_Libraries/Gradio_UI/Config_tab.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import configparser
3
+
4
+ # FIXME
5
+ CONFIG_PATH = './Config_Files/config.txt'
6
+
7
+ def load_config():
8
+ config = configparser.ConfigParser()
9
+ config.read(CONFIG_PATH)
10
+ return config
11
+
12
+ def save_config(config):
13
+ with open(CONFIG_PATH, 'w') as configfile:
14
+ config.write(configfile)
15
+
16
+ def get_config_as_text():
17
+ with open(CONFIG_PATH, 'r') as file:
18
+ content = file.read()
19
+ return content, "Config refreshed successfully"
20
+
21
+ def save_config_from_text(text):
22
+ with open(CONFIG_PATH, 'w') as file:
23
+ file.write(text)
24
+ return "Config saved successfully"
25
+
26
+
27
+ def create_config_editor_tab():
28
+ with gr.TabItem("Edit Config"):
29
+ gr.Markdown("# Edit Configuration File")
30
+
31
+ with gr.Row():
32
+ with gr.Column():
33
+ refresh_button = gr.Button("Refresh Config")
34
+
35
+ with gr.Column():
36
+ config_text = gr.TextArea(label="Full Config", lines=30)
37
+ save_text_button = gr.Button("Save Config")
38
+
39
+ with gr.Row():
40
+ output = gr.Textbox(label="Output")
41
+
42
+ # Event handlers
43
+ refresh_button.click(get_config_as_text, inputs=[], outputs=[config_text, output])
44
+
45
+ config_text.change(lambda: None, None, None) # Dummy handler to enable changes
46
+ save_text_button.click(save_config_from_text, inputs=[config_text], outputs=[output])
47
+
48
+ # Initialize the interface
49
+ config_text.value = get_config_as_text()[0] # Only set the config text, not the output message
50
+
51
+ return refresh_button, config_text, save_text_button, output