import os import requests import json import time import gradio as gr from utils import get_token from obshandler import OBSHandler url = os.environ["URL_NODE"] obs = OBSHandler() def detect_image(image): print("image: ", image) user_name = "huggingface" upload_path = user_name + "/" + str(time.time()) + "/input.jpg" obs.upload_file(upload_path, image) token = get_token() requests_json = {"file_path": upload_path} headers = {"Content-Type": "application/json", "X-Auth-Token": token} resp = requests.post(url, json=requests_json, headers=headers, verify=False) resp = json.loads(resp.text) gen_url = resp["result"] 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") ] 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, interactive=False) image_output = gr.Image(type="filepath") 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)