Spaces:
Runtime error
Runtime error
update url to point to rasa
Browse files
app.py
CHANGED
|
@@ -8,19 +8,22 @@ theme = gr.themes.Base(
|
|
| 8 |
|
| 9 |
def chat_with_rasa(user_message, history):
|
| 10 |
response = requests.post(
|
| 11 |
-
"https://clairify.ai/
|
| 12 |
json={"sender": "user", "message": user_message}
|
| 13 |
)
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
with gr.Blocks(theme=gr.themes.Default(primary_hue="red", secondary_hue="pink")) as demo:
|
| 26 |
gr.Markdown("## Rasa Chatbot")
|
|
@@ -31,3 +34,4 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="red", secondary_hue="pink"))
|
|
| 31 |
submit_button.click(fn=chat_with_rasa, inputs=[user_message, history], outputs=history)
|
| 32 |
|
| 33 |
demo.launch()
|
|
|
|
|
|
| 8 |
|
| 9 |
def chat_with_rasa(user_message, history):
|
| 10 |
response = requests.post(
|
| 11 |
+
"https://clairify.ai/rasa",
|
| 12 |
json={"sender": "user", "message": user_message}
|
| 13 |
)
|
| 14 |
|
| 15 |
+
try:
|
| 16 |
+
bot_messages = response.json()
|
| 17 |
+
chat_log = history
|
| 18 |
+
if isinstance(bot_messages, list):
|
| 19 |
+
chat_log += f"\nYou: {user_message}"
|
| 20 |
+
for msg in bot_messages:
|
| 21 |
+
chat_log += f"\nBot: {msg.get('text', 'No response')}"
|
| 22 |
+
else:
|
| 23 |
+
chat_log += "\nError: Unexpected response type from Rasa."
|
| 24 |
+
return chat_log
|
| 25 |
+
except ValueError as e:
|
| 26 |
+
return f"Error decoding JSON response: {str(e)}"
|
| 27 |
|
| 28 |
with gr.Blocks(theme=gr.themes.Default(primary_hue="red", secondary_hue="pink")) as demo:
|
| 29 |
gr.Markdown("## Rasa Chatbot")
|
|
|
|
| 34 |
submit_button.click(fn=chat_with_rasa, inputs=[user_message, history], outputs=history)
|
| 35 |
|
| 36 |
demo.launch()
|
| 37 |
+
|