2021-09-21 09:35:18 +08:00
|
|
|
import random
|
2022-01-21 21:44:12 +08:00
|
|
|
import gradio as gr
|
|
|
|
|
2022-01-14 04:22:38 +08:00
|
|
|
def chat(message, history):
|
|
|
|
history = history or []
|
2022-07-25 09:18:42 +08:00
|
|
|
message = message.lower()
|
|
|
|
if message.startswith("how many"):
|
2022-01-21 21:44:12 +08:00
|
|
|
response = random.randint(1, 10)
|
2022-07-25 09:18:42 +08:00
|
|
|
elif message.startswith("how"):
|
2021-09-21 09:35:18 +08:00
|
|
|
response = random.choice(["Great", "Good", "Okay", "Bad"])
|
2022-07-25 09:18:42 +08:00
|
|
|
elif message.startswith("where"):
|
2021-09-21 09:35:18 +08:00
|
|
|
response = random.choice(["Here", "There", "Somewhere"])
|
|
|
|
else:
|
|
|
|
response = "I don't know"
|
|
|
|
history.append((message, response))
|
2022-02-22 13:30:22 +08:00
|
|
|
return history, history
|
2021-09-21 09:35:18 +08:00
|
|
|
|
2022-07-19 23:53:01 +08:00
|
|
|
chatbot = gr.Chatbot().style(color_map=("green", "pink"))
|
2022-03-28 23:11:14 +08:00
|
|
|
demo = gr.Interface(
|
2022-01-21 21:44:12 +08:00
|
|
|
chat,
|
|
|
|
["text", "state"],
|
2022-05-02 16:41:20 +08:00
|
|
|
[chatbot, "state"],
|
2022-01-21 21:44:12 +08:00
|
|
|
allow_flagging="never",
|
|
|
|
)
|
2021-09-21 09:35:18 +08:00
|
|
|
if __name__ == "__main__":
|
2022-03-28 23:11:14 +08:00
|
|
|
demo.launch()
|