sidagarwal04 commited on
Commit
2393894
·
verified ·
1 Parent(s): db6f419

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -17
app.py CHANGED
@@ -105,20 +105,26 @@ def generate_and_exec_cypher(input_query):
105
  return run_cypher_on_neo4j(gen_query, gen_key)
106
 
107
  def chatbot(input, history=[]):
108
- output = str(generate_and_exec_cypher(input))
109
- history.append((input, output))
110
- return history, history
111
-
112
- gr.Interface(fn = chatbot,
113
- title = "Mahabharata Chatbot",
114
- description = "powered by Neo4j",
115
- theme = "soft",
116
- chatbot = gr.Chatbot(height=500),
117
- undo_btn = None,
118
- clear_btn = "\U0001F5D1 Clear chat",
119
- examples = ["Who killed Ghatotakach?",
120
- "Who are the parents of Karna?",
121
- "Who are the kids of Kunti?",
122
- "Who are the siblings of Karna?"],
123
- inputs = ["text",'state'],
124
- outputs = ["chatbot",'state']).launch(debug = True, share=True)
 
 
 
 
 
 
 
105
  return run_cypher_on_neo4j(gen_query, gen_key)
106
 
107
  def chatbot(input, history=[]):
108
+
109
+ try:
110
+ output = str(generate_and_exec_cypher(input))
111
+ history.append((input, output))
112
+ return history, history
113
+ except:
114
+ # a bit of protection against exposed error messages
115
+ # we could log these situations in the backend to revisit later in development
116
+ return "I'm sorry, there was an error retrieving the information you requested."
117
+
118
+ gr.ChatInterface(fn = chatbot,
119
+ title = "Mahabharata Chatbot",
120
+ description = "powered by Neo4j",
121
+ theme = "soft",
122
+ chatbot = gr.Chatbot(height=500),
123
+ undo_btn = None,
124
+ clear_btn = "\U0001F5D1 Clear chat",
125
+ examples = ["Who killed Ghatotakach?",
126
+ "Who are the parents of Karna?",
127
+ "Who are the kids of Kunti?",
128
+ "Who are the siblings of Karna?"],
129
+ inputs = ["text",'state'],
130
+ outputs = ["chatbot",'state']).launch(debug = True, share=True)