赞
踩
Gradio UI应用转化调用的API接口,
1、Flask Web库框架创建一个API服务器。
2、下面是一个简单的代码示例:
- from flask import Flask, jsonify, request
- import gradio as gr
-
- app = Flask(__name__)
-
- # define your Gradio interface function
- def say_hello(name):
- return "Hello, {}".format(name)
-
- # define your API endpoint
- @app.route('/api/say_hello', methods=['POST'])
- def api_say_hello():
- data = request.get_json()
- name = data['name']
- result = say_hello(name)
- return jsonify(result=result)
-
- # run the server
- if __name__ == '__main__':
- gr.Interface(fn=say_hello, inputs="text", outputs="text").launch()
- app.run(debug=True)

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。