HamzaNaser commited on
Commit
ea1fbb8
·
verified ·
1 Parent(s): c2d3401

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -3,6 +3,9 @@ import requests
3
  import time
4
 
5
 
 
 
 
6
  API_URL = "https://cm7kxsqi3sekfih7.us-east-1.aws.endpoints.huggingface.cloud"
7
  headers = {
8
  "Accept" : "application/json",
@@ -19,11 +22,20 @@ def query(payload):
19
 
20
 
21
  def run_model(text):
 
22
  output = query({
23
  "inputs": text,
24
  "parameters": {}
25
  })
26
- return output[0]['generated_text'] if output is not None else None
 
 
 
 
 
 
 
 
27
 
28
 
29
 
@@ -45,10 +57,7 @@ examples = [
45
 
46
  def mode_run(text):
47
  result = run_model(text)
48
- if result:
49
- return result
50
- else:
51
- return "Model is running please try again..."
52
 
53
 
54
  demo = gr.Interface(fn=mode_run,
 
3
  import time
4
 
5
 
6
+ trial = 0
7
+
8
+
9
  API_URL = "https://cm7kxsqi3sekfih7.us-east-1.aws.endpoints.huggingface.cloud"
10
  headers = {
11
  "Accept" : "application/json",
 
22
 
23
 
24
  def run_model(text):
25
+ global trial
26
  output = query({
27
  "inputs": text,
28
  "parameters": {}
29
  })
30
+ if output:
31
+ trial = 0
32
+ return output[0]['generated_text']
33
+ else:
34
+ trial += 1
35
+ if trial%2==1:
36
+ return 'Model is loading, please try again...'
37
+ else:
38
+ return 'Try one more time, it should work now...'
39
 
40
 
41
 
 
57
 
58
  def mode_run(text):
59
  result = run_model(text)
60
+ return result
 
 
 
61
 
62
 
63
  demo = gr.Interface(fn=mode_run,