gradio交互式界面部署
示例:http://xxxxx:1111/api/v1/my_model 为模型服务api,传入参数为:
{"company": company,"name": name,"t_date": t_date,"amount": amount,"img1_path": img1_path,"img2_path": img2_path
}
1. gradio app
# -*- coding: utf-8 -*-import gradio as gr
import requests
import json
import os
import requests
import json
import threadingmodel_url = "http://xxxxx:1111/api/v1/my_model"
headers = {'Content-Type': 'application/json'
}def func(url_1, url_2, company, name, amount, t_date):name1 = "img1.jpg"name2 = "img2.jpg"# 存储第一张图片if url_1:img1_path = os.path.join('/home/.../gradio-test', name1)url_1.save(img1_path)# 存储第二张图片if url_2:img2_path = os.path.join('/home/.../gradio-test', name2)url_2.save(img2_path)payload = json.dumps({"company": company,"name": name,"t_date": t_date,"amount": amount,"img1_path": img1_path,"img2_path": img2_path})response = requests.request("POST", model_url, headers=headers, data=payload)result = json.loads(response.text)#["data"]return resultiface = gr.Interface(fn=func,inputs=[gr.Image(label="xxxxxx图片",type="pil"),gr.Image(label="xxx图片",type="pil"),gr.Textbox(label="公司名称"),gr.Textbox(label="姓名"),gr.Textbox(label="金额"),gr.Textbox(label="日期"),# gr.Slider(minimum=1, maximum=10, label="距离限制")],outputs=gr.JSON(label="结果")
)iface.launch(share=True,server_port=8766,inbrowser=True,server_name = "0.0.0.0")
2. 启动服务
nohup python app.py >> log.log 2>&1 &
3. 打开页面
打开网址:http://xxxx:8766/