stevez commited on
Commit
761ae49
·
1 Parent(s): d877f5a
Files changed (1) hide show
  1. app.py +39 -38
app.py CHANGED
@@ -2,50 +2,51 @@ import requests
2
  import json
3
  from datetime import datetime
4
 
5
- import gradio
6
  from gradio_client import Client
7
 
8
- function_list1 = [
9
- "angry birds",
10
- 'snake',
11
- "greet",
12
- "list AI backend functionality",
13
- "show json",
14
- "game"
15
- # "flappy birds",
16
  ]
17
- function_list1 = [
18
- "angry birds",
 
19
  'snake',
20
  ]
21
- function_list2 = [
22
- "greet",
 
23
  "list AI backend functionality",
24
  "show json",
25
- "game"
26
- # "flappy birds",
27
  ]
28
- # function_list.pop()
29
 
30
- space = 'stevez-abc123'
31
  # space = 'stevez-test-public'
32
 
33
  # url = f'https://{space}.hf.space/run/predict'
34
  # url = f'https://{space}.hf.space/api/predict'
35
  url = f'https://{space}.hf.space'
36
 
37
- def run(hf_token, game, r, nlp_command):
38
  if hf_token is None or hf_token == '':
39
  return 'please specify hf token'
40
- if game is None:
41
- return "please specify which game"
42
- if r is None:
43
- return "please choose the AI functionality"
 
 
 
 
 
 
44
  try:
45
  print(f"{datetime.today()}\t{nlp_command}")
46
- myobj = {
47
- 'data': [game, r, nlp_command],
48
- }
49
  # myauth = ('Bearer', hf_token)
50
  # x = requests.post(
51
  # url,
@@ -61,7 +62,7 @@ def run(hf_token, game, r, nlp_command):
61
  hf_token=hf_token,
62
  )
63
  res = client.predict(
64
- r, nlp_command,
65
  api_name='/predict',
66
  )
67
  res2 = json.loads(res[0])
@@ -72,22 +73,22 @@ def run(hf_token, game, r, nlp_command):
72
  except Exception as e:
73
  return f"{type(e)}, {str(e)}. \nyou many want to make sure your hf_token is correct"
74
 
75
- demo = gradio.Interface(
76
  fn=run,
77
  inputs=[
78
  "text",
79
- gradio.Radio(
80
- function_list1,
81
- value='angry birds',
82
- label = "Which game?",
83
- # info = "Greet for testing server",
84
- info = "Only 'angry birds' is implemented as of now",
 
85
  ),
86
- gradio.Radio(
87
- function_list2,
88
- value='game',
89
- label = "What do you want to do?",
90
- info = "Greet for testing server",
91
  ),
92
  "text"],
93
  outputs="text",
 
2
  import json
3
  from datetime import datetime
4
 
5
+ import gradio as gr
6
  from gradio_client import Client
7
 
8
+ functionality_shared = [
9
+ 'games',
10
+ 'greet',
11
+ 'tokenization',
 
 
 
 
12
  ]
13
+
14
+ game_list = [
15
+ 'angry birds',
16
  'snake',
17
  ]
18
+
19
+ functionality_list = [
20
+ "AI",
21
  "list AI backend functionality",
22
  "show json",
 
 
23
  ]
 
24
 
25
+ space = 'stevez-bbc123'
26
  # space = 'stevez-test-public'
27
 
28
  # url = f'https://{space}.hf.space/run/predict'
29
  # url = f'https://{space}.hf.space/api/predict'
30
  url = f'https://{space}.hf.space'
31
 
32
+ def run(hf_token, service, game, r, nlp_command):
33
  if hf_token is None or hf_token == '':
34
  return 'please specify hf token'
35
+
36
+ if service not in functionality_shared[1:]:
37
+ if game is None:
38
+ return "please specify which game"
39
+ if r is None:
40
+ return "please choose the AI functionality"
41
+ if r == 'game':
42
+ if nlp_command in ["", None]:
43
+ return "please make sure the command is not empty"
44
+
45
  try:
46
  print(f"{datetime.today()}\t{nlp_command}")
47
+ # myobj = {
48
+ # 'data': [service, game, r, nlp_command],
49
+ # }
50
  # myauth = ('Bearer', hf_token)
51
  # x = requests.post(
52
  # url,
 
62
  hf_token=hf_token,
63
  )
64
  res = client.predict(
65
+ service, game, r, nlp_command,
66
  api_name='/predict',
67
  )
68
  res2 = json.loads(res[0])
 
73
  except Exception as e:
74
  return f"{type(e)}, {str(e)}. \nyou many want to make sure your hf_token is correct"
75
 
76
+ demo = gr.Interface(
77
  fn=run,
78
  inputs=[
79
  "text",
80
+ gr.Radio(
81
+ functionality_shared,
82
+ info = "Shared services",
83
+ ),
84
+ gr.Radio(
85
+ game_list,
86
+ info = "Which game you want the AI to support?",
87
  ),
88
+ gr.Radio(
89
+ functionality_list,
90
+ # label = "What do you want to do?",
91
+ info = "What functionality?",
 
92
  ),
93
  "text"],
94
  outputs="text",