Spaces:
Sleeping
Sleeping
Commit
·
c185cfc
1
Parent(s):
eb50bc8
init
Browse files
app.py
CHANGED
|
@@ -1,19 +1,22 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
-
description = """
|
| 5 |
-
The bot was trained to answer questions based on Rick and Morty dialogues. Ask Rick anything!
|
| 6 |
-
<img src="https://huggingface.co/spaces/course-demos/Rick_and_Morty_QA/resolve/main/rick.png" width=200px>
|
| 7 |
-
"""
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
gr.
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
import random
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
def respond(message, chat_history):
|
| 6 |
+
#No LLM here, just respond with a random pre-made message
|
| 7 |
+
bot_message = random.choice(["Tell me more about it",
|
| 8 |
+
"Cool, but I'm not interested",
|
| 9 |
+
"Hmmmm, ok then"])
|
| 10 |
+
chat_history.append((message, bot_message))
|
| 11 |
+
return "", chat_history
|
| 12 |
|
| 13 |
+
with gr.Blocks() as demo:
|
| 14 |
+
chatbot = gr.Chatbot(height=240) #just to fit the notebook
|
| 15 |
+
msg = gr.Textbox(label="Prompt")
|
| 16 |
+
btn = gr.Button("Submit")
|
| 17 |
+
clear = gr.ClearButton(components=[msg, chatbot], value="Clear console")
|
| 18 |
+
|
| 19 |
+
btn.click(respond, inputs=[msg, chatbot], outputs=[msg, chatbot])
|
| 20 |
+
msg.submit(respond, inputs=[msg, chatbot], outputs=[msg, chatbot]) #Press enter to submit
|
| 21 |
+
gr.close_all()
|
| 22 |
+
demo.launch()
|