mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-13 11:57:29 +08:00
* remove deprecated api from docs * Remove usage of 'state' shortcut * Back out state changes * Back out state changes in creating_a_chatbot * Link chatbot guide to Variable docs
29 lines
704 B
Python
29 lines
704 B
Python
import random
|
|
|
|
import gradio as gr
|
|
|
|
|
|
def chat(message, history):
|
|
history = history or []
|
|
if message.startswith("How many"):
|
|
response = random.randint(1, 10)
|
|
elif message.startswith("How"):
|
|
response = random.choice(["Great", "Good", "Okay", "Bad"])
|
|
elif message.startswith("Where"):
|
|
response = random.choice(["Here", "There", "Somewhere"])
|
|
else:
|
|
response = "I don't know"
|
|
history.append((message, response))
|
|
return history, history
|
|
|
|
|
|
chatbot = gr.Chatbot().style(color_map=("green", "pink"))
|
|
demo = gr.Interface(
|
|
chat,
|
|
["text", "state"],
|
|
[chatbot, "state"],
|
|
allow_flagging="never",
|
|
)
|
|
if __name__ == "__main__":
|
|
demo.launch()
|