AjithKSenthil commited on
Commit
824bec1
·
verified ·
1 Parent(s): 0611f13

Update chatbot.py

Browse files
Files changed (1) hide show
  1. chatbot.py +6 -5
chatbot.py CHANGED
@@ -12,7 +12,6 @@ DATABASE_URL = os.getenv('DATABASE_URL')
12
 
13
  # Parse the database URL
14
  result = urlparse(DATABASE_URL)
15
-
16
  username = result.username
17
  password = result.password
18
  database = result.path[1:]
@@ -142,13 +141,15 @@ with gr.Blocks() as demo:
142
  password = gr.Textbox(label="Password", type="password")
143
  login_button = gr.Button("Login")
144
  register_button = gr.Button("Register")
 
145
 
146
  chat_interface = gr.Interface(
147
  fn=chatbot,
148
- inputs=[gr.Textbox(label="User ID"), gr.Textbox(lines=7, label="Chat with AttachmentBot")],
149
  outputs=gr.Textbox(label="Conversation"),
150
  title="AttachmentBot",
151
- description="Let me survey you about your attachment with certain people in your life. To begin, enter 'start'."
 
152
  )
153
 
154
  def login(username, password):
@@ -165,7 +166,7 @@ with gr.Blocks() as demo:
165
  else:
166
  return gr.update(visible=False), "", "Registration failed, try a different username."
167
 
168
- login_button.click(login, inputs=[username, password], outputs=[chat_interface, gr.Variable(), gr.Textbox(visible=False)])
169
- register_button.click(register, inputs=[username, password], outputs=[chat_interface, gr.Variable(), gr.Textbox(visible=False)])
170
 
171
  demo.launch()
 
12
 
13
  # Parse the database URL
14
  result = urlparse(DATABASE_URL)
 
15
  username = result.username
16
  password = result.password
17
  database = result.path[1:]
 
141
  password = gr.Textbox(label="Password", type="password")
142
  login_button = gr.Button("Login")
143
  register_button = gr.Button("Register")
144
+ user_id_state = gr.State()
145
 
146
  chat_interface = gr.Interface(
147
  fn=chatbot,
148
+ inputs=[user_id_state, gr.Textbox(lines=7, label="Chat with AttachmentBot")],
149
  outputs=gr.Textbox(label="Conversation"),
150
  title="AttachmentBot",
151
+ description="Let me survey you about your attachment with certain people in your life. To begin, enter 'start'.",
152
+ visible=False # Initially hidden, shown after login
153
  )
154
 
155
  def login(username, password):
 
166
  else:
167
  return gr.update(visible=False), "", "Registration failed, try a different username."
168
 
169
+ login_button.click(login, inputs=[username, password], outputs=[chat_interface, user_id_state, gr.Textbox(visible=False)])
170
+ register_button.click(register, inputs=[username, password], outputs=[chat_interface, user_id_state, gr.Textbox(visible=False)])
171
 
172
  demo.launch()