deepsync commited on
Commit
59c6335
1 Parent(s): 64f007a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -1
app.py CHANGED
@@ -8,6 +8,35 @@ import gradio as gr
8
  import google.auth
9
  from google.auth.transport.requests import Request
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  def get_google_token():
12
  credentials, project = google.auth.load_credentials_from_dict(
13
  json.loads(os.environ.get('GCP_FINETUNE_KEY')),
@@ -62,7 +91,9 @@ def clean_hindi_transliterated_text(text):
62
  text = text.replace('`', '').replace("output:", "")
63
  for o, n in updates:
64
  text = text.replace(o, n)
65
- return text.strip().strip("'").strip('"')
 
 
66
 
67
 
68
  def dubpro_english_transliteration(text, call_gpt):
 
8
  import google.auth
9
  from google.auth.transport.requests import Request
10
 
11
+
12
+ def update_text_from_dictionary(text, dictionary_path="./en_hi.dict", initial_lookup=True):
13
+ if not dictionary_path:
14
+ return texts
15
+
16
+ with open(dictionary_path) as f:
17
+ lines = f.read().splitlines()
18
+
19
+ updated_lines = list(map(lambda x: x.split("|"), lines))
20
+
21
+ initial_pass_dict = {}
22
+ final_pass_dict = {}
23
+ for initial, incorrect, correct in updated_lines:
24
+ initial_pass_dict[initial] = correct
25
+ initial_pass_dict[initial+"."] = correct+"."
26
+ initial_pass_dict[initial+"?"] = correct+"?"
27
+ initial_pass_dict[initial+","] = correct+","
28
+ final_pass_dict[incorrect] = correct
29
+ final_pass_dict[incorrect+"."] = correct+"."
30
+ final_pass_dict[incorrect+"?"] = correct+"?"
31
+ final_pass_dict[incorrect+","] = correct+","
32
+
33
+ replacable_dict = initial_pass_dict if initial_lookup else final_pass_dict
34
+ print(f"Original [{initial_lookup}]: ", text)
35
+ new_text = " ".join([replacable_dict.get(t, t) for t in text.split()])
36
+ print(f"New [{initial_lookup}]: ", text)
37
+ return new_text
38
+
39
+
40
  def get_google_token():
41
  credentials, project = google.auth.load_credentials_from_dict(
42
  json.loads(os.environ.get('GCP_FINETUNE_KEY')),
 
91
  text = text.replace('`', '').replace("output:", "")
92
  for o, n in updates:
93
  text = text.replace(o, n)
94
+ final_text = text.strip().strip("'").strip('"')
95
+ result_text = update_text_from_dictionary(final_text)
96
+ return result_text
97
 
98
 
99
  def dubpro_english_transliteration(text, call_gpt):