python3写一个http接口服务(UI界面), 给别人调用4
一、概述
还尝试了一下pywebio, 好像是国内的个人项目, github上有3.2star。
官网上说:
PyWebIO提供了一系列命令函数,用于获取用户在浏览器上的输入和输出,将浏览器变成“富文本终端”,
并可用于构建简单的web应用程序或基于浏览器的GUI应用程序,而无需了解HTML和JS。
PyWebIO还可以轻松集成到现有的Web服务中。PyWebIO非常适合快速构建不需要复杂UI的应用程序。
二、使用感受
比较简单, 安转依赖少, 就是界面样式可能不是想要的, 尤其是需要输入输出的时候(页面跳转了)。
样例github地址: https://github.com/yongzhuo/web-demo)
三、pywebio简单demo样例
# -*- coding: UTF-8 -*-
# !/usr/bin/python
# @time :2022/7/16 21:56
# @author :Mo
# @function :demo of pywebio
from pywebio.input import input, TEXT, FLOAT, input_update, input_control, textarea
from pywebio.output import put_text, put_tabs, put_table, put_file, put_code
from pywebio import start_server
def cal_jaccard():
sen_1 = input("请输入第一个句子:", type=TEXT)
sen_2 = input("请输入第二个句子:", type=TEXT)
try:
sent_intersection = list(set(list(sen_1)).intersection(set(list(sen_2))))
sent_union = list(set(list(sen_1)).union(set(list(sen_2))))
score_jaccard = round(float(len(sent_intersection) / len(sent_union)), 6)
except:
score_jaccard = 0.0
res = {
"result": score_jaccard}
data = {
"code": 200, "data": res, "message": "success"}
# put_text(data)
put_text(data)
if __name__ == '__main__':
start_server(cal_jaccard, port=8832)
"""
1.启动
python demo.py
2.访问
地址: http://localhost:8832
请输入第一个句子:你是谁呀
请输入第二个句子:你叫什么
关闭似乎很慢
"""
四、启动方式
python demo.py
五、界面效果展示
访问: http://localhost:8832/
5.1 nlp-demo
六、参考
- PyWebIO的github地址: https://github.com/pywebio/PyWebIO