pasupuletkarthiksai commited on
Commit
b13b4d8
·
verified ·
1 Parent(s): f956173

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -13
app.py CHANGED
@@ -31,17 +31,22 @@ def start_bot(userid, password, api_key_input):
31
 
32
 
33
  def answer(message, history):
34
- answer_md, tables_display, images_display, retrieved_display = bot.get_answer(message)
35
-
36
- # Combine all parts into a single response string for chat
37
- combined_response = f"{answer_md}\n\n{tables_display}"
38
-
39
- # Add images as markdown
40
- if images_display:
41
- combined_response += "\n\n" + "\n\n".join(images_display)
42
-
43
- return combined_response
44
-
 
 
 
 
 
45
 
46
 
47
  with gr.Blocks(fill_height=True, fill_width=True) as app:
@@ -83,7 +88,7 @@ with gr.Blocks(fill_height=True, fill_width=True) as app:
83
  # Function connections
84
  login_btn.click(
85
  start_bot,
86
- inputs=[userid_login, password_login],
87
  outputs=[login_output, login_register_section, chat_section]
88
  )
89
 
@@ -94,4 +99,4 @@ with gr.Blocks(fill_height=True, fill_width=True) as app:
94
  )
95
 
96
 
97
- app.launch(server_name="0.0.0.0", server_port=7860, ssr_mode=False)
 
31
 
32
 
33
  def answer(message, history):
34
+ global bot
35
+ if bot is None:
36
+ return "Please log in or register to start the bot."
37
+ try:
38
+ answer_md, tables_display, images_display, retrieved_display = bot.get_answer(message)
39
+
40
+ # Combine all parts into a single response string for chat
41
+ combined_response = f"{answer_md}\n\n{tables_display}"
42
+
43
+ # Add images as markdown
44
+ if images_display:
45
+ combined_response += "\n\n" + "\n\n".join(images_display)
46
+
47
+ return combined_response
48
+ except Exception as e:
49
+ return f"An error occurred: {e}"
50
 
51
 
52
  with gr.Blocks(fill_height=True, fill_width=True) as app:
 
88
  # Function connections
89
  login_btn.click(
90
  start_bot,
91
+ inputs=[userid_login, password_login, api_key_register],
92
  outputs=[login_output, login_register_section, chat_section]
93
  )
94
 
 
99
  )
100
 
101
 
102
+ app.launch(server_name="0.0.0.0", server_port=7860, ssr_mode=False)