gradio交互式界面部署

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 threading

model_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 result

iface = 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/
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值