Bikatr7 commited on
Commit
3847404
1 Parent(s): da09a1f

hopefully fixed google translate bug

Browse files
Files changed (2) hide show
  1. modules/common/file_ensurer.py +5 -1
  2. webgui.py +18 -4
modules/common/file_ensurer.py CHANGED
@@ -64,6 +64,9 @@ class FileEnsurer():
64
  openai_api_key_path = os.path.join(secrets_dir,'openai_api_key.txt')
65
  gemini_api_key_path = os.path.join(secrets_dir,'gemini_api_key.txt')
66
  google_translate_service_key_json_path = os.path.join(secrets_dir, "google_translate_service_key.json")
 
 
 
67
 
68
  ## favicon
69
  favicon_path = os.path.join(gui_lib, "Kudasai_Logo.png")
@@ -221,7 +224,8 @@ class FileEnsurer():
221
  stuff_to_purge = [
222
  FileEnsurer.secrets_dir,
223
  FileEnsurer.config_dir,
224
- FileEnsurer.archive_dir
 
225
  ]
226
 
227
  stuff_to_truncate = [
 
64
  openai_api_key_path = os.path.join(secrets_dir,'openai_api_key.txt')
65
  gemini_api_key_path = os.path.join(secrets_dir,'gemini_api_key.txt')
66
  google_translate_service_key_json_path = os.path.join(secrets_dir, "google_translate_service_key.json")
67
+
68
+ ## temp files
69
+ temp_file_path = os.path.join(script_dir, "temp.txt")
70
 
71
  ## favicon
72
  favicon_path = os.path.join(gui_lib, "Kudasai_Logo.png")
 
224
  stuff_to_purge = [
225
  FileEnsurer.secrets_dir,
226
  FileEnsurer.config_dir,
227
+ FileEnsurer.archive_dir,
228
+ FileEnsurer.temp_file_path
229
  ]
230
 
231
  stuff_to_truncate = [
webgui.py CHANGED
@@ -2,6 +2,7 @@
2
  import typing
3
  import base64
4
  import asyncio
 
5
 
6
  ## third-party libraries
7
  import gradio as gr
@@ -137,6 +138,9 @@ class KudasaiGUI:
137
 
138
  """
139
 
 
 
 
140
  service_to_path = {
141
  "openai": FileEnsurer.openai_api_key_path,
142
  "gemini": FileEnsurer.gemini_api_key_path,
@@ -169,10 +173,14 @@ class KudasaiGUI:
169
 
170
  """
171
 
 
 
 
 
172
  if(Translator.TRANSLATION_METHOD == "google translate"):
173
- FileEnsurer.standard_overwrite_file(FileEnsurer.google_translate_service_key_json_path, str(api_key), omit=True)
174
- await asyncio.sleep(2)
175
- api_key = FileEnsurer.google_translate_service_key_json_path
176
 
177
  try:
178
 
@@ -186,6 +194,13 @@ class KudasaiGUI:
186
  except:
187
  raise gr.Error("Invalid API key")
188
 
 
 
 
 
 
 
 
189
  ##-------------------start-of-update_translator_api_key()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
190
 
191
  def update_translator_api_key(api_key) -> None:
@@ -199,7 +214,6 @@ class KudasaiGUI:
199
 
200
  """
201
 
202
- ## we don't want to store api keys in hugging space
203
  if(FileEnsurer.is_hugging_space()):
204
  return
205
 
 
2
  import typing
3
  import base64
4
  import asyncio
5
+ import os
6
 
7
  ## third-party libraries
8
  import gradio as gr
 
138
 
139
  """
140
 
141
+ if(FileEnsurer.is_hugging_space()):
142
+ return ""
143
+
144
  service_to_path = {
145
  "openai": FileEnsurer.openai_api_key_path,
146
  "gemini": FileEnsurer.gemini_api_key_path,
 
173
 
174
  """
175
 
176
+ ## ik this looks really bad
177
+ ## but the set_credentials for google translate expects a filepath, and normal way isn't working
178
+ ## so we write the client secrets to a temp file, send that, then clear the file
179
+ ## even if it fails, purge_storage is set to kill that path too so we should be good.
180
  if(Translator.TRANSLATION_METHOD == "google translate"):
181
+ FileEnsurer.standard_overwrite_file(FileEnsurer.temp_file_path, str(api_key), omit=True)
182
+ await asyncio.sleep(1)
183
+ api_key = FileEnsurer.temp_file_path
184
 
185
  try:
186
 
 
194
  except:
195
  raise gr.Error("Invalid API key")
196
 
197
+ finally:
198
+ try:
199
+ os.remove(FileEnsurer.temp_file_path)
200
+
201
+ except:
202
+ pass
203
+
204
  ##-------------------start-of-update_translator_api_key()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
205
 
206
  def update_translator_api_key(api_key) -> None:
 
214
 
215
  """
216
 
 
217
  if(FileEnsurer.is_hugging_space()):
218
  return
219