forked from Samagra-Development/ai-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
37 lines (24 loc) · 1.36 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from src.text_lang_detection.bhashini.remote import *
import asyncio, aiohttp, time
from quart import Quart
str_to_test = "ତୁମର କୋଡ୍ ରିଫାକ୍ଟର୍ କରିବାକୁ ଯାହା ଦ୍ you ାରା ତୁମେ ଲୁପ୍ ପାଇଁ ପ୍ରତିକ୍ରିୟାକୁ ଅପେକ୍ଷା କରୁନାହଁ, ତୁମେ ଏକାସାଙ୍ଗରେ ଇନ୍ଫରେନ୍ସ ଫଙ୍କସନ୍ ର ଏକାଧିକ ଉଦାହରଣ ଚଲାଇବାକୁ ବ୍ୟବହାର କରିପାରିବ | ଏଠାରେ ଅପଡେଟ୍ କୋଡ୍ ଅଛି |"
app = Quart(__name__)
async def single_inference(app, text, index):
m = Model(app)
resp = await m.inference(ModelRequest(text=text))
print(f"{index}: {resp}")
async def bench_text_lang_detection(app):
tasks = []
for i in range(len(str_to_test)):
task = single_inference(app, str_to_test[0:i], i)
tasks.append(task)
await asyncio.gather(*tasks)
async def main():
app.client = aiohttp.ClientSession()
start_time = time.perf_counter()
await bench_text_lang_detection(app)
end_time = time.perf_counter()
print(f"Time taken: {end_time - start_time:.4f} seconds for {len(str_to_test)} characters")
await app.client.close()
asyncio.run(main())
# Time taken: 4.2715 seconds for 104 characters