File size: 2,979 Bytes
21fb63e 5169cb4 08fba0b 5169cb4 21fb63e 7bf9351 5169cb4 21fb63e 5169cb4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
#******* import gradio as gr *******
# importing the gradio library! we're going to use this for our chat interface.
# we're giving it an alias -- gr. just like numpy & pandas
# now we're going to use the chat interface function from the gradio library to create
# a new instance of a chat interface
# we're gonna do this by saving it to a variable
# we'll call it chatbot & we'll assign it to an instance of a chat interface from the gradio library
# ********** chatbot = gr.ChatInterface() ********)
# this alone isn't going to launch the chat interface
# we'll hit return & call the launch function, with the open & closed parenthesis after it
# ************ chatbot.launch() *********
# if you were to save this & try running it, you're gonna get an error message
# the reason is this chatinterface function expects to receive a parameter or an argument
# this argument is going to be a function
# this function should define or handle how the chatbot should actually behave
# what kind of interactions should we expect?
# import gradio as gr
# ***enter new code here on line 3**
#chatbot = gr.ChatInterface()
#chatbot.launch()
# before we actually initalize the chatinterface
# so we're actually going to jump back up here (to line 3)
# for our simple chatbot, we're gonna make it an echo function
# its gonna echo what the user types in... so lets call it echo
# so here, whatever we return should be the chatbot's response
# theres something else we need to make note of
# it needs to be passed into the chatInterface
# so lets add that inside the parenthesis chatbot = gr.ChatInterface(echo)
# but!!!! this function must have 2 parameters
# the message the user typed in & the history!
# add message, history inside def(echo)
# so when chat interface picks up that there's a new message from the user,
# its going to call the echo function, passing in the message from the user & any history from the prior conversation
# we want our chatbot to be like a parrot right now, where it just returnes the same thing
# add message after return
#return message
# we just want it to repeat what we're saying!
#then update commit changes note
# define echo function & set up chat interface
#import gradio as gr
#def echo(message, history):
#return message
#chatbot = gr.ChatInterface(echo)
#chatbot.launch()
# after this, go back to slides until the try-it
# ope theres a warning in the log!
# so lets resolve this by after the echo function, add a comma and set the type parameter to messages
# before we close out i'm also going to add a print message that says Hello world
# what this is going to do is print Hello world every time in the log
# so if we check the log now, our warning is gone... and it's printing hello world!
import gradio as gr
def echo(message, history):
print("Hello, world!")
return message
chatbot = gr.ChatInterface(echo, type='messages')
chatbot.launch() |