lwdragon commited on
Commit
eef6aa0
1 Parent(s): 49fa731

add luojianet

Browse files
__pycache__/obshandler.cpython-39.pyc ADDED
Binary file (1.82 kB). View file
 
__pycache__/utils.cpython-39.pyc ADDED
Binary file (811 Bytes). View file
 
app.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import requests
3
+ import json
4
+ import time
5
+ import gradio as gr
6
+
7
+ from utils import get_token
8
+ from obshandler import OBSHandler
9
+
10
+ url = os.environ["URL_NODE"]
11
+
12
+ obs = OBSHandler()
13
+
14
+
15
+ def detect_image(image):
16
+ print("image: ", image)
17
+
18
+ user_name = "huggingface"
19
+ upload_path = user_name + "/" + str(time.time()) + "/input.jpg"
20
+ obs.upload_file(upload_path, image)
21
+
22
+ token = get_token()
23
+
24
+ requests_json = {"file_path": upload_path}
25
+ headers = {"Content-Type": "application/json", "X-Auth-Token": token}
26
+ resp = requests.post(url,
27
+ json=requests_json,
28
+ headers=headers,
29
+ verify=False)
30
+ resp = json.loads(resp.text)
31
+ gen_url = resp["result"]
32
+ return gen_url
33
+
34
+
35
+ def read_content(file_path):
36
+ with open(file_path, 'r', encoding='utf-8') as f:
37
+ content = f.read()
38
+ return content
39
+
40
+
41
+ example_images = [
42
+ os.path.join(os.path.dirname(__file__), "examples/00.jpg"),
43
+ os.path.join(os.path.dirname(__file__), "examples/01.jpg"),
44
+ os.path.join(os.path.dirname(__file__), "examples/02.jpg"),
45
+ os.path.join(os.path.dirname(__file__), "examples/03.jpg"),
46
+ os.path.join(os.path.dirname(__file__), "examples/04.jpg"),
47
+ os.path.join(os.path.dirname(__file__), "examples/05.jpg")
48
+ ]
49
+
50
+ default_image = example_images[0]
51
+
52
+ css = """
53
+ .gradio-container {background-image: url('file=./background.jpg'); background-size:cover; background-repeat: no-repeat;}
54
+ """
55
+
56
+ # warm up
57
+ # detect_image()
58
+
59
+ with gr.Blocks(css=css) as demo:
60
+ gr.HTML(read_content("./header.html"))
61
+ gr.Markdown("# MindSpore Wuhan.LuoJiaNET")
62
+ gr.Markdown(
63
+ "`Wuhan.LuoJiaNET` is the first domestic autonomous and controllable machine learning framework for remote sensing in the field of remote sensing,"
64
+ " jointly developed by` Wuhan University` and `Huawei's Ascend AI team`, which has the characteristics of large image size,"
65
+ " multiple data channels, and large scale variation of remote sensing data."
66
+ " It is compatible with existing deep learning frameworks and provides a user-friendly,"
67
+ " drag-and-drop interactive network structure to build an interface."
68
+ " It can shield the differences between different hardware devices and manage a diversified remote sensing image sample library,"
69
+ " LuoJiaSET, to achieve efficient storage and management of remote multi-source sensing image samples."
70
+ )
71
+
72
+ with gr.Tab("目标识别 (Object Detection)"):
73
+ with gr.Row():
74
+ image_input = gr.Image(type="filepath",
75
+ value=default_image,
76
+ interactive=False)
77
+ image_output = gr.Image(type="filepath")
78
+
79
+ gr.Examples(
80
+ examples=example_images,
81
+ inputs=image_input,
82
+ )
83
+ image_button = gr.Button("Detect")
84
+
85
+ with gr.Accordion("Open for More!"):
86
+ gr.Markdown(
87
+ "- If you want to know more about the foundation models of MindSpore, please visit "
88
+ "[The Foundation Models Platform for Mindspore](https://xihe.mindspore.cn/)"
89
+ )
90
+ gr.Markdown(
91
+ "- If you want to know more about Wuhan.LuoJiaNET, please visit "
92
+ "[Wuhan.LuoJiaNET](https://github.com/WHULuoJiaTeam/luojianet)")
93
+ gr.Markdown(
94
+ "- Try [Wukong-LuojiaNET model on the Foundation Models Platform for Mindspore]"
95
+ "(https://xihe.mindspore.cn/modelzoo/luojia)")
96
+
97
+ image_button.click(detect_image,
98
+ inputs=[image_input],
99
+ outputs=[image_output])
100
+
101
+ demo.queue(concurrency_count=5)
102
+ demo.launch(enable_queue=True)
background.jpg ADDED
examples/00.jpg ADDED
examples/01.jpg ADDED
examples/02.jpg ADDED
examples/03.jpg ADDED
examples/04.jpg ADDED
examples/05.jpg ADDED
header.html ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div style="text-align: center; max-width: 1920px; margin: 0 auto;">
2
+ <div
3
+ style="
4
+ display: inline-flex;
5
+ gap: 0.8rem;
6
+ font-size: 1.75rem;
7
+ margin-bottom: 10px;
8
+ margin-left: 220px;
9
+ justify-content: center;
10
+ "
11
+ >
12
+ </div>
13
+ <div
14
+ style="
15
+ display: inline-flex;
16
+ align-items: center;
17
+ gap: 0.8rem;
18
+ font-size: 1.75rem;
19
+ margin-bottom: 10px;
20
+ justify-content: center;
21
+ ">
22
+ <a href="https://github.com/mindspore-ai/mindspore"><h1 style="font-weight: 900; align-items: center; margin-bottom: 7px;">
23
+ </h1></a>
24
+ </div>
25
+ <a href="https://github.com/mindspore-ai/mindspore"><img src="https://xihe.mindspore.cn/assets/modelzoo2.3fcf3c59.jpg" width="100%"></a>
26
+
27
+ </div>
obshandler.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import traceback
3
+
4
+ from obs import ObsClient
5
+ from obs import PutObjectHeader
6
+
7
+ AK = os.environ["OBS_AK"]
8
+ SK = os.environ["OBS_SK"]
9
+
10
+ ENDPOINT = os.environ["OBS_ENDPOINT"]
11
+ BUCKET_NAME = os.environ["BUCKET"]
12
+
13
+
14
+ class OBSHandler:
15
+ def __init__(self):
16
+ self.access_key = AK
17
+ self.secret_key = SK
18
+ self.endpoint = ENDPOINT
19
+ self.bucket_name = BUCKET_NAME
20
+ self.server = "https://" + self.endpoint
21
+ self.obsClient = self.init_obs()
22
+ self.maxkeys = 1000 # 查询的对象最大个数
23
+
24
+ # 初始化obs
25
+ def init_obs(self):
26
+ obsClient = ObsClient(access_key_id=self.access_key,
27
+ secret_access_key=self.secret_key,
28
+ server=self.server)
29
+ return obsClient
30
+
31
+ def close_obs(self):
32
+ self.obsClient.close()
33
+
34
+ def upload_file(self, dest, source):
35
+ response_msg = {'status': 200, 'msg': '单个对象上传成功'}
36
+ headers = PutObjectHeader()
37
+ headers.contentType = 'image/jpeg'
38
+ try:
39
+ resp = self.obsClient.putFile(self.bucket_name,
40
+ dest,
41
+ source,
42
+ headers=headers)
43
+
44
+ if resp.status < 300:
45
+ print("Upload image to obs successfully!")
46
+ else:
47
+ print('errorCode:', resp.errorCode)
48
+ print('errorMessage:', resp.errorMessage)
49
+ except Exception:
50
+ print(traceback.format_exc())
51
+ response_msg["status"] = -1
52
+ response_msg["msg"] = "单个对象上传失败"
53
+ print("Upload image to obs error!")
54
+ return response_msg
utils.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import requests
3
+
4
+
5
+ def get_token():
6
+ username = os.environ["USER_NAME"]
7
+ domain_name = os.environ["DOMAIN_NAME"]
8
+ domain_pwd = os.environ["DOMAIN_PWD"]
9
+ url = os.environ["IAM_URL"]
10
+
11
+ requests_json = {
12
+ "auth": {
13
+ "identity": {
14
+ "methods": ["password"],
15
+ "password": {
16
+ "user": {
17
+ "name": username,
18
+ "password": domain_pwd,
19
+ "domain": {
20
+ "name": domain_name
21
+ }
22
+ }
23
+ }
24
+ },
25
+ "scope": {
26
+ "project": {
27
+ "name": "cn-central-221"
28
+ }
29
+ }
30
+ }
31
+ }
32
+
33
+ headers = {
34
+ "Content-Type": "application/json"
35
+ }
36
+
37
+ response = requests.post(url, json=requests_json, headers=headers)
38
+
39
+ result = response.headers
40
+ print("token success")
41
+
42
+ return result['X-Subject-Token']
43
+
44
+
45
+ if __name__ == "__main__":
46
+ get_token()