Spaces:
Runtime error
Runtime error
Commit
·
da2f1e3
1
Parent(s):
3044389
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,50 +1,36 @@
|
|
| 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
|
| 8 |
|
| 9 |
-
from utils import get_token
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 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 |
-
token = get_token()
|
| 20 |
-
url_node1 = os.environ["url_node1"]
|
| 21 |
-
url_node2 = os.environ["url_node2"]
|
| 22 |
-
url_node3 = os.environ["url_node3"]
|
| 23 |
-
url_list = [url_node1, url_node2, url_node3]
|
| 24 |
|
| 25 |
requests_json = {
|
| 26 |
-
"user_name": "huggingface",
|
| 27 |
"style": style,
|
| 28 |
"desc": desc
|
| 29 |
}
|
| 30 |
|
| 31 |
headers = {
|
| 32 |
"Content-Type": "application/json",
|
| 33 |
-
"X-Auth-Token": token
|
| 34 |
}
|
| 35 |
|
| 36 |
-
response = requests.post(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
response = json.loads(response.text)
|
| 38 |
-
status = response["status"]
|
| 39 |
-
assert status == 200
|
| 40 |
-
url_list = response["output_image_url"]
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
|
| 47 |
-
return
|
| 48 |
|
| 49 |
|
| 50 |
def read_content(file_path: str) -> str:
|
|
@@ -69,7 +55,7 @@ css = """
|
|
| 69 |
"""
|
| 70 |
|
| 71 |
# warm up
|
| 72 |
-
generate_figure("梵高", "一只猫"
|
| 73 |
|
| 74 |
with gr.Blocks(css=css) as demo:
|
| 75 |
gr.HTML(read_content("./header.html"))
|
|
@@ -116,7 +102,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 116 |
gr.Markdown("- Try [Wukong-Huahua model on the Foundation Models Platform for Mindspore]"
|
| 117 |
"(https://xihe.mindspore.cn/modelzoo/wukong)")
|
| 118 |
|
| 119 |
-
generate_button.click(
|
| 120 |
inputs=[style_input, desc_input],
|
| 121 |
outputs=[img_output1, img_output2, img_output3, img_output4])
|
| 122 |
|
|
|
|
| 1 |
import os
|
| 2 |
import requests
|
| 3 |
import json
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
from PIL import Image
|
| 6 |
from io import BytesIO
|
| 7 |
|
|
|
|
| 8 |
|
| 9 |
+
def generate_figure(style, desc):
|
| 10 |
+
url = os.environ["req_url"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
requests_json = {
|
|
|
|
| 13 |
"style": style,
|
| 14 |
"desc": desc
|
| 15 |
}
|
| 16 |
|
| 17 |
headers = {
|
| 18 |
"Content-Type": "application/json",
|
|
|
|
| 19 |
}
|
| 20 |
|
| 21 |
+
response = requests.post(url, json=requests_json, headers=headers, verify=False)
|
| 22 |
+
|
| 23 |
+
status = response.status_code
|
| 24 |
+
assert status == 201
|
| 25 |
+
|
| 26 |
response = json.loads(response.text)
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
url_dict = response["data"]["pictures"]
|
| 29 |
+
image_list = []
|
| 30 |
+
for k in url_dict:
|
| 31 |
+
image_list.append(Image.open(BytesIO(requests.get(url_dict[k]).content)))
|
| 32 |
|
| 33 |
+
return image_list
|
| 34 |
|
| 35 |
|
| 36 |
def read_content(file_path: str) -> str:
|
|
|
|
| 55 |
"""
|
| 56 |
|
| 57 |
# warm up
|
| 58 |
+
generate_figure("梵高", "一只猫")
|
| 59 |
|
| 60 |
with gr.Blocks(css=css) as demo:
|
| 61 |
gr.HTML(read_content("./header.html"))
|
|
|
|
| 102 |
gr.Markdown("- Try [Wukong-Huahua model on the Foundation Models Platform for Mindspore]"
|
| 103 |
"(https://xihe.mindspore.cn/modelzoo/wukong)")
|
| 104 |
|
| 105 |
+
generate_button.click(generate_figure,
|
| 106 |
inputs=[style_input, desc_input],
|
| 107 |
outputs=[img_output1, img_output2, img_output3, img_output4])
|
| 108 |
|