Gradio Tutorial

0. Foreword

Gradio Oficial Documents: https://www.gradio.app/docs/inetrface
Gradio github url: https://github.com/gradio-app/gradio

0.2 Note

The official documentation is far more detailed than this article, and is written only for my own convenience.
The link to the official document is shown in 0.1.

1. Translator demo

1.1 Using regular inference with pipeline

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import gradio as gr

from transformers import pipeline

pipe = pipeline("translation", model="Helsinki-NLP/opus-mt-en-zh")

def predict(text):
return pipe(text)[0]["translation_text"]

demo = gr.Interface(
fn=predict,
inputs='text',
outputs='text',
)

demo.launch()

1.2 Using Hugging Face Inference API

1
2
3
4
5
import gradio as gr

demo = gr.load("Helsinki-NLP/opus-mt-en-zh", src="models")

demo.launch()

2.


Gradio Tutorial
https://www.hardyhu.cn/2023/10/19/Gradio-Tutorial/
Author
John Doe
Posted on
October 19, 2023
Licensed under