Upload app.py
Browse files
app.py
CHANGED
@@ -3,8 +3,7 @@ import requests
|
|
3 |
import time
|
4 |
|
5 |
|
6 |
-
|
7 |
-
|
8 |
|
9 |
API_URL = "https://cm7kxsqi3sekfih7.us-east-1.aws.endpoints.huggingface.cloud"
|
10 |
headers = {
|
@@ -13,29 +12,28 @@ headers = {
|
|
13 |
}
|
14 |
|
15 |
def query(payload):
|
|
|
16 |
response = requests.post(API_URL, headers=headers, json=payload)
|
17 |
if response.status_code != 200:
|
18 |
print('Sleeping due to API error')
|
19 |
-
time.
|
|
|
20 |
return None
|
21 |
return response.json()
|
22 |
|
23 |
|
24 |
def run_model(text):
|
25 |
-
global
|
26 |
output = query({
|
27 |
"inputs": text,
|
28 |
"parameters": {}
|
29 |
})
|
30 |
if output:
|
31 |
-
|
32 |
return output[0]['generated_text']
|
33 |
else:
|
34 |
-
|
35 |
-
|
36 |
-
return 'Model is loading, please try again...'
|
37 |
-
else:
|
38 |
-
return 'Try one more time, it should work now...'
|
39 |
|
40 |
|
41 |
|
|
|
3 |
import time
|
4 |
|
5 |
|
6 |
+
hold_time = time.time()
|
|
|
7 |
|
8 |
API_URL = "https://cm7kxsqi3sekfih7.us-east-1.aws.endpoints.huggingface.cloud"
|
9 |
headers = {
|
|
|
12 |
}
|
13 |
|
14 |
def query(payload):
|
15 |
+
global hold_time
|
16 |
response = requests.post(API_URL, headers=headers, json=payload)
|
17 |
if response.status_code != 200:
|
18 |
print('Sleeping due to API error')
|
19 |
+
if (time.time() - hold_time) > 60:
|
20 |
+
hold_time = time.time()
|
21 |
return None
|
22 |
return response.json()
|
23 |
|
24 |
|
25 |
def run_model(text):
|
26 |
+
global hold_time
|
27 |
output = query({
|
28 |
"inputs": text,
|
29 |
"parameters": {}
|
30 |
})
|
31 |
if output:
|
32 |
+
hold_time = 1
|
33 |
return output[0]['generated_text']
|
34 |
else:
|
35 |
+
return f'Model is being loaded, please try again in {int((hold_time - time.time()) + 35)} seconds.'
|
36 |
+
|
|
|
|
|
|
|
37 |
|
38 |
|
39 |
|