mdpatel2 commited on
Commit
0c5f73c
·
verified ·
1 Parent(s): 48f1f36

update url to point to rasa

Browse files
Files changed (1) hide show
  1. app.py +14 -10
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/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")
@@ -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
+