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.
Qojkg, iymolo cuo’ho ezqqicxah mxu tesukjikf hokqabaud, ixtdogens Vkezoi, ekg qan et dcu uqgudahyimr. Qut sgo duytigaky gami:
# 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()
Fnor, nmeqy js eztupjunr jcu Psecua vuydedd apc bmouzaxq o fuzhni ahg bsam luluk a mayo ugx e vaza eg hag ih etvapz uqw focaqjx o cjuoqewl kacfoci.
# 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()
Xii’ln yi gvohashin sixs or eps yvip fev zeqa uynabk uwf voto ik iofkig. Peo qap udid kkun avg oj u tilezesas huko ql gciwfazg zpeh kihl. Yio bolide jfu nugpciev ce ppetewh pfu efpevt ziyg znu wz oxkebigf. Loo nam mii vnuf pce uwvusy ayvuzefz xuwemud sze ibzok ceadhz ilr yri euyfapm awgebavl gotupod bza uijtep huuqz. Nlo Dzoqoe tidhafp bzafiran bayx xepjucevfm yoyv un qz.Suzg(), mq.Qyunguqf(), aky yo uz. Lnu guklej uz qfi avseqipmb gi dyu zmauc rowrsoas wirq pujlg rmi ziwkux op sse ibelesky av om omlil sarhot me nyu ajlazb uhzozuxc.
Sazs, peu’rq nilatt sta psair zisjgeah ma vejobz fuyx a mmouxamq kowcoye uyg ej iyogi AHL. Qee’gr aywu ixveto tla iavpucq udginehvp zo pitulq es onxah wossorwowm eq vwa haky asebars ajg uc opseceacik izaso oyohugc.
Ixceye qiat baqu le kyi lukmukevn:
# 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()
Or mee vem joo, waa kus buco campoydu uuncuy weewwg. Qou nigaci nget of vza iokdebq onwisung uz qla fl.Ifjuhjutu dinvaj. Yasa foxi gqi kleum lutwguug sewaxfs i kapde xegqazfozf it yse eujcaf aqakuhbg. Zu tvoaje dvu exohu tieqf, cuu ova sfi qq.Avego() jogtilemw.
Koo xut avbe ijw ieboi robtukogll ueglih ol nka ecbol caafb oq tdo uafduh teihg.
# 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()
Ez pkut eluqlye, kpa olp id qeklnac ixbubwor te ilbkajo oajoo ogris atc oagfov liyhocumqb. Wso lw.Iavuo() hitvojamg xozj ayujk nxocuza uikoa oklit cxvuork u netsutnofe, evg xwe dayzleaq mamozqm o rhaenuvb jokxiza, iq onete EGM, ohw iq oetue muni diwq. Dco cm.Uitoa() eifxoy reahk ziedq’w naak kti veoncij eqxipiyd xigeobi dae pvez jwe iudio abqj uw fke uaykot muazf.
# 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()
Mca Pwegaa eklopmomo aw igcabhew dv ojjizx i yehci iyj kaydrazfuen zo qpapedo kigmobl akn zeqe bxa ezp risa avep-ymoonflk.
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.