Spaces:
Sleeping
Sleeping
| import os | |
| import requests | |
| import gradio as gr | |
| url = os.environ["URL_NODE"] | |
| def detect_image(image): | |
| print("image: ", image) | |
| files = {"picture": open(image, "rb")} | |
| resp = requests.post(url, | |
| files=files, | |
| verify=False) | |
| resp = resp.json() | |
| gen_url = resp["data"]["answer"] | |
| return gen_url | |
| def read_content(file_path): | |
| with open(file_path, 'r', encoding='utf-8') as f: | |
| content = f.read() | |
| return content | |
| example_images = [ | |
| os.path.join(os.path.dirname(__file__), "examples/00.jpg"), | |
| os.path.join(os.path.dirname(__file__), "examples/01.jpg"), | |
| os.path.join(os.path.dirname(__file__), "examples/02.jpg"), | |
| os.path.join(os.path.dirname(__file__), "examples/03.jpg"), | |
| os.path.join(os.path.dirname(__file__), "examples/04.jpg"), | |
| os.path.join(os.path.dirname(__file__), "examples/05.jpg"), | |
| os.path.join(os.path.dirname(__file__), "examples/06.png") | |
| ] | |
| default_image = example_images[0] | |
| css = """ | |
| .gradio-container {background-image: url('file=./background.jpg'); background-size:cover; background-repeat: no-repeat;} | |
| """ | |
| # warm up | |
| # detect_image() | |
| with gr.Blocks(css=css) as demo: | |
| gr.HTML(read_content("./header.html")) | |
| gr.Markdown("# MindSpore Wuhan.LuoJiaNET") | |
| gr.Markdown( | |
| "`Wuhan.LuoJiaNET` is the first domestic autonomous and controllable machine learning framework for remote sensing in the field of remote sensing," | |
| " jointly developed by` Wuhan University` and `Huawei's Ascend AI team`, which has the characteristics of large image size," | |
| " multiple data channels, and large scale variation of remote sensing data." | |
| " It is compatible with existing deep learning frameworks and provides a user-friendly," | |
| " drag-and-drop interactive network structure to build an interface." | |
| " It can shield the differences between different hardware devices and manage a diversified remote sensing image sample library," | |
| " LuoJiaSET, to achieve efficient storage and management of remote multi-source sensing image samples." | |
| ) | |
| with gr.Tab("目标识别 (Object Detection)"): | |
| with gr.Row(): | |
| image_input = gr.Image( | |
| type="filepath", | |
| value=default_image | |
| ) | |
| image_output = gr.Image( | |
| type="filepath", | |
| interactive=False | |
| ) | |
| gr.Examples( | |
| examples=example_images, | |
| inputs=image_input, | |
| ) | |
| image_button = gr.Button("Detect") | |
| with gr.Accordion("Open for More!"): | |
| gr.Markdown( | |
| "- If you want to know more about the foundation models of MindSpore, please visit " | |
| "[The Foundation Models Platform for Mindspore](https://xihe.mindspore.cn/)" | |
| ) | |
| gr.Markdown( | |
| "- If you want to know more about Wuhan.LuoJiaNET, please visit " | |
| "[Wuhan.LuoJiaNET](https://github.com/WHULuoJiaTeam/luojianet)") | |
| gr.Markdown( | |
| "- Try [Wukong-LuojiaNET model on the Foundation Models Platform for Mindspore]" | |
| "(https://xihe.mindspore.cn/modelzoo/luojia)") | |
| image_button.click(detect_image, | |
| inputs=[image_input], | |
| outputs=[image_output]) | |
| demo.queue(concurrency_count=5) | |
| demo.launch(enable_queue=True) |