define echo function & set up chat interface
Browse files
app.py
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#******* import gradio as gr *******
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
# importing the gradio library! we're going to use this for our chat interface.
|
| 5 |
+
# we're giving it an alias -- gr. just like numpy & pandas
|
| 6 |
+
|
| 7 |
+
# now we're going to use the chat interface function from the gradio library to create
|
| 8 |
+
# a new instance of a chat interface
|
| 9 |
+
|
| 10 |
+
# we're gonna do this by saving it to a variable
|
| 11 |
+
# we'll call it chatbot & we'll assign it to an instance of a chat interface from the gradio library
|
| 12 |
+
|
| 13 |
+
# ********** chatbot = gr.ChatInterface() ********)
|
| 14 |
+
|
| 15 |
+
# this alone isn't going to launch the chat interface
|
| 16 |
+
# we'll hit return & call the launch function, with the open & closed parenthesis after it
|
| 17 |
+
|
| 18 |
+
# ************ chatbot.launch() *********
|
| 19 |
+
|
| 20 |
+
# if you were to save this & try running it, you're gonna get an error message
|
| 21 |
+
# the reason is this chatinterface function expects to receive a parameter or an argument
|
| 22 |
+
# this argument is going to be a function
|
| 23 |
+
# this function should define or handle how the chatbot should actually behave
|
| 24 |
+
# what kind of interactions should we expect?
|
| 25 |
+
|
| 26 |
+
# import gradio as gr
|
| 27 |
+
|
| 28 |
+
# ***enter new code here on line 3**
|
| 29 |
+
|
| 30 |
+
#chatbot = gr.ChatInterface()
|
| 31 |
+
#chatbot.launch()
|
| 32 |
+
|
| 33 |
+
# before we actually initalize the chatinterface
|
| 34 |
+
# so we're actually going to jump back up here (to line 3)
|
| 35 |
+
# for our simple chatbot, we're gonna make it an echo function
|
| 36 |
+
# its gonna echo what the user types in... so lets call it echo
|
| 37 |
+
|
| 38 |
+
# so here, whatever we return should be the chatbot's response
|
| 39 |
+
# theres something else we need to make note of
|
| 40 |
+
# it needs to be passed into the chatInterface
|
| 41 |
+
# so lets add that inside the parenthesis chatbot = gr.ChatInterface(echo)
|
| 42 |
+
# but!!!! this function must have 2 parameters
|
| 43 |
+
# the message the user typed in & the history!
|
| 44 |
+
# add message, history inside def(echo)
|
| 45 |
+
# so when chat interface picks up that there's a new message from the user,
|
| 46 |
+
# its going to call the echo function, passing in the message from the user & any history from the prior conversation
|
| 47 |
+
|
| 48 |
+
# we want our chatbot to be like a parrot right now, where it just returnes the same thing
|
| 49 |
+
# add message after return
|
| 50 |
+
#return message
|
| 51 |
+
# we just want it to repeat what we're saying!
|
| 52 |
+
|
| 53 |
+
#then update commit changes note
|
| 54 |
+
# define echo function & set up chat interface
|
| 55 |
+
|
| 56 |
+
import gradio as gr
|
| 57 |
+
|
| 58 |
+
def echo(message, history)
|
| 59 |
+
return message
|
| 60 |
+
|
| 61 |
+
chatbot = gr.ChatInterface(echo)
|
| 62 |
+
chatbot.launch()
|
| 63 |
+
|