#105 Gradio:简单易用的 Demo 工具(Web)

2023-03-04

今天了解到这个库,为一些演示工作的方便而开发。用 Python 来配置界面,主要是输入、输出,然后将输入的参数传入处理方法,将返回值显示在输出。
PS:安装的时候可以看到,这个库有 14M,而且其他的依赖不少。

这只是一个简单的示例:

import gradio as gr

def greet(name):
    return "Hello " + name + "!"

# demo = gr.Interface(fn=greet, inputs="text", outputs="text")
demo = gr.Interface(
    fn=greet,
    inputs=gr.Textbox(lines=2, placeholder="Name Here..."),
    outputs="text",
)
demo.launch()
python gradioTest.py
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.

20230304-gradio.png

以后需要用到这个的时候再来研究研究。

#104 Cygwin 下的时区问题

2023-02-24

Cygwin 下执行一个 Python 脚本,其中 datetime.now() 获取到的时间居然是 UTF 时间。
执行 date 命令也是如此。

执行 tzselect,三次分别选 Asia,China,Beijing Time,然后就好了。

命令中有提示:如果要永久有效,需要在 ~/.profile 中加入 TZ='Asia/Shanghai'

关键是,TZ 其实有配置:

export | grep TZ
declare -x TZ="Asia/Shanghai"

#102 Pytest setup 和 teardown 方法

2022-07-12
  • 全局
    • setup_module(module) / teardown_module(module) 引入包的时候执行
    • setup_function(function) / teardown_function(function)
  • 模块级别
    • setup() / teardown() 测试模块载入的时候执行
  • 类级别
    • setup_class(cls) / teardown_class(cls)
    • setup_method(self, method) / teardown_method(self, method)
    • setup(self) / teardown(self) nose 语法,会被上面两个方法覆盖

Supported nose Idioms

  • setup() and teardown() at module/class/method level: any function or method called setup will be called during the setup phase for each test, same for teardown.
  • SkipTest exceptions and markers
  • setup/teardown decorators
  • __test__ attribute on modules/classes/functions
  • general usage of nose utilities

#98 Poetry

2022-01-12

我研究了半天之后感觉无法掌握 poetry,决定放弃,还是用我的 Pipenv。

img

Poetry 是一个 Python 虚拟环境管理器。

#96 Python GIL 的最新动态

2021-10-22

开源中国上看到有人通过一些实验验证来视图说服 Python 核心团队移除 GIL,根据他的数据,移除 GIL 可以大幅提升多线程性能(19.8 倍)。

#93 Python 内置函数: hash

2021-10-01

一个不值一提的小问题:
有个地方使用 hash 方法来做哈希计算,将字符串转换成一个数值,但是发现改用 Python 3 之后,这个值每次运行都不一样了。