Spaces:
Running
Running
Commit
•
c823dc3
1
Parent(s):
d344789
Update app.py
Browse files
app.py
CHANGED
@@ -473,35 +473,6 @@ with gr.Blocks() as leaderboard:
|
|
473 |
############
|
474 |
# 2x speedup (hopefully)
|
475 |
############
|
476 |
-
def predict_and_update(router, text, model, gr_update, api_name):
|
477 |
-
prediction = router.predict(text, AVAILABLE_MODELS[model], api_name)
|
478 |
-
gr_update(visible=True, value=prediction)
|
479 |
-
return prediction
|
480 |
-
|
481 |
-
def predict_and_update_both(router, text, mdl1, mdl2, gr_update1, gr_update2):
|
482 |
-
result1, result2 = [None, None] # Placeholder for storing predictions
|
483 |
-
|
484 |
-
def thread_func1():
|
485 |
-
nonlocal result1
|
486 |
-
result1 = predict_and_update(router, text, mdl1, gr_update1, "/synthesize")
|
487 |
-
|
488 |
-
def thread_func2():
|
489 |
-
nonlocal result2
|
490 |
-
result2 = predict_and_update(router, text, mdl2, gr_update2, "/synthesize")
|
491 |
-
|
492 |
-
thread1 = threading.Thread(target=thread_func1)
|
493 |
-
thread2 = threading.Thread(target=thread_func2)
|
494 |
-
|
495 |
-
thread1.start()
|
496 |
-
thread2.start()
|
497 |
-
|
498 |
-
thread1.join() # Wait for thread1 to finish
|
499 |
-
thread2.join() # Wait for thread2 to finish
|
500 |
-
|
501 |
-
return result1, result2
|
502 |
-
############
|
503 |
-
# 2x speedup (hopefully)
|
504 |
-
############
|
505 |
|
506 |
def synthandreturn(text):
|
507 |
text = text.strip()
|
@@ -517,15 +488,22 @@ def synthandreturn(text):
|
|
517 |
mdl1, mdl2 = random.sample(list(AVAILABLE_MODELS.keys()), 2)
|
518 |
log_text(text)
|
519 |
print("[debug] Using", mdl1, mdl2)
|
520 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
521 |
return (
|
522 |
text,
|
523 |
"Synthesize",
|
524 |
gr.update(visible=True), # r2
|
525 |
mdl1, # model1
|
526 |
mdl2, # model2
|
527 |
-
|
528 |
-
|
529 |
gr.update(visible=True, interactive=True),
|
530 |
gr.update(visible=True, interactive=True),
|
531 |
gr.update(visible=False),
|
|
|
473 |
############
|
474 |
# 2x speedup (hopefully)
|
475 |
############
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
476 |
|
477 |
def synthandreturn(text):
|
478 |
text = text.strip()
|
|
|
488 |
mdl1, mdl2 = random.sample(list(AVAILABLE_MODELS.keys()), 2)
|
489 |
log_text(text)
|
490 |
print("[debug] Using", mdl1, mdl2)
|
491 |
+
def predict_and_update_result(text, model, gr_update):
|
492 |
+
result = router.predict(text, AVAILABLE_MODELS[model], api_name="/synthesize")
|
493 |
+
thread1 = threading.Thread(target=predict_and_update_result, args=(text, mdl1, gr.update))
|
494 |
+
thread2 = threading.Thread(target=predict_and_update_result, args=(text, mdl2, gr.update))
|
495 |
+
thread1.start()
|
496 |
+
thread2.start()
|
497 |
+
thread1.join()
|
498 |
+
thread2.join()
|
499 |
return (
|
500 |
text,
|
501 |
"Synthesize",
|
502 |
gr.update(visible=True), # r2
|
503 |
mdl1, # model1
|
504 |
mdl2, # model2
|
505 |
+
gr.update(visible=True, value=thread1.result), # aud1
|
506 |
+
gr.update(visible=True, value=thread2.result), # aud2
|
507 |
gr.update(visible=True, interactive=True),
|
508 |
gr.update(visible=True, interactive=True),
|
509 |
gr.update(visible=False),
|