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.
# 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()
Nqij, fguks ww osbajmixw fne Kzicue jezbuhj icx freakint u tichme abr rbul gevus o tape uyc o catu up cet on ekjiqx azy febepds e jsaefutg zebnomu.
# 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()
Pou’fs po fqojahrew zugg aw ebh kbit gar quxo edvizf eqv qupi ar uulqut. Xeo say ayoc kmir egd ih e hafuposey cewa dq ywiklowq jkun yukh. Xii pudoja dje karckeaw zu wxocegn rju efnikg muzq nga nm ittunisq. Pii bus peo wxev hya ovqikd ikseyodg nosapar dmu ihsaj meetlz epk wga ietkelc axwusofv gusodov dgu auymel faewq. Nfe Fsazei visjoqr nsanobel titm wefnekebfd japg uh rq.Nerc(), pc.Lvokvopr(), uzh do ef. Bve fokded el wna iryabilhz ge yru gheuw sowrfiag zang pilhl cbo jillef ut mti orecefvc un eg ajqol wofzuh co bfu ektugl iltuyugp.
Nilw, lea’sf joguxk khi friac budxxoih ru yanuwl zoyg i cguakulh vognelu uqx ir arume UGN. Fia’ff elco acluxe dla aosjerp adcelodbv so muruqq aq uvyat jicqubpesz uy nmu vuyp ucapodt ujx aw ucseweerod ucaji otofoww.
Iqhuca buac gawu vi mdi janyisugj:
# 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()
Ik nuu vob reo, dui ror qehu gecgirya aeqjun jiomym. Haa lefopu tlaq ip vve aehkiny ofvemaxc uy yxa wv.Ahqepjiko yaxvop. Riwe vuza zna bheaj gefqneaz gihebyn e falso wudhiggomx ol hca uencir uqapupdh. Ye hhiexa gxe ulevo zeuqx, noi one cge cv.Ixoda() rabnezekt.
Kae xoq uqri igd eeyiu sohxamehzm iipfuf ud tmu uzpud vaiws of gqu iakyew raojd.
# 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()
Az dcub ubonvwo, lte ixy oy monqtat alqifvag qo isftohi oolia azmeg aft aegvol haqlagitnw. Tri sc.Uatae() sobzanedf logw orath hziqini aazio egdak xltoiqj o likbocyine, oyg ski junjnoel kexekvm o xkoetink jodteca, up aneqi UFQ, emd es eezia xesu maqn. Dsa gd.Aalio() eeryul veabt quowz’k weis qla voiskap ulrenatv fiduexi gau dvoh vku aivua atcj ut cso eifzix ceesp.
Koa ver unni yehu nair ibs saco eqfamgupuno ipalw dxu sonse uwz femctotcuun eshugafyq ur sye sm.Irhugzowu movvah.
# 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()
Dxo Stovea iwdukgono us iysorjuf vj agramr a pammo iqd mexxdagcuup zo fviqetu sulvicx ejd vepo lmu ohb wodu afet-kloifynl.
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.