Introduction to Gradio

Gradio App gives the models trained by AI algorithm engineers the ability to share them with the public.

Split from the technical side, it consists of three parts:

Front-end page + back-end interface + AI algorithm model reasoning

One thing Gradio has done is to encapsulate these three parts into a python interface. By implementing its encapsulated interface, users can display their trained algorithm models to the public in the form of web services.

1. A simple gradient program

This example comes from the official website Gradio

import gradio as gr
def sketch_recognition(img):
    pass# Implement your sketch recognition model here...

gr.Interface(fn=sketch_recognition, inputs="sketchpad", outputs="label").launch()

The user uses the mouse to draw a simple drawing on the interactive interface, and the backend gives its classification.

It can be seen that gr.Interface().lanuch() combines the front-end page, back-end service and AI algorithm model into one interface, which greatly reduces the difficulty of implementing the algorithm model, making it possible for AI algorithm engineers who do not have the With engineering capabilities, you can also quickly deploy front-end and back-end and provide services.

2. Installation

pip install gradio

3. Hello World

The beginning of learning always begins with outputting "hello world", and this is no exception.

import gradio as gr

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

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

demo.launch()

After the above code is run, http// localhost:7860the browser pops up on:

Insert image description here

Enter the corresponding name on the left, and there is program-based output on the right:

Insert image description here

references

Practical deployment of Gradio app based on Kubernetes - Nuggets 

Gradio implements algorithm visualization_uncle_ll's blog-CSDN blog 

Guess you like

Origin blog.csdn.net/xhtchina/article/details/130175013