fixed issue regarding persistent storage privacy issues
Browse files- README.md +2 -0
- handlers/json_handler.py +1 -1
- modules/common/file_ensurer.py +26 -0
- webgui.py +6 -33
README.md
CHANGED
@@ -36,6 +36,8 @@ Preprocessor is sourced from an external package, which I also designed, called
|
|
36 |
|
37 |
Kudasai has a public trello board, you can find it [here](https://trello.com/b/Wsuwr24S/kudasai) to see what I'm working on.
|
38 |
|
|
|
|
|
39 |
---------------------------------------------------------------------------------------------------------------------------------------------------
|
40 |
**Naming Conventions**<a name="naming-conventions"></a>
|
41 |
|
|
|
36 |
|
37 |
Kudasai has a public trello board, you can find it [here](https://trello.com/b/Wsuwr24S/kudasai) to see what I'm working on.
|
38 |
|
39 |
+
To prevent privacy issues, Kudasai will manually clear all persistent files it uses upon boot when on Hugging Face's servers. This means that you'll have to reupload any files/api keys you want to use every time you use, reload, or refresh the page. This is not the case for local versions of Kudasai.
|
40 |
+
|
41 |
---------------------------------------------------------------------------------------------------------------------------------------------------
|
42 |
**Naming Conventions**<a name="naming-conventions"></a>
|
43 |
|
handlers/json_handler.py
CHANGED
@@ -398,7 +398,7 @@ gemini_stream, gemini_stop_sequences and gemini_candidate_count are included for
|
|
398 |
|
399 |
elif(setting_info["type"] == int) or (setting_info["type"] == float):
|
400 |
|
401 |
-
if(value is None or value
|
402 |
converted_value = None
|
403 |
|
404 |
elif(setting_info["type"] == int):
|
|
|
398 |
|
399 |
elif(setting_info["type"] == int) or (setting_info["type"] == float):
|
400 |
|
401 |
+
if(value is None or value == ''):
|
402 |
converted_value = None
|
403 |
|
404 |
elif(setting_info["type"] == int):
|
modules/common/file_ensurer.py
CHANGED
@@ -187,6 +187,9 @@ class FileEnsurer():
|
|
187 |
|
188 |
"""
|
189 |
|
|
|
|
|
|
|
190 |
## creates the output directory and config directory if they don't exist
|
191 |
FileEnsurer.standard_create_directory(FileEnsurer.config_dir)
|
192 |
FileEnsurer.standard_create_directory(FileEnsurer.output_dir)
|
@@ -207,6 +210,29 @@ class FileEnsurer():
|
|
207 |
with open(FileEnsurer.config_kijiku_rules_path, 'w+', encoding='utf-8') as file:
|
208 |
json.dump(FileEnsurer.DEFAULT_KIJIKU_RULES, file)
|
209 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
##--------------------start-of-standard_create_directory()------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
211 |
|
212 |
@staticmethod
|
|
|
187 |
|
188 |
"""
|
189 |
|
190 |
+
if(FileEnsurer.check_if_hugging_space()):
|
191 |
+
FileEnsurer.purge_storage()
|
192 |
+
|
193 |
## creates the output directory and config directory if they don't exist
|
194 |
FileEnsurer.standard_create_directory(FileEnsurer.config_dir)
|
195 |
FileEnsurer.standard_create_directory(FileEnsurer.output_dir)
|
|
|
210 |
with open(FileEnsurer.config_kijiku_rules_path, 'w+', encoding='utf-8') as file:
|
211 |
json.dump(FileEnsurer.DEFAULT_KIJIKU_RULES, file)
|
212 |
|
213 |
+
##-------------------start-of-purge_storage()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
214 |
+
|
215 |
+
@staticmethod
|
216 |
+
@permission_error_decorator()
|
217 |
+
def purge_storage() -> None:
|
218 |
+
|
219 |
+
"""
|
220 |
+
|
221 |
+
In case of hugging face, purges the storage.
|
222 |
+
|
223 |
+
"""
|
224 |
+
|
225 |
+
stuff_to_purge = [
|
226 |
+
FileEnsurer.output_dir,
|
227 |
+
FileEnsurer.archive_dir,
|
228 |
+
FileEnsurer.secrets_dir,
|
229 |
+
FileEnsurer.config_dir
|
230 |
+
]
|
231 |
+
|
232 |
+
for thing in stuff_to_purge:
|
233 |
+
if(os.path.exists(thing)):
|
234 |
+
os.remove(thing)
|
235 |
+
|
236 |
##--------------------start-of-standard_create_directory()------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
237 |
|
238 |
@staticmethod
|
webgui.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
## built-in libraries
|
2 |
import typing
|
3 |
import base64
|
4 |
-
import os
|
5 |
|
6 |
## third-party libraries
|
7 |
import gradio as gr
|
@@ -104,9 +103,6 @@ class KudasaiGUI:
|
|
104 |
"""
|
105 |
|
106 |
try:
|
107 |
-
|
108 |
-
assert FileEnsurer.check_if_hugging_space() == False
|
109 |
-
|
110 |
## Api key is encoded in base 64 so we need to decode it before returning
|
111 |
return base64.b64decode(FileEnsurer.standard_read_file(FileEnsurer.deepl_api_key_path).encode('utf-8')).decode('utf-8')
|
112 |
|
@@ -127,9 +123,6 @@ class KudasaiGUI:
|
|
127 |
"""
|
128 |
|
129 |
try:
|
130 |
-
|
131 |
-
assert FileEnsurer.check_if_hugging_space() == False
|
132 |
-
|
133 |
## Api key is encoded in base 64 so we need to decode it before returning
|
134 |
return base64.b64decode(FileEnsurer.standard_read_file(FileEnsurer.openai_api_key_path).encode('utf-8')).decode('utf-8')
|
135 |
|
@@ -150,9 +143,6 @@ class KudasaiGUI:
|
|
150 |
"""
|
151 |
|
152 |
try:
|
153 |
-
|
154 |
-
assert FileEnsurer.check_if_hugging_space() == False
|
155 |
-
|
156 |
## Api key is encoded in base 64 so we need to decode it before returning
|
157 |
return base64.b64decode(FileEnsurer.standard_read_file(FileEnsurer.gemini_api_key_path).encode('utf-8')).decode('utf-8')
|
158 |
|
@@ -204,9 +194,6 @@ class KudasaiGUI:
|
|
204 |
|
205 |
"""
|
206 |
|
207 |
-
if(FileEnsurer.check_if_hugging_space() == True):
|
208 |
-
return
|
209 |
-
|
210 |
## also gonna want to update the api key file with the new api key
|
211 |
if(Kijiku.LLM_TYPE == "openai"):
|
212 |
path_to_api_key = FileEnsurer.openai_api_key_path
|
@@ -396,7 +383,7 @@ class KudasaiGUI:
|
|
396 |
with gr.Column():
|
397 |
self.input_txt_file_kijiku = gr.File(label='TXT file with Japanese Text', file_count='single', file_types=['.txt'], type='filepath', interactive=True)
|
398 |
self.input_text_kijiku = gr.Textbox(label='Japanese Text', placeholder='Use this or the text file input, if you provide both, Kudasai will use the file input.', lines=10, show_label=True, interactive=True, type='text')
|
399 |
-
self.input_kijiku_rules_file = gr.File(value = FileEnsurer.config_kijiku_rules_path
|
400 |
|
401 |
with gr.Row():
|
402 |
self.llm_option_dropdown = gr.Dropdown(label='LLM Option', choices=["OpenAI", "Gemini"], value="OpenAI", show_label=True, interactive=True)
|
@@ -806,9 +793,6 @@ class KudasaiGUI:
|
|
806 |
|
807 |
indexed_text = Kudasai.mark_indexed_names(text_to_index, unique_names)
|
808 |
|
809 |
-
if(FileEnsurer.check_if_hugging_space == True):
|
810 |
-
os.remove(FileEnsurer.output_dir)
|
811 |
-
|
812 |
return indexed_text, indexing_log, log_text, log_text, error_log
|
813 |
|
814 |
else:
|
@@ -870,9 +854,6 @@ class KudasaiGUI:
|
|
870 |
|
871 |
log_text = FileEnsurer.standard_read_file(Logger.log_file_path)
|
872 |
|
873 |
-
if(FileEnsurer.check_if_hugging_space == True):
|
874 |
-
os.remove(FileEnsurer.output_dir)
|
875 |
-
|
876 |
return preprocessed_text, preprocessing_log, log_text, log_text, error_log
|
877 |
|
878 |
else:
|
@@ -949,12 +930,8 @@ class KudasaiGUI:
|
|
949 |
|
950 |
error_text = FileEnsurer.standard_read_file(FileEnsurer.error_log_path)
|
951 |
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
else:
|
956 |
-
## also gonna want to update the api key file with the new api key
|
957 |
-
FileEnsurer.standard_overwrite_file(FileEnsurer.deepl_api_key_path, base64.b64encode(str(api_key_input).encode('utf-8')).decode('utf-8'), omit=True)
|
958 |
|
959 |
return translated_text, je_check_text, log_text, error_text
|
960 |
|
@@ -1036,9 +1013,6 @@ class KudasaiGUI:
|
|
1036 |
log_text = FileEnsurer.standard_read_file(Logger.log_file_path)
|
1037 |
|
1038 |
error_text = FileEnsurer.standard_read_file(FileEnsurer.error_log_path)
|
1039 |
-
|
1040 |
-
if(FileEnsurer.check_if_hugging_space == True):
|
1041 |
-
os.remove(FileEnsurer.output_dir)
|
1042 |
|
1043 |
## then overwrite the api key file with the new api key
|
1044 |
update_kijiku_api_key(api_key)
|
@@ -1115,9 +1089,6 @@ class KudasaiGUI:
|
|
1115 |
|
1116 |
gr.Info(cost_estimation)
|
1117 |
|
1118 |
-
if(FileEnsurer.check_if_hugging_space == True):
|
1119 |
-
os.remove(FileEnsurer.output_dir)
|
1120 |
-
|
1121 |
update_kijiku_api_key(api_key)
|
1122 |
|
1123 |
return cost_estimation
|
@@ -1679,6 +1650,8 @@ class KudasaiGUI:
|
|
1679 |
|
1680 |
self.gui.load(webgui_update_check)
|
1681 |
|
|
|
|
|
1682 |
##-------------------start-of-index()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
1683 |
|
1684 |
self.indexing_run_button.click(index,
|
@@ -2218,4 +2191,4 @@ if(__name__ == '__main__'):
|
|
2218 |
|
2219 |
except Exception as e:
|
2220 |
|
2221 |
-
FileEnsurer.handle_critical_exception(e)
|
|
|
1 |
## built-in libraries
|
2 |
import typing
|
3 |
import base64
|
|
|
4 |
|
5 |
## third-party libraries
|
6 |
import gradio as gr
|
|
|
103 |
"""
|
104 |
|
105 |
try:
|
|
|
|
|
|
|
106 |
## Api key is encoded in base 64 so we need to decode it before returning
|
107 |
return base64.b64decode(FileEnsurer.standard_read_file(FileEnsurer.deepl_api_key_path).encode('utf-8')).decode('utf-8')
|
108 |
|
|
|
123 |
"""
|
124 |
|
125 |
try:
|
|
|
|
|
|
|
126 |
## Api key is encoded in base 64 so we need to decode it before returning
|
127 |
return base64.b64decode(FileEnsurer.standard_read_file(FileEnsurer.openai_api_key_path).encode('utf-8')).decode('utf-8')
|
128 |
|
|
|
143 |
"""
|
144 |
|
145 |
try:
|
|
|
|
|
|
|
146 |
## Api key is encoded in base 64 so we need to decode it before returning
|
147 |
return base64.b64decode(FileEnsurer.standard_read_file(FileEnsurer.gemini_api_key_path).encode('utf-8')).decode('utf-8')
|
148 |
|
|
|
194 |
|
195 |
"""
|
196 |
|
|
|
|
|
|
|
197 |
## also gonna want to update the api key file with the new api key
|
198 |
if(Kijiku.LLM_TYPE == "openai"):
|
199 |
path_to_api_key = FileEnsurer.openai_api_key_path
|
|
|
383 |
with gr.Column():
|
384 |
self.input_txt_file_kijiku = gr.File(label='TXT file with Japanese Text', file_count='single', file_types=['.txt'], type='filepath', interactive=True)
|
385 |
self.input_text_kijiku = gr.Textbox(label='Japanese Text', placeholder='Use this or the text file input, if you provide both, Kudasai will use the file input.', lines=10, show_label=True, interactive=True, type='text')
|
386 |
+
self.input_kijiku_rules_file = gr.File(value = FileEnsurer.config_kijiku_rules_path, label='Kijiku Rules File', file_count='single', file_types=['.json'], type='filepath')
|
387 |
|
388 |
with gr.Row():
|
389 |
self.llm_option_dropdown = gr.Dropdown(label='LLM Option', choices=["OpenAI", "Gemini"], value="OpenAI", show_label=True, interactive=True)
|
|
|
793 |
|
794 |
indexed_text = Kudasai.mark_indexed_names(text_to_index, unique_names)
|
795 |
|
|
|
|
|
|
|
796 |
return indexed_text, indexing_log, log_text, log_text, error_log
|
797 |
|
798 |
else:
|
|
|
854 |
|
855 |
log_text = FileEnsurer.standard_read_file(Logger.log_file_path)
|
856 |
|
|
|
|
|
|
|
857 |
return preprocessed_text, preprocessing_log, log_text, log_text, error_log
|
858 |
|
859 |
else:
|
|
|
930 |
|
931 |
error_text = FileEnsurer.standard_read_file(FileEnsurer.error_log_path)
|
932 |
|
933 |
+
## also gonna want to update the api key file with the new api key
|
934 |
+
FileEnsurer.standard_overwrite_file(FileEnsurer.deepl_api_key_path, base64.b64encode(str(api_key_input).encode('utf-8')).decode('utf-8'), omit=True)
|
|
|
|
|
|
|
|
|
935 |
|
936 |
return translated_text, je_check_text, log_text, error_text
|
937 |
|
|
|
1013 |
log_text = FileEnsurer.standard_read_file(Logger.log_file_path)
|
1014 |
|
1015 |
error_text = FileEnsurer.standard_read_file(FileEnsurer.error_log_path)
|
|
|
|
|
|
|
1016 |
|
1017 |
## then overwrite the api key file with the new api key
|
1018 |
update_kijiku_api_key(api_key)
|
|
|
1089 |
|
1090 |
gr.Info(cost_estimation)
|
1091 |
|
|
|
|
|
|
|
1092 |
update_kijiku_api_key(api_key)
|
1093 |
|
1094 |
return cost_estimation
|
|
|
1650 |
|
1651 |
self.gui.load(webgui_update_check)
|
1652 |
|
1653 |
+
self.gui.load(FileEnsurer.purge_storage)
|
1654 |
+
|
1655 |
##-------------------start-of-index()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
1656 |
|
1657 |
self.indexing_run_button.click(index,
|
|
|
2191 |
|
2192 |
except Exception as e:
|
2193 |
|
2194 |
+
FileEnsurer.handle_critical_exception(e)
|