Spaces:
Runtime error
Runtime error
Mehul Patel commited on
Commit ·
48f1f36
1
Parent(s): d1ddaff
vertical arrangement with gr blocks
Browse files
app.py
CHANGED
|
@@ -1,7 +1,33 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
|
| 4 |
+
theme = gr.themes.Base(
|
| 5 |
+
primary_hue="cyan",
|
| 6 |
+
secondary_hue="blue",
|
| 7 |
+
)
|
| 8 |
|
| 9 |
+
def chat_with_rasa(user_message, history):
|
| 10 |
+
response = requests.post(
|
| 11 |
+
"https://clairify.ai/gradio",
|
| 12 |
+
json={"sender": "user", "message": user_message}
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
bot_messages = response.json()
|
| 16 |
+
chat_log = history
|
| 17 |
+
if isinstance(bot_messages, list):
|
| 18 |
+
chat_log += f"\nYou: {user_message}"
|
| 19 |
+
for msg in bot_messages:
|
| 20 |
+
chat_log += f"\nBot: {msg.get('text', 'No response')}"
|
| 21 |
+
else:
|
| 22 |
+
chat_log += "\nError: Unexpected response type from Rasa."
|
| 23 |
+
return chat_log
|
| 24 |
+
|
| 25 |
+
with gr.Blocks(theme=gr.themes.Default(primary_hue="red", secondary_hue="pink")) as demo:
|
| 26 |
+
gr.Markdown("## Rasa Chatbot")
|
| 27 |
+
gr.Markdown("This is a simple chat interface for a Rasa chatbot.")
|
| 28 |
+
history = gr.Textbox(label="Chat History", value="", lines=12, interactive=False)
|
| 29 |
+
user_message = gr.Textbox(label="Your Message", lines=2, placeholder="Type your message here...")
|
| 30 |
+
submit_button = gr.Button("Send")
|
| 31 |
+
submit_button.click(fn=chat_with_rasa, inputs=[user_message, history], outputs=history)
|
| 32 |
+
|
| 33 |
+
demo.launch()
|