drizzlezyk commited on
Commit
f829abc
1 Parent(s): 574e015

update for multi-node delivery

Browse files
Files changed (2) hide show
  1. app.py +15 -6
  2. utils.py +1 -2
app.py CHANGED
@@ -1,5 +1,7 @@
 
1
  import requests
2
  import json
 
3
  import gradio as gr
4
  from PIL import Image
5
  from io import BytesIO
@@ -7,9 +9,17 @@ from io import BytesIO
7
  from utils import get_token
8
 
9
 
10
- def generate_figure(style, desc):
11
- url = "https://a2f051d4cabf45f885d7b0108edc9b9c.infer.ovaijisuan.com/" \
12
- "v1/infers/975eedfd-6e15-4571-8ca9-b945da0da24b/wukong_hf"
 
 
 
 
 
 
 
 
13
 
14
  requests_json = {
15
  "user_name": "huggingface",
@@ -22,7 +32,7 @@ def generate_figure(style, desc):
22
  "X-Auth-Token": token
23
  }
24
 
25
- response = requests.post(url, json=requests_json, headers=headers, verify=False)
26
  response = json.loads(response.text)
27
  status = response["status"]
28
  assert status == 200
@@ -57,7 +67,6 @@ css = """
57
  border-radius: 8px;
58
  color: #26498B
59
  }
60
-
61
  """
62
 
63
  with gr.Blocks(css=css) as demo:
@@ -105,7 +114,7 @@ with gr.Blocks(css=css) as demo:
105
  gr.Markdown("- Try [Wukong-Huahua model on the Foundation Models Platform for Mindspore]"
106
  "(https://xihe.mindspore.cn/modelzoo/wukong)")
107
 
108
- generate_button.click(generate_figure,
109
  inputs=[style_input, desc_input],
110
  outputs=[img_output1, img_output2, img_output3, img_output4])
111
 
 
1
+ import os
2
  import requests
3
  import json
4
+ import random
5
  import gradio as gr
6
  from PIL import Image
7
  from io import BytesIO
 
9
  from utils import get_token
10
 
11
 
12
+ def deliver_request(style, desc):
13
+ number = random.randint(1, 90) % 3
14
+ print("node: ", number)
15
+ return generate_figure(style, desc, number)
16
+
17
+
18
+ def generate_figure(style, desc, number):
19
+ url_node1 = os.environ["url_node1"]
20
+ url_node2 = os.environ["url_node2"]
21
+ url_node3 = os.environ["url_node3"]
22
+ url_list = [url_node1, url_node2, url_node3]
23
 
24
  requests_json = {
25
  "user_name": "huggingface",
 
32
  "X-Auth-Token": token
33
  }
34
 
35
+ response = requests.post(url_list[number], json=requests_json, headers=headers, verify=False)
36
  response = json.loads(response.text)
37
  status = response["status"]
38
  assert status == 200
 
67
  border-radius: 8px;
68
  color: #26498B
69
  }
 
70
  """
71
 
72
  with gr.Blocks(css=css) as demo:
 
114
  gr.Markdown("- Try [Wukong-Huahua model on the Foundation Models Platform for Mindspore]"
115
  "(https://xihe.mindspore.cn/modelzoo/wukong)")
116
 
117
+ generate_button.click(deliver_request,
118
  inputs=[style_input, desc_input],
119
  outputs=[img_output1, img_output2, img_output3, img_output4])
120
 
utils.py CHANGED
@@ -6,8 +6,7 @@ def get_token():
6
  username = os.environ["username"]
7
  domain_name = os.environ["domain_name"]
8
  domain_pwd = os.environ["domain_pwd"]
9
-
10
- url = "https://iam.cn-central-221.myhuaweicloud.com/v3/auth/tokens"
11
 
12
  requests_json = {
13
  "auth": {
 
6
  username = os.environ["username"]
7
  domain_name = os.environ["domain_name"]
8
  domain_pwd = os.environ["domain_pwd"]
9
+ url = os.environ["token_url"]
 
10
 
11
  requests_json = {
12
  "auth": {