Spaces:
Sleeping
Sleeping
Copy-Paste of Original Training chatbot for just lesson 10 without lesson 11 changes.
Browse files
app.py
CHANGED
|
@@ -1,8 +1,31 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
def echo(message, history):
|
|
|
|
| 4 |
return message
|
| 5 |
|
| 6 |
-
chatbot = gr.ChatInterface(echo)
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
chatbot.launch()
|
|
|
|
| 1 |
+
#import the suite of gradio features
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
#import the random library
|
| 5 |
+
import random as rd
|
| 6 |
+
|
| 7 |
+
#return is what the chatbot's response will be
|
| 8 |
+
#echo function needs 2 parameters,
|
| 9 |
+
#the message that the user input,
|
| 10 |
+
#the history from the prior conversation
|
| 11 |
+
|
| 12 |
+
#this function will just respond exactly what the input was
|
| 13 |
def echo(message, history):
|
| 14 |
+
print("Hello, world!")
|
| 15 |
return message
|
| 16 |
|
|
|
|
| 17 |
|
| 18 |
+
#this is the list of possible choices for the random function
|
| 19 |
+
#this function will randomly respond 'yes' or 'no'
|
| 20 |
+
def yes_no(message, history):
|
| 21 |
+
response_list = ['yes', 'no']
|
| 22 |
+
print("User Message: ", message)
|
| 23 |
+
print("History: ", history)
|
| 24 |
+
return rd.choice(response_list)
|
| 25 |
+
|
| 26 |
+
# assign the chat interface to a variable, expects a function as an argument
|
| 27 |
+
#the second argument fixes an error message about not supporting tuples
|
| 28 |
+
chatbot = gr.ChatInterface(yes_no, type='messages', title="A simple chatbot", description="A cute lil' chatbot that can give quaint, basic responses. Created by Matt Getz for KWK", theme='earneleh/paris')
|
| 29 |
+
|
| 30 |
+
#launch the chat interface
|
| 31 |
chatbot.launch()
|