-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
42 lines (26 loc) · 1.42 KB
/
index.html
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
38
39
40
41
42
<html>
<head>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.0/brython.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.0/brython_stdlib.min.js"></script>
</head>
<body onload="brython()">
<script type="text/python">
from browser import document, alert, ajax
from json import dumps, loads
URL = "https://tech.notai.tech/deepsegment/en/async?api_key=FSOY9tnEJmPG9yB765RcXJFUpCoLQ2VLnlFWoUtb"
def show_result(req):
alert(req.text)
def get_result_from_unique_id(req):
unique_id = loads(req.text)['unique_id']
print(f"UNIQUE_ID: {unique_id}", URL)
ajax.post(URL.replace('/async', '/result'), data=dumps({"unique_id": unique_id}), headers={'content-type': 'application/json'}, blocking=True, oncomplete=show_result)
def get_and_display_result(url, in_dict):
ajax.post(url, data=dumps(in_dict), headers={'content-type': 'application/json'}, blocking=True, oncomplete=get_result_from_unique_id)
def echo(event):
text = document["Submit"].value
get_and_display_result(URL, {"data": [text]})
document["submit_button"].bind("click", echo)
</script>
<input id="Submit"><button id="submit_button">click !</button>
</body>
</html>