Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -53,11 +53,15 @@ def get_translators(platform):
|
|
53 |
else:
|
54 |
client = pymongo.MongoClient(os.environ.get("MONGO_URI"))
|
55 |
source_db = client.deepsync_prod
|
56 |
-
translators = source_db.translators.find({})
|
57 |
transaltors_data = []
|
|
|
|
|
|
|
|
|
58 |
for translator in translators:
|
59 |
try:
|
60 |
-
data =
|
61 |
transaltors_data.append({
|
62 |
"_id": str(translator["_id"]),
|
63 |
"Name": data["name"],
|
@@ -111,11 +115,15 @@ def get_translator_names(platform):
|
|
111 |
else:
|
112 |
client = pymongo.MongoClient(os.environ.get("MONGO_URI"))
|
113 |
source_db = client.deepsync_prod
|
114 |
-
translators = source_db.translators.find({})
|
115 |
translators_names = []
|
|
|
|
|
|
|
|
|
116 |
for translator in translators:
|
117 |
try:
|
118 |
-
data =
|
119 |
translators_names.append(data["name"])
|
120 |
except:
|
121 |
pass
|
@@ -177,7 +185,7 @@ def update_translator(platform, translator_name, source_languages, target_langua
|
|
177 |
{"_id": translator_company_ids[company_id]},
|
178 |
{"$set": updateable_data}
|
179 |
)
|
180 |
-
return f"Updated translator
|
181 |
|
182 |
|
183 |
def get_videos_under_review(status_keys):
|
@@ -190,18 +198,21 @@ def get_videos_under_review(status_keys):
|
|
190 |
response = requests.get(API_URL, headers=headers)
|
191 |
if response.status_code == 200:
|
192 |
options = [f"{str(v['_id'])} / {v['title']}" for v in response.json()['data'] if 'title' in v]
|
193 |
-
return gr.Dropdown.update(choices=options, value=None)
|
194 |
else:
|
195 |
-
return gr.Dropdown.update(choices=[], value=None)
|
196 |
else:
|
197 |
options = []
|
|
|
198 |
for status in status_keys:
|
199 |
API_URL = f"https://api.dev-env.deepsync.co/api/v1/dashboard/dubbed/videos/review/requested/{video_status[status]}"
|
200 |
response = requests.get(API_URL, headers=headers)
|
201 |
if response.status_code == 200:
|
202 |
current_options = [f"{str(v['_id'])} / {v['title']}" for v in response.json()['data'] if 'title' in v]
|
|
|
203 |
options.extend(current_options)
|
204 |
-
|
|
|
205 |
|
206 |
|
207 |
def get_traslators_assign(video):
|
@@ -211,27 +222,58 @@ def get_traslators_assign(video):
|
|
211 |
video = source_db.dubbedvideos.find_one({"_id": ObjectId(video_id)})
|
212 |
source_language = video["sourceLanguage"].split("-")[0]
|
213 |
target_language = video["targetLanguage"].split("-")[0]
|
214 |
-
translators = source_db.translators.find({"sourceAccent": {"$elemMatch": {"$eq": source_language}}, "targetAccent": {"$elemMatch": {"$eq": target_language}}})
|
215 |
translators_list = []
|
|
|
|
|
|
|
|
|
216 |
for translator in translators:
|
217 |
-
company =
|
218 |
-
translators_list.append(f"{company['name']} / {str(translator['_id'])}")
|
219 |
|
220 |
button = gr.Button.update(interactive=False)
|
|
|
|
|
221 |
if "videoReviewInformation" in video:
|
222 |
if video["videoReviewInformation"]["status"] in {"NOT_STARTED", "DUBBING_STARTED", "WAITING_QA"}:
|
223 |
button = gr.Button.update(interactive=True)
|
224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
|
226 |
|
227 |
-
def assign_translator(translator, video
|
228 |
translator_id = translator.rsplit("/", maxsplit=1)[1].strip()
|
229 |
video_id = video.split("/", maxsplit=1)[0].strip()
|
230 |
headers = {
|
231 |
"x-api-key": os.environ.get('X-API-KEY'),
|
232 |
"Content-Type": "application/json"
|
233 |
}
|
234 |
-
role = "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
API_URL = f"https://api.dev-env.deepsync.co/api/v1/dashboard/dubbed/video/assign/{role}"
|
236 |
data = {
|
237 |
"videoId": video_id,
|
@@ -271,14 +313,18 @@ with gr.Blocks() as demo:
|
|
271 |
with gr.Tab("Assign"):
|
272 |
gr.Markdown("Assign Translator / QA")
|
273 |
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.")
|
|
|
274 |
refresh_assign = gr.Button("Load Videos")
|
275 |
under_review_videos_list = gr.Dropdown([], label="Video IDs")
|
276 |
with gr.Row():
|
277 |
source_language_box = gr.Textbox(label="Source Language")
|
278 |
target_language_box = gr.Textbox(label="Target Language")
|
279 |
-
|
280 |
-
|
281 |
-
|
|
|
|
|
|
|
282 |
assign_logs = gr.Textbox(label="Logs")
|
283 |
|
284 |
|
@@ -296,9 +342,10 @@ with gr.Blocks() as demo:
|
|
296 |
update_language.click(update_translator, [source_platform_update, translator_name, source_languages_update, target_languages_update, contact_num_update, pricing_update], result_update)
|
297 |
|
298 |
# For Assign
|
299 |
-
refresh_assign.click(get_videos_under_review, filter_videos_assign, under_review_videos_list)
|
300 |
-
under_review_videos_list.change(get_traslators_assign, under_review_videos_list, [translator_name_assign, source_language_box, target_language_box,
|
301 |
-
|
|
|
302 |
|
303 |
|
304 |
if __name__=="__main__":
|
|
|
53 |
else:
|
54 |
client = pymongo.MongoClient(os.environ.get("MONGO_URI"))
|
55 |
source_db = client.deepsync_prod
|
56 |
+
translators = list(source_db.translators.find({}))
|
57 |
transaltors_data = []
|
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 |
transaltors_data.append({
|
66 |
"_id": str(translator["_id"]),
|
67 |
"Name": data["name"],
|
|
|
115 |
else:
|
116 |
client = pymongo.MongoClient(os.environ.get("MONGO_URI"))
|
117 |
source_db = client.deepsync_prod
|
118 |
+
translators = list(source_db.translators.find({}))
|
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
|
|
|
185 |
{"_id": translator_company_ids[company_id]},
|
186 |
{"$set": updateable_data}
|
187 |
)
|
188 |
+
return f"Updated translator details succesfully."
|
189 |
|
190 |
|
191 |
def get_videos_under_review(status_keys):
|
|
|
198 |
response = requests.get(API_URL, headers=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), ""
|
202 |
else:
|
203 |
+
return gr.Dropdown.update(choices=[], value=None), ""
|
204 |
else:
|
205 |
options = []
|
206 |
+
count = {}
|
207 |
for status in status_keys:
|
208 |
API_URL = f"https://api.dev-env.deepsync.co/api/v1/dashboard/dubbed/videos/review/requested/{video_status[status]}"
|
209 |
response = requests.get(API_URL, headers=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)
|
213 |
options.extend(current_options)
|
214 |
+
data_text = "\n".join([f"{k} : {v}" for k,v in count.items()])
|
215 |
+
return gr.Dropdown.update(choices=options, value=None), data_text
|
216 |
|
217 |
|
218 |
def get_traslators_assign(video):
|
|
|
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):
|
228 |
+
desired_ids = [t["translator"] for t in translators]
|
229 |
+
companies_cursor = source_db.companies.find({'_id': {'$in': desired_ids}})
|
230 |
+
companies = {c["_id"]: c for c in companies_cursor}
|
231 |
for translator in translators:
|
232 |
+
company = companies[translator["translator"]]
|
233 |
+
translators_list.append(f"{company['name']} / {company['email']} / {str(translator['_id'])}")
|
234 |
|
235 |
button = gr.Button.update(interactive=False)
|
236 |
+
current_translator = None
|
237 |
+
current_qa = None
|
238 |
if "videoReviewInformation" in video:
|
239 |
if video["videoReviewInformation"]["status"] in {"NOT_STARTED", "DUBBING_STARTED", "WAITING_QA"}:
|
240 |
button = gr.Button.update(interactive=True)
|
241 |
+
if video["videoReviewInformation"].get("assignedTranslator") is not None:
|
242 |
+
str_id = str(video["videoReviewInformation"].get("assignedTranslator"))
|
243 |
+
value = [v for v in translators_list if str_id in v]
|
244 |
+
current_translator = value[0] if len(value) else None
|
245 |
+
if video["videoReviewInformation"].get("assignedQA") is not None:
|
246 |
+
str_id = str(video["videoReviewInformation"].get("assignedTranslator"))
|
247 |
+
value = [v for v in translators_list if str_id in v]
|
248 |
+
current_qa = value[0] if len(value) else None
|
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 |
+
API_URL = f"https://api.dev-env.deepsync.co/api/v1/dashboard/dubbed/video/assign/{role}"
|
261 |
+
data = {
|
262 |
+
"videoId": video_id,
|
263 |
+
"userId": translator_id
|
264 |
+
}
|
265 |
+
response = requests.post(API_URL, json=data, headers=headers)
|
266 |
+
return str(response.status_code)
|
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 |
API_URL = f"https://api.dev-env.deepsync.co/api/v1/dashboard/dubbed/video/assign/{role}"
|
278 |
data = {
|
279 |
"videoId": video_id,
|
|
|
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")
|
318 |
under_review_videos_list = gr.Dropdown([], label="Video IDs")
|
319 |
with gr.Row():
|
320 |
source_language_box = gr.Textbox(label="Source Language")
|
321 |
target_language_box = gr.Textbox(label="Target Language")
|
322 |
+
with gr.Row():
|
323 |
+
translator_name_assign = gr.Dropdown([], label="Translator")
|
324 |
+
submit_tr_assign_button = gr.Button("Assign Translator")
|
325 |
+
with gr.Row():
|
326 |
+
qa_name_assign = gr.Dropdown([], label="QA")
|
327 |
+
submit_qa_assign_button = gr.Button("Assign QA")
|
328 |
assign_logs = gr.Textbox(label="Logs")
|
329 |
|
330 |
|
|
|
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__":
|