1. Gradio

import gradio

demo = gradio.Interface(fn=function, inputs=[a, b, **], outputs=[c, d, **])
# def function(a, b, **):
#     pass
#     return c, d, **

# demo.launch()
demo.launch(server_name="0.0.0.0", server_port=8899, share=True, 
						auth=("username", "password"))

Untitled

1.1 例1 Hello World

import gradio as gr

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

demo = gr.Interface(fn=greet, inputs="text", outputs="text")

demo.launch()

Untitled

1.2 例2 使用部件

import gradio as gr

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

demo = gr.Interface(
    fn=greet,
    inputs=gr.Textbox(lines=2, placeholder="Name Here..."),
    outputs="text",
)
demo.launch()

Untitled

使用文件

def file_test_fn_file(file_tmp):
    file_path = file_tmp.name
    print(file_path)
    with open(file_path, 'r') as file:
        file_content = file.read()
    return file_content

Then

msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
        bot, chatbot, chatbot
    )

Change

Run this event 'every' number of seconds while the client connection is open. Interpreted in seconds. Queue must be enabled.

period.change(get_plot, period, plot, every=1, cancels=[dep])

Select(Event listener)

需要EventData支持

def on_select_load_history(evt: gr.SelectData, files):
    print("=" * 20 + "run_text" + "=" * 20)
    # print("inputs:", text, state)
    text = file_test_fn_file(files[evt.index])