Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
mrfakename
commited on
Commit
•
7927ab2
1
Parent(s):
9117404
2x speedup
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
from datasets import load_dataset
|
4 |
-
import threading, time, uuid, sqlite3, shutil, os, random, asyncio
|
5 |
from pathlib import Path
|
6 |
from huggingface_hub import CommitScheduler, delete_file, hf_hub_download
|
7 |
from gradio_client import Client
|
@@ -473,36 +473,26 @@ with gr.Blocks() as leaderboard:
|
|
473 |
############
|
474 |
# 2x speedup (hopefully)
|
475 |
############
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
485 |
|
486 |
############
|
487 |
# 2x speedup (hopefully)
|
488 |
############
|
489 |
|
490 |
-
async def process_predictions(text, mdl1, mdl2):
|
491 |
-
aud1, aud2 = await predict_both_concurrently(text, mdl1, mdl2)
|
492 |
-
return (
|
493 |
-
text,
|
494 |
-
"Synthesize",
|
495 |
-
gr.update(visible=True),
|
496 |
-
mdl1,
|
497 |
-
mdl2,
|
498 |
-
gr.update(visible=True, value=aud1),
|
499 |
-
gr.update(visible=True, value=aud2),
|
500 |
-
gr.update(visible=True, interactive=True),
|
501 |
-
gr.update(visible=True, interactive=True),
|
502 |
-
gr.update(visible=False),
|
503 |
-
gr.update(visible=False),
|
504 |
-
gr.update(visible=False),
|
505 |
-
)
|
506 |
def synthandreturn(text):
|
507 |
text = text.strip()
|
508 |
if len(text) > MAX_SAMPLE_TXT_LENGTH:
|
@@ -517,7 +507,21 @@ 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",
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
from datasets import load_dataset
|
4 |
+
import threading, time, uuid, sqlite3, shutil, os, random, asyncio, threading
|
5 |
from pathlib import Path
|
6 |
from huggingface_hub import CommitScheduler, delete_file, hf_hub_download
|
7 |
from gradio_client import Client
|
|
|
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 |
|
480 |
+
def predict_and_update_both(router, text, mdl1, mdl2, gr_update1, gr_update2):
|
481 |
+
thread1 = threading.Thread(target=predict_and_update, args=(router, text, mdl1, gr_update1, "/synthesize"))
|
482 |
+
thread2 = threading.Thread(target=predict_and_update, args=(router, text, mdl2, gr_update2, "/synthesize"))
|
483 |
+
|
484 |
+
thread1.start()
|
485 |
+
thread2.start()
|
486 |
+
|
487 |
+
thread1.join() # Wait for thread1 to finish
|
488 |
+
thread2.join() # Wait for thread2 to finish
|
489 |
+
|
490 |
+
return thread1.predicted_value, thread2.predicted_value
|
491 |
|
492 |
############
|
493 |
# 2x speedup (hopefully)
|
494 |
############
|
495 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
496 |
def synthandreturn(text):
|
497 |
text = text.strip()
|
498 |
if len(text) > MAX_SAMPLE_TXT_LENGTH:
|
|
|
507 |
mdl1, mdl2 = random.sample(list(AVAILABLE_MODELS.keys()), 2)
|
508 |
log_text(text)
|
509 |
print("[debug] Using", mdl1, mdl2)
|
510 |
+
aud1, aud2 = predict_and_update_both(router, text, mdl1, mdl2, gr.update, gr.update)
|
511 |
+
return (
|
512 |
+
text,
|
513 |
+
"Synthesize",
|
514 |
+
gr.update(visible=True), # r2
|
515 |
+
mdl1, # model1
|
516 |
+
mdl2, # model2
|
517 |
+
aud1, # aud1
|
518 |
+
aud2, # aud2
|
519 |
+
gr.update(visible=True, interactive=True),
|
520 |
+
gr.update(visible=True, interactive=True),
|
521 |
+
gr.update(visible=False),
|
522 |
+
gr.update(visible=False),
|
523 |
+
gr.update(visible=False), #nxt round btn
|
524 |
+
)
|
525 |
# return (
|
526 |
# text,
|
527 |
# "Synthesize",
|