Spaces:
Runtime error
Runtime error
Created test API
Browse files- app.py +3 -0
- requirements.txt +1 -0
- test_api.py +46 -0
app.py
CHANGED
@@ -6,6 +6,9 @@ import gradio as gr
|
|
6 |
from gradio import routes
|
7 |
import spacy # noqa
|
8 |
from typing import List, Type
|
|
|
|
|
|
|
9 |
|
10 |
TOKENS2INT_ERROR_INT = 32202
|
11 |
|
|
|
6 |
from gradio import routes
|
7 |
import spacy # noqa
|
8 |
from typing import List, Type
|
9 |
+
from dotenv import load_dotenv
|
10 |
+
|
11 |
+
load_dotenv()
|
12 |
|
13 |
TOKENS2INT_ERROR_INT = 32202
|
14 |
|
requirements.txt
CHANGED
@@ -2,3 +2,4 @@ spacy
|
|
2 |
pandas
|
3 |
pandas-gbq
|
4 |
gradio>=3.0.2,<3.1.0
|
|
|
|
2 |
pandas
|
3 |
pandas-gbq
|
4 |
gradio>=3.0.2,<3.1.0
|
5 |
+
python-dotenv
|
test_api.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""https://zetcode.com/python/concurrent-http-requests/"""
|
2 |
+
|
3 |
+
|
4 |
+
import asyncio
|
5 |
+
import random
|
6 |
+
import time
|
7 |
+
|
8 |
+
import httpx
|
9 |
+
|
10 |
+
local_url = "http://127.0.0.1:5000"
|
11 |
+
remote_url = "https://cetinca-mathtext-nlu.hf.space/run/text2int_preprocessed"
|
12 |
+
remote_url = "https://tangibleai-mathtext.hf.space/run/"
|
13 |
+
headers = {"Content-Type": "application/json; charset=utf-8"}
|
14 |
+
data_list = [
|
15 |
+
["one hundred forty five"],
|
16 |
+
["ninety nine"],
|
17 |
+
["seventy three"],
|
18 |
+
["one thousand seven hundred sixty nine"],
|
19 |
+
]
|
20 |
+
|
21 |
+
|
22 |
+
# async call to endpoint
|
23 |
+
async def call_api(url, _data_list, number):
|
24 |
+
data = random.choice(_data_list)
|
25 |
+
json = {"data": data, "fn_index": 1}
|
26 |
+
async with httpx.AsyncClient() as client:
|
27 |
+
begin1 = time.time()
|
28 |
+
begin2 = time.perf_counter() # Used perf_counter for more precise result.
|
29 |
+
# print(f"Call {number} started on: {start} text: {data}")
|
30 |
+
response = await client.post(url=url, headers=headers, json=json, timeout=30)
|
31 |
+
print(response.status_code)
|
32 |
+
end1 = time.time()
|
33 |
+
end2 = time.perf_counter()
|
34 |
+
return f"Call_{number}: start: {begin1} end: {end1} delay: {end1 - begin1} with_time: {end2 - begin2}\n"\
|
35 |
+
f"input_text: {data} result: {response.json().get('data')}"
|
36 |
+
|
37 |
+
|
38 |
+
async def main(n):
|
39 |
+
calls = []
|
40 |
+
for num in range(n):
|
41 |
+
calls.append(call_api(remote_url, data_list, num))
|
42 |
+
r = await asyncio.gather(*calls)
|
43 |
+
print(*r, sep="\n")
|
44 |
+
|
45 |
+
|
46 |
+
asyncio.run(main(1))
|