Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,6 +19,8 @@ video_status = {
|
|
| 19 |
"Re-review Requested": "RE_REVIEW_REQUESTED"
|
| 20 |
}
|
| 21 |
|
|
|
|
|
|
|
| 22 |
ALL_LANGUAGES = ['Hindi', 'English', 'Bengali', 'Kannada', 'Spanish', 'French', 'German', 'Italian', 'Tamil', 'Telugu']
|
| 23 |
|
| 24 |
language_maps = {
|
|
@@ -44,41 +46,48 @@ language_maps = {
|
|
| 44 |
"kn": "Kannada"
|
| 45 |
}
|
| 46 |
|
| 47 |
-
REVIEW_LIST_API = "https://api.dev-env.deepsync.co/api/v1/dashboard/dubbed/videos/review/requested"
|
| 48 |
|
| 49 |
def get_translators(platform):
|
| 50 |
if platform == "dev":
|
|
|
|
| 51 |
client = pymongo.MongoClient(os.environ.get("MONGO_DEV_URI"))
|
| 52 |
source_db = client.deepsync_stage
|
| 53 |
else:
|
|
|
|
| 54 |
client = pymongo.MongoClient(os.environ.get("MONGO_URI"))
|
| 55 |
source_db = client.deepsync_prod
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
| 58 |
if len(translators):
|
| 59 |
-
desired_ids = [t["translator"] for t in translators]
|
| 60 |
companies_cursor = source_db.companies.find({'_id': {'$in': desired_ids}})
|
| 61 |
companies = {c["_id"]: c for c in companies_cursor}
|
| 62 |
for translator in translators:
|
| 63 |
try:
|
| 64 |
-
data = companies[translator["translator"]]
|
| 65 |
-
|
| 66 |
"_id": str(translator["_id"]),
|
| 67 |
"Name": data["name"],
|
| 68 |
"Email": data["email"],
|
| 69 |
"Source Language": ", ".join(list(map(lambda x: language_maps[x], translator["sourceAccent"]))),
|
| 70 |
"Target Language": ", ".join(list(map(lambda x: language_maps[x], translator["targetAccent"])))
|
| 71 |
})
|
| 72 |
-
except:
|
|
|
|
| 73 |
pass
|
| 74 |
-
return pd.DataFrame(
|
| 75 |
|
| 76 |
|
| 77 |
def add_translator(platform, email_id, source_langs, target_langs, contact_num, pricing):
|
| 78 |
if platform == "dev":
|
|
|
|
| 79 |
client = pymongo.MongoClient(os.environ.get("MONGO_DEV_URI"))
|
| 80 |
source_db = client.deepsync_stage
|
| 81 |
else:
|
|
|
|
| 82 |
client = pymongo.MongoClient(os.environ.get("MONGO_URI"))
|
| 83 |
source_db = client.deepsync_prod
|
| 84 |
|
|
@@ -98,34 +107,53 @@ def add_translator(platform, email_id, source_langs, target_langs, contact_num,
|
|
| 98 |
else:
|
| 99 |
target_accents = [language_maps[l] for l in target_langs]
|
| 100 |
|
| 101 |
-
|
| 102 |
-
"translator": company_id_validity["_id"],
|
| 103 |
"targetAccent": target_accents,
|
| 104 |
"sourceAccent": source_accents,
|
| 105 |
"contactNum": None if len(contact_num.strip()) == 0 else contact_num.strip(),
|
| 106 |
"pricing": None if pricing is None or pricing == -1 else pricing
|
| 107 |
-
}
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
|
| 111 |
def get_translator_names(platform):
|
| 112 |
if platform == "dev":
|
|
|
|
| 113 |
client = pymongo.MongoClient(os.environ.get("MONGO_DEV_URI"))
|
| 114 |
source_db = client.deepsync_stage
|
| 115 |
else:
|
|
|
|
| 116 |
client = pymongo.MongoClient(os.environ.get("MONGO_URI"))
|
| 117 |
source_db = client.deepsync_prod
|
| 118 |
-
|
|
|
|
|
|
|
| 119 |
translators_names = []
|
|
|
|
| 120 |
if len(translators):
|
| 121 |
-
desired_ids = [t["translator"] for t in translators]
|
| 122 |
companies_cursor = source_db.companies.find({'_id': {'$in': desired_ids}})
|
| 123 |
companies = {c["_id"]: c for c in companies_cursor}
|
| 124 |
for translator in translators:
|
| 125 |
try:
|
| 126 |
-
data = companies[translator["translator"]]
|
| 127 |
-
translators_names.append(data["name"])
|
| 128 |
-
except:
|
|
|
|
| 129 |
pass
|
| 130 |
return gr.Dropdown.update(choices=translators_names)
|
| 131 |
|
|
@@ -133,69 +161,67 @@ def get_translator_names(platform):
|
|
| 133 |
def select_current_data(platform, translator_name):
|
| 134 |
if translator_name is None:
|
| 135 |
return "Please select a translator."
|
|
|
|
|
|
|
|
|
|
| 136 |
if platform == "dev":
|
| 137 |
-
|
| 138 |
-
source_db = client.deepsync_stage
|
| 139 |
else:
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
translators = list(
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
company_id = company["_id"]
|
| 149 |
-
break
|
| 150 |
-
for tr in translators:
|
| 151 |
-
if tr["_id"] == translator_company_ids[company_id]:
|
| 152 |
-
translator = tr
|
| 153 |
-
break
|
| 154 |
return gr.CheckboxGroup.update(value=[language_maps[l] for l in translator["sourceAccent"]]), gr.CheckboxGroup.update(value=[language_maps[l] for l in translator["targetAccent"]]), gr.Textbox.update(value="" if translator["contactNum"] is None else translator["contactNum"]), gr.Textbox.update(value=-1 if translator["pricing"] is None else translator["pricing"])
|
| 155 |
|
| 156 |
|
| 157 |
def update_translator(platform, translator_name, source_languages, target_languages, contact_num, pricing):
|
| 158 |
if translator_name is None:
|
| 159 |
return "Please select a translator."
|
|
|
|
|
|
|
|
|
|
| 160 |
if platform == "dev":
|
| 161 |
-
|
| 162 |
-
source_db = client.deepsync_stage
|
| 163 |
else:
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
translators = list(
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
break
|
| 174 |
source_accents = [language_maps[l] for l in source_languages]
|
| 175 |
target_accents = [language_maps[l] for l in target_languages]
|
| 176 |
|
| 177 |
updateable_data = {
|
| 178 |
"sourceAccent": source_accents,
|
| 179 |
"targetAccent": target_accents,
|
| 180 |
-
"contactNum":
|
| 181 |
-
"pricing":
|
| 182 |
}
|
| 183 |
|
| 184 |
-
response =
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
return f"Updated translator details succesfully."
|
| 189 |
|
| 190 |
|
| 191 |
-
def get_videos_under_review(status_keys):
|
| 192 |
-
|
| 193 |
-
"
|
| 194 |
-
|
| 195 |
-
|
|
|
|
| 196 |
if status_keys is None or len(status_keys) == 0:
|
| 197 |
-
API_URL = "
|
| 198 |
-
response = requests.get(API_URL, headers=
|
| 199 |
if response.status_code == 200:
|
| 200 |
options = [f"{str(v['_id'])} / {v['title']}" for v in response.json()['data'] if 'title' in v]
|
| 201 |
return gr.Dropdown.update(choices=options, value=None), ""
|
|
@@ -205,8 +231,8 @@ def get_videos_under_review(status_keys):
|
|
| 205 |
options = []
|
| 206 |
count = {}
|
| 207 |
for status in status_keys:
|
| 208 |
-
API_URL = f"
|
| 209 |
-
response = requests.get(API_URL, headers=
|
| 210 |
if response.status_code == 200:
|
| 211 |
current_options = [f"{str(v['_id'])} / {v['title']}" for v in response.json()['data'] if 'title' in v]
|
| 212 |
count[status] = len(current_options)
|
|
@@ -215,13 +241,40 @@ def get_videos_under_review(status_keys):
|
|
| 215 |
return gr.Dropdown.update(choices=options, value=None), data_text
|
| 216 |
|
| 217 |
|
| 218 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
video_id = video.split("/", maxsplit=1)[0].strip()
|
| 220 |
-
|
| 221 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
video = source_db.dubbedvideos.find_one({"_id": ObjectId(video_id)})
|
| 223 |
source_language = video["sourceLanguage"].split("-")[0]
|
| 224 |
target_language = video["targetLanguage"].split("-")[0]
|
|
|
|
| 225 |
translators = list(source_db.translators.find({"sourceAccent": {"$elemMatch": {"$eq": source_language}}, "targetAccent": {"$elemMatch": {"$eq": target_language}}}))
|
| 226 |
translators_list = []
|
| 227 |
if len(translators):
|
|
@@ -249,38 +302,42 @@ def get_traslators_assign(video):
|
|
| 249 |
return gr.Dropdown.update(choices=translators_list, value=current_translator), gr.Dropdown.update(choices=translators_list, value=current_qa), language_maps[source_language], language_maps[target_language], button, button
|
| 250 |
|
| 251 |
|
| 252 |
-
def assign_translator(translator, video):
|
| 253 |
translator_id = translator.rsplit("/", maxsplit=1)[1].strip()
|
| 254 |
video_id = video.split("/", maxsplit=1)[0].strip()
|
| 255 |
-
headers = {
|
| 256 |
-
"x-api-key": os.environ.get('X-API-KEY'),
|
| 257 |
-
"Content-Type": "application/json"
|
| 258 |
-
}
|
| 259 |
role = "translator"
|
| 260 |
-
|
|
|
|
|
|
|
|
|
|
| 261 |
data = {
|
| 262 |
"videoId": video_id,
|
| 263 |
"userId": translator_id
|
| 264 |
}
|
| 265 |
-
response = requests.post(
|
| 266 |
-
|
|
|
|
|
|
|
|
|
|
| 267 |
|
| 268 |
|
| 269 |
-
def assign_qa(qa, video):
|
| 270 |
translator_id = qa.rsplit("/", maxsplit=1)[1].strip()
|
| 271 |
video_id = video.split("/", maxsplit=1)[0].strip()
|
| 272 |
-
headers = {
|
| 273 |
-
"x-api-key": os.environ.get('X-API-KEY'),
|
| 274 |
-
"Content-Type": "application/json"
|
| 275 |
-
}
|
| 276 |
role = "QA"
|
| 277 |
-
|
|
|
|
|
|
|
|
|
|
| 278 |
data = {
|
| 279 |
"videoId": video_id,
|
| 280 |
"userId": translator_id
|
| 281 |
}
|
| 282 |
-
response = requests.post(
|
| 283 |
-
|
|
|
|
|
|
|
|
|
|
| 284 |
|
| 285 |
|
| 286 |
with gr.Blocks() as demo:
|
|
@@ -309,9 +366,11 @@ with gr.Blocks() as demo:
|
|
| 309 |
contact_num_update = gr.Textbox(label="Contact Number", lines=1)
|
| 310 |
pricing_update = gr.Number(label="Pricing")
|
| 311 |
update_language = gr.Button("Update")
|
|
|
|
| 312 |
result_update = gr.Textbox(label="Logs")
|
| 313 |
with gr.Tab("Assign"):
|
| 314 |
gr.Markdown("Assign Translator / QA")
|
|
|
|
| 315 |
filter_videos_assign = gr.CheckboxGroup(['Not Started', 'Dubbing Started', 'Waiting QA', 'Sent to Client', 'Approved', 'Rejected', 'Churned', 'Re-review Requested'], label="Filter videos. Do not select any of them for videos without request info.")
|
| 316 |
video_details = gr.Textbox(label="Video Details")
|
| 317 |
refresh_assign = gr.Button("Load Videos")
|
|
@@ -340,13 +399,14 @@ with gr.Blocks() as demo:
|
|
| 340 |
source_platform_update.change(get_translator_names, source_platform_update, translator_name)
|
| 341 |
translator_name.change(select_current_data, [source_platform_update, translator_name], [source_languages_update, target_languages_update, contact_num_update, pricing_update])
|
| 342 |
update_language.click(update_translator, [source_platform_update, translator_name, source_languages_update, target_languages_update, contact_num_update, pricing_update], result_update)
|
|
|
|
| 343 |
|
| 344 |
# For Assign
|
| 345 |
-
refresh_assign.click(get_videos_under_review, filter_videos_assign, [under_review_videos_list, video_details])
|
| 346 |
-
under_review_videos_list.change(get_traslators_assign, under_review_videos_list, [translator_name_assign, qa_name_assign, source_language_box, target_language_box, submit_tr_assign_button, submit_qa_assign_button])
|
| 347 |
-
submit_tr_assign_button.click(assign_translator, [translator_name_assign, under_review_videos_list], assign_logs)
|
| 348 |
-
submit_qa_assign_button.click(assign_qa, [qa_name_assign, under_review_videos_list], assign_logs)
|
| 349 |
|
| 350 |
|
| 351 |
if __name__=="__main__":
|
| 352 |
-
demo.launch(auth=(os.environ.get("GRADIO_USERNAME"), os.environ.get("GRADIO_PASSWORD")))
|
|
|
|
| 19 |
"Re-review Requested": "RE_REVIEW_REQUESTED"
|
| 20 |
}
|
| 21 |
|
| 22 |
+
HEADERS = {"x-api-key": os.environ.get('X-API-KEY'), "Content-Type": "application/json"}
|
| 23 |
+
|
| 24 |
ALL_LANGUAGES = ['Hindi', 'English', 'Bengali', 'Kannada', 'Spanish', 'French', 'German', 'Italian', 'Tamil', 'Telugu']
|
| 25 |
|
| 26 |
language_maps = {
|
|
|
|
| 46 |
"kn": "Kannada"
|
| 47 |
}
|
| 48 |
|
|
|
|
| 49 |
|
| 50 |
def get_translators(platform):
|
| 51 |
if platform == "dev":
|
| 52 |
+
api_url = "https://api.dev-env.deepsync.co/api/v1"
|
| 53 |
client = pymongo.MongoClient(os.environ.get("MONGO_DEV_URI"))
|
| 54 |
source_db = client.deepsync_stage
|
| 55 |
else:
|
| 56 |
+
api_url = "https://api.deepsync.co/api/v1"
|
| 57 |
client = pymongo.MongoClient(os.environ.get("MONGO_URI"))
|
| 58 |
source_db = client.deepsync_prod
|
| 59 |
+
|
| 60 |
+
response = requests.get(f"{api_url}/dashboard/translators", headers=HEADERS)
|
| 61 |
+
translators = list(filter(lambda x: not x.get('isDeleted', False), response.json()['data']))
|
| 62 |
+
translators_data = []
|
| 63 |
+
|
| 64 |
if len(translators):
|
| 65 |
+
desired_ids = [ObjectId(t["translator"]) for t in translators]
|
| 66 |
companies_cursor = source_db.companies.find({'_id': {'$in': desired_ids}})
|
| 67 |
companies = {c["_id"]: c for c in companies_cursor}
|
| 68 |
for translator in translators:
|
| 69 |
try:
|
| 70 |
+
data = companies[ObjectId(translator["translator"])]
|
| 71 |
+
translators_data.append({
|
| 72 |
"_id": str(translator["_id"]),
|
| 73 |
"Name": data["name"],
|
| 74 |
"Email": data["email"],
|
| 75 |
"Source Language": ", ".join(list(map(lambda x: language_maps[x], translator["sourceAccent"]))),
|
| 76 |
"Target Language": ", ".join(list(map(lambda x: language_maps[x], translator["targetAccent"])))
|
| 77 |
})
|
| 78 |
+
except Exception as e:
|
| 79 |
+
print(e)
|
| 80 |
pass
|
| 81 |
+
return pd.DataFrame(translators_data)
|
| 82 |
|
| 83 |
|
| 84 |
def add_translator(platform, email_id, source_langs, target_langs, contact_num, pricing):
|
| 85 |
if platform == "dev":
|
| 86 |
+
api_url = "https://api.dev-env.deepsync.co/api/v1"
|
| 87 |
client = pymongo.MongoClient(os.environ.get("MONGO_DEV_URI"))
|
| 88 |
source_db = client.deepsync_stage
|
| 89 |
else:
|
| 90 |
+
api_url = "https://api.deepsync.co/api/v1"
|
| 91 |
client = pymongo.MongoClient(os.environ.get("MONGO_URI"))
|
| 92 |
source_db = client.deepsync_prod
|
| 93 |
|
|
|
|
| 107 |
else:
|
| 108 |
target_accents = [language_maps[l] for l in target_langs]
|
| 109 |
|
| 110 |
+
main_data = {
|
|
|
|
| 111 |
"targetAccent": target_accents,
|
| 112 |
"sourceAccent": source_accents,
|
| 113 |
"contactNum": None if len(contact_num.strip()) == 0 else contact_num.strip(),
|
| 114 |
"pricing": None if pricing is None or pricing == -1 else pricing
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
data = {"translator": str(company_id_validity["_id"]), **main_data}
|
| 118 |
+
|
| 119 |
+
response = requests.post(f"{api_url}/dashboard/translator", json=data, headers=HEADERS)
|
| 120 |
+
|
| 121 |
+
if str(response.status_code).startswith('4') or str(response.status_code).startswith('5'):
|
| 122 |
+
if response.json()['message'].strip() == "Translator already exists":
|
| 123 |
+
translator_main_id = source_db.translators.find_one({"translator": company_id_validity['_id']})
|
| 124 |
+
response = requests.patch(f"{api_url}/dashboard/translators/{translator_main_id['_id']}", json={"isDeleted": False, **main_data}, headers=HEADERS)
|
| 125 |
+
if str(response.status_code).startswith('4') or str(response.status_code).startswith('5'):
|
| 126 |
+
return f"{response.json()['message']} ({response.status_code})"
|
| 127 |
+
return f"Translator added succesfully, ID : {response.json()['data']['_id']}"
|
| 128 |
+
return f"{response.json()['message']} ({response.status_code})"
|
| 129 |
+
|
| 130 |
+
return f"Translator added succesfully, ID : {response.json()['data']['_id']}"
|
| 131 |
|
| 132 |
|
| 133 |
def get_translator_names(platform):
|
| 134 |
if platform == "dev":
|
| 135 |
+
api_url = "https://api.dev-env.deepsync.co/api/v1"
|
| 136 |
client = pymongo.MongoClient(os.environ.get("MONGO_DEV_URI"))
|
| 137 |
source_db = client.deepsync_stage
|
| 138 |
else:
|
| 139 |
+
api_url = "https://api.deepsync.co/api/v1"
|
| 140 |
client = pymongo.MongoClient(os.environ.get("MONGO_URI"))
|
| 141 |
source_db = client.deepsync_prod
|
| 142 |
+
|
| 143 |
+
response = requests.get(f"{api_url}/dashboard/translators", headers=HEADERS)
|
| 144 |
+
translators = list(filter(lambda x: not x.get('isDeleted', False), response.json()['data']))
|
| 145 |
translators_names = []
|
| 146 |
+
|
| 147 |
if len(translators):
|
| 148 |
+
desired_ids = [ObjectId(t["translator"]) for t in translators]
|
| 149 |
companies_cursor = source_db.companies.find({'_id': {'$in': desired_ids}})
|
| 150 |
companies = {c["_id"]: c for c in companies_cursor}
|
| 151 |
for translator in translators:
|
| 152 |
try:
|
| 153 |
+
data = companies[ObjectId(translator["translator"])]
|
| 154 |
+
translators_names.append(f'{data["name"]} / {data["email"]} / {translator["_id"]}')
|
| 155 |
+
except Exception as e:
|
| 156 |
+
print(e)
|
| 157 |
pass
|
| 158 |
return gr.Dropdown.update(choices=translators_names)
|
| 159 |
|
|
|
|
| 161 |
def select_current_data(platform, translator_name):
|
| 162 |
if translator_name is None:
|
| 163 |
return "Please select a translator."
|
| 164 |
+
|
| 165 |
+
name, email, translator_id = list(map(lambda x: x.strip(), translator_name.split("/")))
|
| 166 |
+
|
| 167 |
if platform == "dev":
|
| 168 |
+
api_url = "https://api.dev-env.deepsync.co/api/v1"
|
|
|
|
| 169 |
else:
|
| 170 |
+
api_url = "https://api.deepsync.co/api/v1"
|
| 171 |
+
|
| 172 |
+
response = requests.get(f"{api_url}/dashboard/translators", headers=HEADERS)
|
| 173 |
+
translators = list(filter(lambda x: not x.get('isDeleted', False) and x["_id"] == translator_id, response.json()['data']))
|
| 174 |
+
if len(translators):
|
| 175 |
+
translator = translators[0]
|
| 176 |
+
else:
|
| 177 |
+
raise Exception("Translator", translator_name, "not found.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
return gr.CheckboxGroup.update(value=[language_maps[l] for l in translator["sourceAccent"]]), gr.CheckboxGroup.update(value=[language_maps[l] for l in translator["targetAccent"]]), gr.Textbox.update(value="" if translator["contactNum"] is None else translator["contactNum"]), gr.Textbox.update(value=-1 if translator["pricing"] is None else translator["pricing"])
|
| 179 |
|
| 180 |
|
| 181 |
def update_translator(platform, translator_name, source_languages, target_languages, contact_num, pricing):
|
| 182 |
if translator_name is None:
|
| 183 |
return "Please select a translator."
|
| 184 |
+
|
| 185 |
+
name, email, translator_id = list(map(lambda x: x.strip(), translator_name.split("/")))
|
| 186 |
+
|
| 187 |
if platform == "dev":
|
| 188 |
+
api_url = "https://api.dev-env.deepsync.co/api/v1"
|
|
|
|
| 189 |
else:
|
| 190 |
+
api_url = "https://api.deepsync.co/api/v1"
|
| 191 |
+
|
| 192 |
+
response = requests.get(f"{api_url}/dashboard/translators", headers=HEADERS)
|
| 193 |
+
translators = list(filter(lambda x: not x.get('isDeleted', False), response.json()['data']))
|
| 194 |
+
if len(translators):
|
| 195 |
+
translator = translators[0]
|
| 196 |
+
else:
|
| 197 |
+
raise Exception("Translator", translator_name, "not found.")
|
| 198 |
+
|
|
|
|
| 199 |
source_accents = [language_maps[l] for l in source_languages]
|
| 200 |
target_accents = [language_maps[l] for l in target_languages]
|
| 201 |
|
| 202 |
updateable_data = {
|
| 203 |
"sourceAccent": source_accents,
|
| 204 |
"targetAccent": target_accents,
|
| 205 |
+
"contactNum": "" if contact_num is None else contact_num.strip(),
|
| 206 |
+
"pricing": 0 if pricing is None else pricing
|
| 207 |
}
|
| 208 |
|
| 209 |
+
response = requests.patch(f"{api_url}/dashboard/translators/{translator_id}", json=updateable_data, headers=HEADERS)
|
| 210 |
+
if str(response.status_code).startswith('4') or str(response.status_code).startswith('5'):
|
| 211 |
+
return response.json()['message']
|
| 212 |
+
|
| 213 |
return f"Updated translator details succesfully."
|
| 214 |
|
| 215 |
|
| 216 |
+
def get_videos_under_review(platform, status_keys):
|
| 217 |
+
if platform == "dev":
|
| 218 |
+
api_url = "https://api.dev-env.deepsync.co/api/v1"
|
| 219 |
+
else:
|
| 220 |
+
api_url = "https://api.deepsync.co/api/v1"
|
| 221 |
+
|
| 222 |
if status_keys is None or len(status_keys) == 0:
|
| 223 |
+
API_URL = f"{api_url}/dashboard/dubbed/videos/review/requested"
|
| 224 |
+
response = requests.get(API_URL, headers=HEADERS)
|
| 225 |
if response.status_code == 200:
|
| 226 |
options = [f"{str(v['_id'])} / {v['title']}" for v in response.json()['data'] if 'title' in v]
|
| 227 |
return gr.Dropdown.update(choices=options, value=None), ""
|
|
|
|
| 231 |
options = []
|
| 232 |
count = {}
|
| 233 |
for status in status_keys:
|
| 234 |
+
API_URL = f"{api_url}/dashboard/dubbed/videos/review/requested/{video_status[status]}"
|
| 235 |
+
response = requests.get(API_URL, headers=HEADERS)
|
| 236 |
if response.status_code == 200:
|
| 237 |
current_options = [f"{str(v['_id'])} / {v['title']}" for v in response.json()['data'] if 'title' in v]
|
| 238 |
count[status] = len(current_options)
|
|
|
|
| 241 |
return gr.Dropdown.update(choices=options, value=None), data_text
|
| 242 |
|
| 243 |
|
| 244 |
+
def delete_translator_func(platform, translator_name):
|
| 245 |
+
if translator_name is None:
|
| 246 |
+
return "Please select a translator."
|
| 247 |
+
|
| 248 |
+
name, email, translator_id = list(map(lambda x: x.strip(), translator_name.split("/")))
|
| 249 |
+
|
| 250 |
+
if platform == "dev":
|
| 251 |
+
api_url = "https://api.dev-env.deepsync.co/api/v1"
|
| 252 |
+
else:
|
| 253 |
+
api_url = "https://api.deepsync.co/api/v1"
|
| 254 |
+
|
| 255 |
+
response = requests.patch(f"{api_url}/dashboard/translators/{translator_id}", json={"isDeleted": True}, headers=HEADERS)
|
| 256 |
+
if str(response.status_code).startswith('4') or str(response.status_code).startswith('5'):
|
| 257 |
+
return response.json()['message']
|
| 258 |
+
return "Translator deleted."
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
def get_traslators_assign(platform, video):
|
| 263 |
video_id = video.split("/", maxsplit=1)[0].strip()
|
| 264 |
+
|
| 265 |
+
if platform == "dev":
|
| 266 |
+
api_url = "https://api.dev-env.deepsync.co/api/v1"
|
| 267 |
+
client = pymongo.MongoClient(os.environ.get("MONGO_DEV_URI"))
|
| 268 |
+
source_db = client.deepsync_stage
|
| 269 |
+
else:
|
| 270 |
+
api_url = "https://api.deepsync.co/api/v1"
|
| 271 |
+
client = pymongo.MongoClient(os.environ.get("MONGO_URI"))
|
| 272 |
+
source_db = client.deepsync_prod
|
| 273 |
+
|
| 274 |
video = source_db.dubbedvideos.find_one({"_id": ObjectId(video_id)})
|
| 275 |
source_language = video["sourceLanguage"].split("-")[0]
|
| 276 |
target_language = video["targetLanguage"].split("-")[0]
|
| 277 |
+
|
| 278 |
translators = list(source_db.translators.find({"sourceAccent": {"$elemMatch": {"$eq": source_language}}, "targetAccent": {"$elemMatch": {"$eq": target_language}}}))
|
| 279 |
translators_list = []
|
| 280 |
if len(translators):
|
|
|
|
| 302 |
return gr.Dropdown.update(choices=translators_list, value=current_translator), gr.Dropdown.update(choices=translators_list, value=current_qa), language_maps[source_language], language_maps[target_language], button, button
|
| 303 |
|
| 304 |
|
| 305 |
+
def assign_translator(platform, translator, video):
|
| 306 |
translator_id = translator.rsplit("/", maxsplit=1)[1].strip()
|
| 307 |
video_id = video.split("/", maxsplit=1)[0].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 308 |
role = "translator"
|
| 309 |
+
if platform == "dev":
|
| 310 |
+
api_url = "https://api.dev-env.deepsync.co/api/v1"
|
| 311 |
+
else:
|
| 312 |
+
api_url = "https://api.deepsync.co/api/v1"
|
| 313 |
data = {
|
| 314 |
"videoId": video_id,
|
| 315 |
"userId": translator_id
|
| 316 |
}
|
| 317 |
+
response = requests.post(f"{api_url}/dashboard/dubbed/video/assign/{role}", json=data, headers=HEADERS)
|
| 318 |
+
if str(response.status_code).startswith('2'):
|
| 319 |
+
return "Successfully assigned."
|
| 320 |
+
else:
|
| 321 |
+
return str(response.status_code)
|
| 322 |
|
| 323 |
|
| 324 |
+
def assign_qa(platform, qa, video):
|
| 325 |
translator_id = qa.rsplit("/", maxsplit=1)[1].strip()
|
| 326 |
video_id = video.split("/", maxsplit=1)[0].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
role = "QA"
|
| 328 |
+
if platform == "dev":
|
| 329 |
+
api_url = "https://api.dev-env.deepsync.co/api/v1"
|
| 330 |
+
else:
|
| 331 |
+
api_url = "https://api.deepsync.co/api/v1"
|
| 332 |
data = {
|
| 333 |
"videoId": video_id,
|
| 334 |
"userId": translator_id
|
| 335 |
}
|
| 336 |
+
response = requests.post(f"{api_url}/dashboard/dubbed/video/assign/{role}", json=data, headers=HEADERS)
|
| 337 |
+
if str(response.status_code).startswith('2'):
|
| 338 |
+
return "Successfully assigned."
|
| 339 |
+
else:
|
| 340 |
+
return str(response.status_code)
|
| 341 |
|
| 342 |
|
| 343 |
with gr.Blocks() as demo:
|
|
|
|
| 366 |
contact_num_update = gr.Textbox(label="Contact Number", lines=1)
|
| 367 |
pricing_update = gr.Number(label="Pricing")
|
| 368 |
update_language = gr.Button("Update")
|
| 369 |
+
delete_translator = gr.Button("Delete Translator")
|
| 370 |
result_update = gr.Textbox(label="Logs")
|
| 371 |
with gr.Tab("Assign"):
|
| 372 |
gr.Markdown("Assign Translator / QA")
|
| 373 |
+
source_platform_assign = gr.Radio(["dev", "prod"], value="dev", label="Source Platform")
|
| 374 |
filter_videos_assign = gr.CheckboxGroup(['Not Started', 'Dubbing Started', 'Waiting QA', 'Sent to Client', 'Approved', 'Rejected', 'Churned', 'Re-review Requested'], label="Filter videos. Do not select any of them for videos without request info.")
|
| 375 |
video_details = gr.Textbox(label="Video Details")
|
| 376 |
refresh_assign = gr.Button("Load Videos")
|
|
|
|
| 399 |
source_platform_update.change(get_translator_names, source_platform_update, translator_name)
|
| 400 |
translator_name.change(select_current_data, [source_platform_update, translator_name], [source_languages_update, target_languages_update, contact_num_update, pricing_update])
|
| 401 |
update_language.click(update_translator, [source_platform_update, translator_name, source_languages_update, target_languages_update, contact_num_update, pricing_update], result_update)
|
| 402 |
+
delete_translator.click(delete_translator_func, [source_platform_update, translator_name], result_update)
|
| 403 |
|
| 404 |
# For Assign
|
| 405 |
+
refresh_assign.click(get_videos_under_review, [source_platform_assign, filter_videos_assign], [under_review_videos_list, video_details])
|
| 406 |
+
under_review_videos_list.change(get_traslators_assign, [source_platform_assign, under_review_videos_list], [translator_name_assign, qa_name_assign, source_language_box, target_language_box, submit_tr_assign_button, submit_qa_assign_button])
|
| 407 |
+
submit_tr_assign_button.click(assign_translator, [source_platform_assign, translator_name_assign, under_review_videos_list], assign_logs)
|
| 408 |
+
submit_qa_assign_button.click(assign_qa, [source_platform_assign, qa_name_assign, under_review_videos_list], assign_logs)
|
| 409 |
|
| 410 |
|
| 411 |
if __name__=="__main__":
|
| 412 |
+
demo.launch(share=True, auth=(os.environ.get("GRADIO_USERNAME"), os.environ.get("GRADIO_PASSWORD")))
|