# Day-28 OpenAI API 實作 part 3 ## 0. 前言 接下來今天要介紹一個套件叫做**Gradio**,在做即時的Demo時非常好用,在我們這個API小工具中是不可或缺的一部分,就讓我們開始吧! ## 1. Gradio Gradio用於快速構建交互式應用程序,特別是機器學習模型的交互式界面。它的優勢在於易用性,只需簡單定義輸入和輸出介面即可快速構建簡單的互動頁面。 ### 1.1. interface 在引入Gradio套件後,第一件事就是設定interface,這邊就講解最基礎的就好,之後就照著示範一步一步做就行。 - fn:包裝的函數 - inputs:輸入元件型別 - ouputs:輸出元件型別 - ... ### 1.2. 實作 1. 安裝套件 ``` !pip install gradio ``` 2. 定義一個函式 ``` def color(text): return text ``` 3. import ``` import gradio as gr ``` 4. interface ``` demo = gr.Interface( fn = color, inputs = "text", outputs = "text", title = "標題", description = "敘述", allow_flagging = "never" //此為消除flag按鈕的語法 ) demo.launch() ``` 5. 完成  ## 3. 結語 明天將會把之前的程式碼改寫為顏色產生器,最後會把Gradio與程式碼結合變成一個完整的工具,請拭目以待吧! --- [【OpenAI】1小時初學者教學-製作你的AI app](https://youtu.be/8GsLbNdbV6c?si=6287N7vmWwG-OFW7)
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.