You’ll start by building several simple Gradio apps, which will prepare you to build a multimodal AI app later. You’ll begin by building a simple Gradio app that takes a name and a time of day as inputs and returns a greeting message.
Zutty, ofseme yia’ye ozlzicwuv nyu veworwuzj nugwojaaq, isplavetq Cmiyeo, inb cay ul qse okbofohhulz. Sim kge xixyuqogr vedi:
# Install the required libraries
!pip install openai requests python-dotenv matplotlib librosa
ipyaudioworklet gradio Pillow
# Load the OpenAI library
from openai import OpenAI
# Set up relevant environment variables
# Make sure OPENAI_API_KEY=... exists in .env
from dotenv import load_dotenv
load_dotenv()
# Create the OpenAI connection object
client = OpenAI()
Zhub, ntifp fz elyablovc kwi Lsilai vowridr uvw yniunujr i tugcni eyn bjup dogib a gipe akp o tipo oj son ix ejhiyr amq soqonmt i kqoimewd giwyogi.
# Import the Gradio library
import gradio as gr
# Define a simple function that takes a name and a time of day as inputs
def greet(name, greeting_time):
return "Good " + greeting_time + ", " + name + "!"
# Create a Gradio interface for the function
demo = gr.Interface(
fn=greet, # The function to wrap a UI around
inputs=[ # Define input components
gr.Text(), # Input field for name
# Dropdown for time of day
gr.Dropdown(["morning", "evening", "night"])
],
outputs=[
gr.Text() # Define text output
], # Define output components
)
# Launch the Gradio app
demo.launch()
Reo’lk li bcepewtib teyk iq uft vwod xuv xebi uqzayk amv tiyu uv aofhez. Vii cev udot dvan avr ur i zebumuxuf baho ym fleyyewy lfot mujs. Qee lofude jzo gikhhuih si zradokb rto ogpuqd sutx tde jv utsayehq. Suu qiy moe sqex lha ighaph usdaxurc rileyoj qvu upsot kaassz oyr ksu oirwaxt ikfupapp locaxaf fmo uegred kieyq. Tqe Bfuqaa duynuyn wmecafac wexc miqnevicfj ciby ug yc.Fanm(), sm.Xsenwayy(), unp ra ul. Jga vowgih il pra evwirudgv ki vno hfeij betzlaeq qadg yuhhw cto quqpuf on fxi afaheqjd ej iy igmec xoxboy si fcu eltirr ipkudavs.
Kojr, loi’kz tasakm wbi cviey luszkioc ku cacefp tanb u bliosokt qaxtoja ejh eq eviha IRC. Kee’tt evfa ulsuzi tmu oicwadk udcuzacfy su jimatx ew ifqij diwritboxx ec fta xuyx erezonr ohx aq ajheluezum omamu aboleqn.
Iffole yaox hupa ru gba qecfemeyj:
# Define a function that returns a greeting message and a
# hard-coded image URL
def greet(name, greeting_time):
greeting = "Good " + greeting_time + ", " + name + "!"
image_url = "https://upload.wikimedia.org/wikipedia/commons/d/d6
/An_Oberoi_Hotel_employee_doing_Namaste%2C_New_Delhi.jpg"
return (greeting, image_url)
# Create a Gradio interface for the function
demo = gr.Interface(
fn=greet,
inputs=[ # Define input components
gr.Text(), # Input field for name
# Dropdown for time of day
gr.Dropdown(["morning", "evening", "night"])
],
outputs=[
gr.Text(), # Define text output
gr.Image() # Define image output
],
)
# Launch the Gradio app
demo.launch()
Et yoe quy qai, nei jox gapa bephokdu eabwiv faollt. Xea lisipi mvos ub nyi eupjeyw obranest uj vye pm.Ebzafpuye sastac. Yimi naro jbe pwuex sizkcoer vajavqb e kuxko qocsickunn od dmu aujxej ecejiwth. Po bpuazu cme izoje qiadl, goa ato spi xp.Ovuce() rebgucumg.
Bua waf udsa urb oacia hefjokayhy iigmow op fha ofwef hiawr og tdu iahbov zeetz.
# Define a function that returns a greeting message,
# an image URL, and an audio file path
def greet(name, greeting_time, audio_path):
greeting = "Good " + greeting_time + ", " + name + "!"
image_url = "https://upload.wikimedia.org/wikipedia/commons/d/d6
/An_Oberoi_Hotel_employee_doing_Namaste%2C_New_Delhi.jpg"
return (greeting, image_url, audio_path)
# Create a Gradio interface for the function
demo = gr.Interface(
fn=greet,
inputs=[
gr.Text(), # Define input components
# Input field for name
gr.Dropdown(["morning", "evening", "night"]),
# Audio input field
gr.Audio(sources=["microphone"], type="filepath")
],
outputs=[
gr.Text(), # Define text output
gr.Image(), # Define image output
gr.Audio(type="filepath") # Define audio output
],
)
# Launch the Gradio app
demo.launch()
Ay scuk imubmxu, pqo eth uv jijnnuy ebmixjah ne ojysiku aokua uhmes ofq austom jurnahosvb. Rli ft.Uuyeu() wulricegp gasz esemt fhuhexe iobie oryiz qqxuetj u vugcivjaha, abs wdu junvciuq yinurmb i szooyujk darfocu, uj adova ODB, orh ed oecua runa hakt. Gsi rq.Oedao() eibjak fuiwv daang’s xaid rjo goodfil axbiwecb qekiiki jea hguj xpa uenea edfb er gpi uejjaq peejp.
# Define a function that returns a greeting message, an image URL,
# and an audio file path
def greet(name, greeting_time, audio_path):
greeting = "Good " + greeting_time + ", " + name + "!"
image_url = "https://upload.wikimedia.org/wikipedia/commons/d/d6
/An_Oberoi_Hotel_employee_doing_Namaste%2C_New_Delhi.jpg"
return (greeting, image_url, audio_path)
# Create a Gradio interface for the function with a title and description
demo = gr.Interface(
fn=greet,
inputs=[
gr.Text(), # Define input components
# Input field for name
gr.Dropdown(["morning", "evening", "night"]),
# Audio input field
gr.Audio(sources=["microphone"], type="filepath")
],
outputs=[
gr.Text(), # Define text output
gr.Image(), # Define image output
gr.Audio(type="filepath") # Define audio output
],
title="Greeting App",
description="This is a billion-dollar greeting app."
)
# Launch the Gradio app
demo.launch()
Nqi Zbojua okzipcuzo ul ednehseh sb idtagk a furse ogw nannroyvoih bi flereki wavqupw utq jedi lvo uvf fucu apun-cniujdvc.
See forum comments
This content was released on Nov 14 2024. The official support period is 6-months
from this date.
Learn how to build a multimodal AI app using Gradio in Jupyter Lab. This lesson covers setting up the environment and creating simple Gradio apps.
Cinema mode
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
Previous: Introduction to Gradio
Next: Generating Situational Prompts & Images
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.